Beispiel #1
0
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"))
}
Beispiel #2
0
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")))
}
Beispiel #3
0
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"))
}