1
0
mirror of https://github.com/volatiletech/authboss.git synced 2024-11-30 09:06:45 +02:00
authboss/client_storer_test.go
Aaron f12f10fa43 Stop reliance on global scope.
- This change was necessary because multi-tenancy sites could not use
  authboss properly.
2015-03-31 12:34:03 -07:00

58 lines
1.3 KiB
Go

package authboss
import (
"net/http"
"testing"
)
type testClientStorerErr string
func (t testClientStorerErr) Put(key, value string) {}
func (t testClientStorerErr) Get(key string) (string, bool) {
return string(t), key == string(t)
}
func (t testClientStorerErr) Del(key string) {}
func TestClientStorerErr(t *testing.T) {
t.Parallel()
var cs testClientStorerErr
csw := clientStoreWrapper{&cs}
if _, err := csw.GetErr("hello"); err == nil {
t.Error("Expected an error")
}
cs = "hello"
if str, err := csw.GetErr("hello"); err != nil {
t.Error(err)
} else if str != "hello" {
t.Error("Wrong value:", str)
}
}
func TestFlashClearer(t *testing.T) {
t.Parallel()
session := mockClientStore{FlashSuccessKey: "success", FlashErrorKey: "error"}
ab := New()
ab.SessionStoreMaker = func(w http.ResponseWriter, r *http.Request) ClientStorer {
return session
}
if msg := ab.FlashSuccess(nil, nil); msg != "success" {
t.Error("Unexpected flash success:", msg)
}
if msg, ok := session.Get(FlashSuccessKey); ok {
t.Error("Unexpected success flash:", msg)
}
if msg := ab.FlashError(nil, nil); msg != "error" {
t.Error("Unexpected flash error:", msg)
}
if msg, ok := session.Get(FlashErrorKey); ok {
t.Error("Unexpected error flash:", msg)
}
}