forked from volatiletech/authboss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
values_test.go
70 lines (56 loc) · 1.67 KB
/
values_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
package authboss
import "testing"
type testAssertionValues struct{}
func (testAssertionValues) Validate() []error { return nil }
func (testAssertionValues) GetPID() string { return "" }
func (testAssertionValues) GetPassword() string { return "" }
func (testAssertionValues) GetToken() string { return "" }
func (testAssertionValues) GetShouldRemember() bool { return false }
func (testAssertionValues) GetValues() map[string]string { return nil }
type testAssertionFailValues struct{}
func (testAssertionFailValues) Validate() []error { return nil }
func TestValueAssertions(t *testing.T) {
t.Parallel()
v := testAssertionValues{}
fv := testAssertionFailValues{}
paniced := false
func() {
defer func() {
if r := recover(); r != nil {
paniced = true
}
}()
MustHaveUserValues(v)
MustHaveConfirmValues(v)
MustHaveRecoverStartValues(v)
MustHaveRecoverMiddleValues(v)
MustHaveRecoverEndValues(v)
}()
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() { MustHaveUserValues(fv) }) {
t.Error("should have panic'd")
}
if !didPanic(func() { MustHaveConfirmValues(fv) }) {
t.Error("should have panic'd")
}
if !didPanic(func() { MustHaveRecoverStartValues(fv) }) {
t.Error("should have panic'd")
}
if !didPanic(func() { MustHaveRecoverMiddleValues(fv) }) {
t.Error("should have panic'd")
}
if !didPanic(func() { MustHaveRecoverEndValues(fv) }) {
t.Error("should have panic'd")
}
}