github.com/volatiletech/authboss@v2.4.1+incompatible/storage_test.go (about) 1 package authboss 2 3 import ( 4 "context" 5 "testing" 6 ) 7 8 type testAssertionFailStorer struct{} 9 10 func (testAssertionFailStorer) Load(ctx context.Context, key string) (User, error) { return nil, nil } 11 func (testAssertionFailStorer) Save(ctx context.Context, user User) error { return nil } 12 13 func TestStorageAssertions(t *testing.T) { 14 t.Parallel() 15 16 s := &mockServerStorer{} 17 fs := testAssertionFailStorer{} 18 19 paniced := false 20 func() { 21 defer func() { 22 if r := recover(); r != nil { 23 paniced = true 24 } 25 }() 26 27 EnsureCanCreate(s) 28 EnsureCanConfirm(s) 29 EnsureCanRecover(s) 30 EnsureCanRemember(s) 31 EnsureCanOAuth2(s) 32 }() 33 34 if paniced { 35 t.Error("The mock storer should have included all interfaces and should not panic") 36 } 37 38 didPanic := func(f func()) (paniced bool) { 39 defer func() { 40 if r := recover(); r != nil { 41 paniced = true 42 } 43 }() 44 45 f() 46 return paniced 47 } 48 49 if !didPanic(func() { EnsureCanCreate(fs) }) { 50 t.Error("should have panic'd") 51 } 52 if !didPanic(func() { EnsureCanConfirm(fs) }) { 53 t.Error("should have panic'd") 54 } 55 if !didPanic(func() { EnsureCanRecover(fs) }) { 56 t.Error("should have panic'd") 57 } 58 if !didPanic(func() { EnsureCanRemember(fs) }) { 59 t.Error("should have panic'd") 60 } 61 if !didPanic(func() { EnsureCanOAuth2(fs) }) { 62 t.Error("should have panic'd") 63 } 64 }