1
0
mirror of https://github.com/volatiletech/authboss.git synced 2025-01-10 04:17:59 +02:00
authboss/module_test.go
Aaron a2ffe4f7c4 Add many new files and types.
- Add context.
- Add handler type.
- Add new storers for client storage and sessions.
- Add start of remember module.
2015-01-10 22:54:31 -08:00

61 lines
1.0 KiB
Go

package authboss
import (
"net/http"
"testing"
)
const testModName = "testmodule"
type testModule struct {
c *Config
s StorageOptions
r RouteTable
}
var testMod = &testModule{
r: RouteTable{
"/testroute": testHandler,
},
}
func testHandler(ctx *Context, w http.ResponseWriter, r *http.Request) {
w.Header().Set("testhandler", "test")
}
func (t *testModule) Initialize(c *Config) error {
t.c = c
return nil
}
func (t *testModule) Routes() RouteTable {
return t.r
}
func (t *testModule) Storage() StorageOptions {
return t.s
}
func TestRegister(t *testing.T) {
t.Parallel()
// RegisterModule called by TestMain.
if _, ok := modules["testmodule"]; !ok {
t.Error("Expected module to be saved.")
}
}
func TestLoadedModules(t *testing.T) {
t.Parallel()
// RegisterModule called by TestMain.
loadedMods := LoadedModules()
if len(loadedMods) != 1 {
t.Error("Expected only a single module to be loaded.")
} else if loadedMods[0] != "testmodule" {
t.Error("Expected testmodule to be loaded.")
}
}