mirror of
https://github.com/volatiletech/authboss.git
synced 2025-07-13 01:20:17 +02:00
Add session and cookie concepts.
- Add tests for callbacks. - Refactor callbacks into a keyed map.
This commit is contained in:
38
callbacks_test.go
Normal file
38
callbacks_test.go
Normal file
@ -0,0 +1,38 @@
|
||||
package authboss
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestCallbacks(t *testing.T) {
|
||||
afterCalled := false
|
||||
beforeCalled := false
|
||||
c := NewCallbacks()
|
||||
|
||||
c.Before(EventRegister, func(ctx *Context) error {
|
||||
beforeCalled = true
|
||||
return nil
|
||||
})
|
||||
c.After(EventRegister, func(ctx *Context) {
|
||||
afterCalled = true
|
||||
})
|
||||
|
||||
if beforeCalled || afterCalled {
|
||||
t.Error("Neither should be called.")
|
||||
}
|
||||
|
||||
err := c.FireBefore(EventRegister, NewContext())
|
||||
if err != nil {
|
||||
t.Error("Unexpected error:", err)
|
||||
}
|
||||
|
||||
if !beforeCalled {
|
||||
t.Error("Expected before to have been called.")
|
||||
}
|
||||
if afterCalled {
|
||||
t.Error("Expected after not to be called.")
|
||||
}
|
||||
|
||||
c.FireAfter(EventRegister, NewContext())
|
||||
if !afterCalled {
|
||||
t.Error("Expected after to be called.")
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user