1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-18 10:27:06 +00:00
Files
kararas_iris/httptest/_example/main_test.go
Gerasimos (Makis) Maropoulos bfeabbd74e Add a httptest simple example, I'm thinking to obselete the gitbook entirely, the feature/_example folder is easier for the users
Former-commit-id: 6d4143e63838164a6b1bf1184b0c86a6b3fe15cd
2017-02-17 01:34:45 +02:00

33 lines
1004 B
Go

package main
import (
"testing"
"gopkg.in/kataras/iris.v6/httptest"
)
// $ cd _example
// $ go test -v
func TestNewApp(t *testing.T) {
app := newApp()
e := httptest.New(app, t)
// test nauthorized
e.GET("/hello").Expect().Status(401).Body().Equal("<h1> Unauthorized Page! </h1>")
// test our login flash message
name := "myname"
e.POST("/login").WithFormField("name", name).Expect().Status(200)
// test the /hello again with the flash (a message which deletes itself after it has been shown to the user)
// setted on /login previously.
expectedResponse := map[string]interface{}{
"Message": "Hello",
"From": name,
}
e.GET("/hello").Expect().Status(200).JSON().Equal(expectedResponse)
// test /hello nauthorized again, it should be return 401 now (flash should be removed)
e.GET("/hello").Expect().Status(401).Body().Equal("<h1> Unauthorized Page! </h1>")
}
// for advanced test examples navigate there:
// https://github.com/gavv/httpexpect/blob/master/_examples/iris_test.go