Update test to reflect current behavior
This commit is contained in:
parent
a5c62fc572
commit
d40a65b6a3
1 changed files with 12 additions and 21 deletions
|
@ -19,18 +19,15 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var tokenTests = []struct {
|
var tokenTests = []struct {
|
||||||
inLabel string
|
inLabel string
|
||||||
inBody string
|
inBody string
|
||||||
inSession *settings.Session
|
storeErr error
|
||||||
inHaveSess bool
|
outCode int
|
||||||
storeErr error
|
outKind string
|
||||||
outCode int
|
|
||||||
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
|
|
||||||
store.On("AddToken", mock.AnythingOfType("*types.Token")).Return(test.storeErr).Once()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// prepare the mock
|
||||||
|
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)
|
||||||
|
|
Loading…
Reference in a new issue