-
Notifications
You must be signed in to change notification settings - Fork 208
/
storage_test.go
64 lines (53 loc) · 1.29 KB
/
storage_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
package authboss
import (
"context"
"testing"
)
type testAssertionFailStorer struct{}
func (testAssertionFailStorer) Load(ctx context.Context, key string) (User, error) { return nil, nil }
func (testAssertionFailStorer) Save(ctx context.Context, user User) error { return nil }
func TestStorageAssertions(t *testing.T) {
t.Parallel()
s := &mockServerStorer{}
fs := testAssertionFailStorer{}
paniced := false
func() {
defer func() {
if r := recover(); r != nil {
paniced = true
}
}()
EnsureCanCreate(s)
EnsureCanConfirm(s)
EnsureCanRecover(s)
EnsureCanRemember(s)
EnsureCanOAuth2(s)
}()
if paniced {
t.Error("The mock storer should have included all interfaces and should not panic")
}
didPanic := func(f func()) (paniced bool) {
defer func() {
if r := recover(); r != nil {
paniced = true
}
}()
f()
return paniced
}
if !didPanic(func() { EnsureCanCreate(fs) }) {
t.Error("should have panic'd")
}
if !didPanic(func() { EnsureCanConfirm(fs) }) {
t.Error("should have panic'd")
}
if !didPanic(func() { EnsureCanRecover(fs) }) {
t.Error("should have panic'd")
}
if !didPanic(func() { EnsureCanRemember(fs) }) {
t.Error("should have panic'd")
}
if !didPanic(func() { EnsureCanOAuth2(fs) }) {
t.Error("should have panic'd")
}
}