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