func TestAdminAuthToken(t *testing.T) { app := testApp() // first without secret set err := app.checkAdminAuthToken("") assert.Equal(t, ErrUnauthorized, err) // no web secret set token, err := app.adminAuthToken() if err == nil { println(app.config.WebSecret) println(token) } assert.Equal(t, ErrInternalServerError, err) app.Lock() app.config.WebSecret = "secret" app.Unlock() err = app.checkAdminAuthToken("") assert.Equal(t, ErrUnauthorized, err) token, err = app.adminAuthToken() assert.Equal(t, nil, err) assert.True(t, len(token) > 0) err = app.checkAdminAuthToken(token) assert.Equal(t, nil, err) }
func TestMarshalling(t *testing.T) { SetConfigType("yaml") r := bytes.NewReader(yamlExample) marshalReader(r, v.config) assert.True(t, InConfig("name")) assert.False(t, InConfig("state")) assert.Equal(t, "steve", Get("name")) assert.Equal(t, []interface{}{"skateboarding", "snowboarding", "go"}, Get("hobbies")) assert.Equal(t, map[interface{}]interface{}{"jacket": "leather", "trousers": "denim", "pants": map[interface{}]interface{}{"size": "large"}}, Get("clothing")) assert.Equal(t, 35, Get("age")) }
func TestSubHub(t *testing.T) { h := newClientHub() c := newTestUserCC() h.addSub("test1", c) h.addSub("test2", c) assert.Equal(t, 2, h.nChannels()) channels := []string{} for _, ch := range h.channels() { channels = append(channels, string(ch)) } assert.Equal(t, stringInSlice("test1", channels), true) assert.Equal(t, stringInSlice("test2", channels), true) assert.True(t, h.hasSubscribers(ChannelID("test1"))) assert.True(t, h.hasSubscribers(ChannelID("test2"))) err := h.broadcast("test1", []byte("message")) assert.Equal(t, err, nil) h.removeSub("test1", c) h.removeSub("test2", c) assert.Equal(t, len(h.subs), 0) assert.False(t, h.hasSubscribers(ChannelID("test1"))) assert.False(t, h.hasSubscribers(ChannelID("test2"))) }
func TestReadBufConfig(t *testing.T) { v := New() v.SetConfigType("yaml") v.ReadConfig(bytes.NewBuffer(yamlExample)) t.Log(v.AllKeys()) assert.True(t, v.InConfig("name")) assert.False(t, v.InConfig("state")) assert.Equal(t, "steve", v.Get("name")) assert.Equal(t, []interface{}{"skateboarding", "snowboarding", "go"}, v.Get("hobbies")) assert.Equal(t, map[interface{}]interface{}{"jacket": "leather", "trousers": "denim", "pants": map[interface{}]interface{}{"size": "large"}}, v.Get("clothing")) assert.Equal(t, 35, v.Get("age")) }
func TestAdminAuthToken(t *testing.T) { app := testApp() // first without secret set token, err := app.adminAuthToken() assert.Equal(t, nil, err) assert.True(t, len(token) > 0) err = app.checkAdminAuthToken("") assert.Equal(t, ErrUnauthorized, err) err = app.checkAdminAuthToken(token) assert.Equal(t, ErrUnauthorized, err) // now with secret set app.config.WebSecret = "test" token, err = app.adminAuthToken() assert.Equal(t, nil, err) err = app.checkAdminAuthToken(token) assert.Equal(t, nil, err) }