40 lines
798 B
Go
40 lines
798 B
Go
|
package cookie
|
||
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
"net/http/httptest"
|
||
|
"testing"
|
||
|
|
||
|
"git.1248.nz/1248/Otfe/misc/b64"
|
||
|
"git.1248.nz/1248/Otfe/misc/helpers"
|
||
|
)
|
||
|
|
||
|
func TestCreate(t *testing.T) {
|
||
|
recorder := httptest.NewRecorder()
|
||
|
Create(recorder, "test", "test")
|
||
|
request := &http.Request{Header: http.Header{
|
||
|
"Cookie": recorder.HeaderMap["Set-Cookie"]}}
|
||
|
cookie, err := request.Cookie("test")
|
||
|
if err != nil {
|
||
|
t.Fail()
|
||
|
return
|
||
|
}
|
||
|
value, err := b64.Decode(cookie.Value)
|
||
|
if err != nil || value != "test" {
|
||
|
t.Fail()
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestRead(t *testing.T) {
|
||
|
cookie := &http.Cookie{Name: "test", Value: b64.Encode("test")}
|
||
|
|
||
|
request, err := http.NewRequest("GET", "", nil)
|
||
|
if err != nil {
|
||
|
t.Fail()
|
||
|
return
|
||
|
}
|
||
|
request.AddCookie(cookie)
|
||
|
value, err := Read(request, "test")
|
||
|
helpers.Equals(t, value, "test")
|
||
|
}
|