2017-07-10 17:32:42 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2019-10-25 00:27:02 +02:00
|
|
|
"github.com/kataras/iris/v12"
|
|
|
|
"github.com/kataras/iris/v12/httptest"
|
2017-07-10 17:32:42 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestSessionsEncodeDecode(t *testing.T) {
|
2017-07-11 17:09:32 +02:00
|
|
|
app := newApp()
|
2017-07-10 17:32:42 +02:00
|
|
|
e := httptest.New(t, app, httptest.URL("http://example.com"))
|
|
|
|
|
2017-07-11 17:09:32 +02:00
|
|
|
es := e.GET("/set").Expect()
|
|
|
|
es.Status(iris.StatusOK)
|
|
|
|
es.Cookies().NotEmpty()
|
2023-07-08 01:08:18 +02:00
|
|
|
es.Body().IsEqual("All ok session set to: iris [isNew=true]")
|
2017-07-11 17:09:32 +02:00
|
|
|
|
2023-07-08 01:08:18 +02:00
|
|
|
e.GET("/get").Expect().Status(iris.StatusOK).Body().IsEqual("The username on the /set was: iris")
|
2017-07-11 17:09:32 +02:00
|
|
|
// delete and re-get
|
|
|
|
e.GET("/delete").Expect().Status(iris.StatusOK)
|
2023-07-08 01:08:18 +02:00
|
|
|
e.GET("/get").Expect().Status(iris.StatusOK).Body().IsEqual("The username on the /set was: ")
|
2017-07-11 17:09:32 +02:00
|
|
|
// set, clear and re-get
|
2023-07-08 01:08:18 +02:00
|
|
|
e.GET("/set").Expect().Body().IsEqual("All ok session set to: iris [isNew=false]")
|
2017-07-11 17:09:32 +02:00
|
|
|
e.GET("/clear").Expect().Status(iris.StatusOK)
|
2023-07-08 01:08:18 +02:00
|
|
|
e.GET("/get").Expect().Status(iris.StatusOK).Body().IsEqual("The username on the /set was: ")
|
2017-07-10 17:32:42 +02:00
|
|
|
}
|