-
Notifications
You must be signed in to change notification settings - Fork 9
/
testing_persistence.go
56 lines (43 loc) · 1.19 KB
/
testing_persistence.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
package test161
import (
"errors"
)
// A fake persistence to use for test code
var testStudent = &Student{
Email: "[email protected]",
Token: "TestToken4$5^",
}
type TestingPersistence struct {
Verbose bool
}
func (p *TestingPersistence) Close() {
}
func (p *TestingPersistence) Notify(entity interface{}, msg, what int) error {
return nil
}
func (d *TestingPersistence) CanRetrieve() bool {
return true
}
func (d *TestingPersistence) Retrieve(what int, who map[string]interface{},
filter map[string]interface{}, res interface{}) error {
switch what {
case PERSIST_TYPE_STUDENTS:
if email, _ := who["email"]; email == testStudent.Email {
if token, _ := who["token"]; token == testStudent.Token {
students := res.(*[]*Student)
*students = append(*students, testStudent)
}
}
return nil
case PERSIST_TYPE_USERS:
// Only currently used to get the staff flag, and only the length is
// checked. Since it's like 4 levels deep, we'll just fake it.
if id, _ := who["services.auth0.email"]; id == testStudent.Email {
results := res.(*[]interface{})
*results = append(*results, 1)
}
return nil
default:
return errors.New("Persistence: Invalid data type")
}
}