forked from go-cas/cas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
memory_store_test.go
49 lines (38 loc) · 1.21 KB
/
memory_store_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
package cas
import (
"testing"
)
func TestMemoryStore(t *testing.T) {
user1 := &AuthenticationResponse{User: "user1"}
user2 := &AuthenticationResponse{User: "user2"}
store := &MemoryStore{}
if err := store.Write("user1", user1); err != nil {
t.Errorf("Expected store.Write(user1) to succeed, got error: %v", err)
}
if err := store.Write("user2", user2); err != nil {
t.Errorf("Expected store.Write(user2) to succeed, got error: %v", err)
}
ar, err := store.Read("user2")
if err != nil {
t.Errorf("Expected store.Read(user2) to succeed, got error: %v", err)
}
if ar != user2 {
t.Errorf("Expected retrieved AuthenticationResponse to be %v, got %v", user2, ar)
}
if err := store.Delete("user2"); err != nil {
t.Errorf("Error while deleting user2, got %v", err)
}
if _, err := store.Read("user2"); err != ErrInvalidTicket {
t.Errorf("Expected store.Read(user2) to fail")
}
if err := store.Clear(); err != nil {
t.Errorf("Expected store.Clear() to succeed, got error: %v", err)
}
_, err = store.Read("user1")
if err == nil {
t.Errorf("Expected an error from store.Read(user1), got nil")
}
if err != ErrInvalidTicket {
t.Errorf("Expected ErrInvalidTicket from store.Read(user1), got %v", err)
}
}