-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathetcd_ticket_store_test.go
55 lines (43 loc) · 1.44 KB
/
etcd_ticket_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
50
51
52
53
54
55
package casstore
import (
"context"
"reflect"
"testing"
clientv3 "go.etcd.io/etcd/client/v3"
"gopkg.in/cas.v2"
)
func TestEtcdTicketStore(t *testing.T) {
user1 := &cas.AuthenticationResponse{User: "user1"}
user2 := &cas.AuthenticationResponse{User: "user2"}
store, err := NewEtcdTicketStore(clientv3.Config{Endpoints: []string{_defaultEtcd}},
context.Background(), "/cas/tickets", 3600)
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 !reflect.DeepEqual(*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 != cas.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 != cas.ErrInvalidTicket {
t.Errorf("Expected ErrInvalidTicket from store.Read(user1), got %v", err)
}
}