-
Notifications
You must be signed in to change notification settings - Fork 0
/
session_test.go
66 lines (56 loc) · 1.44 KB
/
session_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
58
59
60
61
62
63
64
65
66
package authkit
import (
"net/http"
"net/http/httptest"
"reflect"
"testing"
)
// TestStore - struct for testing Store interface
type TestStore struct{}
// New - implement Store interface
func (ts TestStore) New(req *http.Request, name string) (*Session, error) {
return &Session{
name: name,
}, nil
}
// Save - implement Store interface
func (ts TestStore) Save(w http.ResponseWriter, session *Session) error {
return nil
}
// TestNewSession - test creating Session
func TestNewSession(t *testing.T) {
var store = TestStore{}
var sess *Session = NewSession(store, "test")
var newSession *Session = &Session{
store: store,
name: "test",
Values: make(map[string]interface{}),
}
if !reflect.DeepEqual(sess, newSession) {
t.Fatal("Failed to init session", sess, newSession)
}
}
// TestSessionMethods - test Sessions methodd
func TestSessionMethods(t *testing.T) {
store := TestStore{}
req, err := http.NewRequest("GET", "http://www.example.com", nil)
if err != nil {
t.Fatal("failed to create request", err)
}
w := httptest.NewRecorder()
session, err := store.New(req, "test")
if err != nil {
t.Fatal("failed to create session", err)
}
if session.Name() != "test" {
t.Fatal("failed get session name", err)
}
var sess *Session = NewSession(store, "test")
if !reflect.DeepEqual(sess.Store(), store) {
t.Fatal("failed get session store", err)
}
err = sess.Save(w)
if err != nil {
t.Fatal("failed to save session", err)
}
}