forked from kataras/iris
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
32 lines (27 loc) · 1004 Bytes
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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