forked from volatiletech/authboss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_storer_test.go
57 lines (45 loc) · 1.25 KB
/
client_storer_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package authboss
import (
"net/http"
"testing"
)
type testClientStorerErr string
func (t testClientStorerErr) Put(key, value string) {}
func (t testClientStorerErr) Get(key string) (string, bool) {
return string(t), key == string(t)
}
func (t testClientStorerErr) Del(key string) {}
func TestClientStorerErr(t *testing.T) {
t.Parallel()
var cs testClientStorerErr
csw := clientStoreWrapper{&cs}
if _, err := csw.GetErr("hello"); err == nil {
t.Error("Expected an error")
}
cs = "hello"
if str, err := csw.GetErr("hello"); err != nil {
t.Error(err)
} else if str != "hello" {
t.Error("Wrong value:", str)
}
}
func TestFlashClearer(t *testing.T) {
t.Parallel()
session := mockClientStore{FlashSuccessKey: "success", FlashErrorKey: "error"}
ab := New()
ab.SessionStoreMaker = func(w http.ResponseWriter, r *http.Request) ClientStorer {
return session
}
if msg := ab.FlashSuccess(nil, nil); msg != "success" {
t.Error("Unexpected flash success:", msg)
}
if msg, ok := session.Get(FlashSuccessKey); ok {
t.Error("Unexpected success flash:", msg)
}
if msg := ab.FlashError(nil, nil); msg != "error" {
t.Error("Unexpected flash error:", msg)
}
if msg, ok := session.Get(FlashErrorKey); ok {
t.Error("Unexpected error flash:", msg)
}
}