Update test to reflect current behavior

This commit is contained in:
Ben Schumacher 2015-05-18 12:46:08 -06:00
parent a5c62fc572
commit d40a65b6a3

View file

@ -21,16 +21,13 @@ import (
var tokenTests = []struct { var tokenTests = []struct {
inLabel string inLabel string
inBody string inBody string
inSession *settings.Session
inHaveSess bool
storeErr error storeErr error
outCode int outCode int
outKind string outKind string
}{ }{
{"", `{}`, nil, false, nil, 500, ""}, {"", `{}`, sql.ErrNoRows, 500, ""},
{"", `{}`, &settings.Session{Secret: "Otto"}, false, sql.ErrNoRows, 500, ""}, {"app1", `{"label": "app1"}`, nil, 200, types.TokenUser},
{"app1", `{"label": "app1"}`, &settings.Session{Secret: "Otto"}, true, nil, 200, types.TokenUser}, {"app2", `{"label": "app2"}`, nil, 200, types.TokenUser},
{"app2", `{"label": "app2"}`, &settings.Session{Secret: "Otto"}, false, nil, 200, types.TokenUser},
} }
func TestToken(t *testing.T) { func TestToken(t *testing.T) {
@ -48,18 +45,12 @@ func TestToken(t *testing.T) {
ctx.Set("datastore", store) ctx.Set("datastore", store)
ctx.Set("user", &types.User{Login: "Freya"}) ctx.Set("user", &types.User{Login: "Freya"})
config := settings.Settings{Session: test.inSession} config := settings.Settings{Session: &settings.Session{Secret: "Otto"}}
ctx.Set("settings", &config) ctx.Set("settings", &config)
if test.inSession != nil { ctx.Set("session", session.New(config.Session))
// only set these up if we've got Session configuration
if test.inHaveSess {
ctx.Set("session", session.New(test.inSession))
}
// prepare the mock datastore // prepare the mock
store.On("AddToken", mock.AnythingOfType("*types.Token")).Return(test.storeErr).Once() store.On("AddToken", mock.AnythingOfType("*types.Token")).Return(test.storeErr).Once()
}
PostToken(&ctx) PostToken(&ctx)
g.Assert(rw.Code).Equal(test.outCode) g.Assert(rw.Code).Equal(test.outCode)