improve the flash messages test

This commit is contained in:
Makis Maropoulos 2016-07-02 15:16:42 +02:00
parent 9100560e00
commit 50b1366e9d
2 changed files with 12 additions and 4 deletions

View File

@ -720,10 +720,10 @@ func (ctx *Context) RemoveCookie(name string) {
}
// GetFlash get a flash message by it's key
// after the request lifetime the value is removed
// returns the value as string and an error
//
// if the cookie doesn't exists the string is empty and the error is filled
// after the request's life the value is removed
func (ctx *Context) GetFlash(key string) (value string, err error) {
// first check if flash exists from this request's lifetime, if yes return that else continue to get the cookie

View File

@ -83,6 +83,9 @@ func FlashMessagesTest(t *testing.T) {
}
})
//we don't get the flash so on the next request the flash messages should be available.
api.Get("/get_no_getflash", func(ctx *iris.Context) {})
api.Get("/get", func(ctx *iris.Context) {
// one time one handler
kv := make(map[string]string)
@ -106,9 +109,14 @@ func FlashMessagesTest(t *testing.T) {
})
e := tester(api, t)
e.PUT("/set").Expect().Status(iris.StatusOK)
e.PUT("/set").Expect().Status(iris.StatusOK).Cookies().NotEmpty()
// just a request which does not use the flash message, so flash messages should be available on the next request
e.GET("/get_no_getflash").Expect().Status(iris.StatusOK).Cookies().NotEmpty()
e.GET("/get").Expect().Status(iris.StatusOK).JSON().Object().Equal(values)
// secnd request lifetime ,the flash messages here should be not available
e.GET("/get").Expect().Status(iris.StatusOK).JSON().Object().Empty()
// second request ,the flash messages here should be not available and cookie has been removed
// (the true is that the cookie is removed from the first GetFlash, but is available though the whole request saved on context's values for faster get, keep that secret!)*
g := e.GET("/get").Expect().Status(iris.StatusOK)
g.JSON().Object().Empty()
g.Cookies().Empty()
}