2018-06-02 06:28:40 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2019-10-25 00:27:02 +02:00
|
|
|
"github.com/kataras/iris/v12/httptest"
|
2018-06-02 06:28:40 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCookiesBasic(t *testing.T) {
|
|
|
|
app := newApp()
|
|
|
|
e := httptest.New(t, app, httptest.URL("http://example.com"))
|
|
|
|
|
|
|
|
cookieName, cookieValue := "my_cookie_name", "my_cookie_value"
|
|
|
|
|
2020-05-09 13:04:51 +02:00
|
|
|
// Test set a Cookie.
|
2018-06-02 06:28:40 +02:00
|
|
|
t1 := e.GET(fmt.Sprintf("/cookies/%s/%s", cookieName, cookieValue)).Expect().Status(httptest.StatusOK)
|
|
|
|
t1.Cookie(cookieName).Value().Equal(cookieValue) // validate cookie's existence, it should be there now.
|
|
|
|
t1.Body().Contains(cookieValue)
|
|
|
|
|
2020-05-09 13:04:51 +02:00
|
|
|
// Test retrieve a Cookie.
|
2018-06-02 06:28:40 +02:00
|
|
|
t2 := e.GET(fmt.Sprintf("/cookies/%s", cookieName)).Expect().Status(httptest.StatusOK)
|
2023-07-08 01:08:18 +02:00
|
|
|
t2.Body().IsEqual(cookieValue)
|
2018-06-02 06:28:40 +02:00
|
|
|
|
2020-05-09 13:04:51 +02:00
|
|
|
// Test remove a Cookie.
|
2018-06-02 06:28:40 +02:00
|
|
|
t3 := e.DELETE(fmt.Sprintf("/cookies/%s", cookieName)).Expect().Status(httptest.StatusOK)
|
|
|
|
t3.Body().Contains(cookieName)
|
|
|
|
|
|
|
|
t4 := e.GET(fmt.Sprintf("/cookies/%s", cookieName)).Expect().Status(httptest.StatusOK)
|
|
|
|
t4.Cookies().Empty()
|
2023-07-08 01:08:18 +02:00
|
|
|
t4.Body().IsEmpty()
|
2018-06-02 06:28:40 +02:00
|
|
|
}
|