mirror of
https://github.com/volatiletech/authboss.git
synced 2024-11-24 08:42:17 +02:00
c38f79490b
- Missed some actual tests, added them. - Added a bunch of useless tests to increase coverage. Guilty as charged.
65 lines
1.3 KiB
Go
65 lines
1.3 KiB
Go
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")
|
|
}
|
|
}
|