-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwares-test[session-manager]_test.go
72 lines (67 loc) · 1.9 KB
/
wares-test[session-manager]_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
67
68
69
70
71
72
// Copyright 2015 Afshin Darian. All rights reserved.
// Use of this source code is governed by The MIT License
// that can be found in the LICENSE file.
package wares_test
import (
"errors"
"time"
"github.com/ursiform/bear"
"github.com/ursiform/forest"
)
// implements SessionManager
type sessionManager struct{}
func (manager *sessionManager) Create(sessionID string, userID string,
userJSON string, ctx *bear.Context) error {
testError, ok := ctx.Get("testerror").(bool)
if !ok {
testError = false
}
if testError {
return errors.New("manager.Create error")
} else {
ctx.Set(forest.SessionID, sessionID)
ctx.Set(forest.SessionUserID, userID)
return nil
}
}
func (manager *sessionManager) CreateEmpty(sessionID string,
ctx *bear.Context) {
ctx.Set(forest.SessionID, sessionID)
}
func (manager *sessionManager) Delete(sessionID string, userID string) error {
if sessionID == sessionIDWithDeleteError {
return errors.New("manager.Delete error")
}
return nil
}
func (manager *sessionManager) Marshal(ctx *bear.Context) ([]byte, error) {
sessionID := ctx.Get(forest.SessionID).(string)
if sessionID == sessionIDWithMarshalError {
return nil, errors.New("manager.Marshal error")
}
if sessionID == sessionIDWithSelfDestruct {
ctx.Set(forest.SessionID, nil)
}
if sessionID == sessionIDWithUserDestruct {
ctx.Set(forest.SessionUserID, nil)
}
return []byte(sessionUserJSON), nil
}
func (manager *sessionManager) Read(sessionID string) (userID string,
userJSON string, err error) {
if sessionID == sessionIDNonExistent {
return "", "", nil
} else {
return sessionUserID, sessionUserJSON, nil
}
}
func (manager *sessionManager) Revoke(userID string) error {
return nil
}
func (manager *sessionManager) Update(sessionID string, userID string,
userJSON string, duration time.Duration) error {
if sessionID == sessionIDWithUpdateError {
return errors.New("manager.Update error")
}
return nil
}