1
0
mirror of https://github.com/volatiletech/authboss.git synced 2025-01-10 04:17:59 +02:00
authboss/authboss_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

54 lines
988 B
Go

package authboss
import (
"net/http"
"net/http/httptest"
"os"
"strings"
"testing"
)
func TestMain(main *testing.M) {
RegisterModule("testmodule", testMod)
Init(NewConfig())
code := main.Run()
os.Exit(code)
}
func TestAuthBossInit(t *testing.T) {
c := NewConfig()
err := Init(c)
if err == nil || !strings.Contains(err.Error(), "storer") {
t.Error("Expected error about a storer, got:", err)
}
c.Storer = testStorer(0)
err = Init(c)
if err != nil {
t.Error("Unexpected error:", err)
}
if testMod.c == nil {
t.Error("Expected the modules to be passed the config.")
}
}
func TestAuthBossRouter(t *testing.T) {
t.Parallel()
c := NewConfig()
c.MountPath = "/candycanes"
c.LogWriter = os.Stdout
router := NewRouter(c)
r, _ := http.NewRequest("GET", "/candycanes/testroute", nil)
response := httptest.NewRecorder()
router.ServeHTTP(response, r)
if response.Header().Get("testhandler") != "test" {
t.Error("Expected a header to have been set.")
}
}