mirror of
https://github.com/kataras/iris.git
synced 2025-12-19 10:57:05 +00:00
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
This commit is contained in:
32
httptest/_example/main_test.go
Normal file
32
httptest/_example/main_test.go
Normal file
@@ -0,0 +1,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
|
||||
Reference in New Issue
Block a user