From 50b1366e9d498ccdae97f9fa3cda7cabf5d95c3e Mon Sep 17 00:00:00 2001 From: Makis Maropoulos Date: Sat, 2 Jul 2016 15:16:42 +0200 Subject: [PATCH] improve the flash messages test --- context.go | 2 +- test/sessions_test.go | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/context.go b/context.go index b5c39129..201491c5 100644 --- a/context.go +++ b/context.go @@ -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 diff --git a/test/sessions_test.go b/test/sessions_test.go index 8e5c7989..c1e8e277 100644 --- a/test/sessions_test.go +++ b/test/sessions_test.go @@ -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() }