dispatch/storage/channel_test.go

73 lines
2.5 KiB
Go
Raw Normal View History

2015-06-11 04:27:48 +00:00
package storage
import (
"testing"
2015-12-11 03:35:48 +00:00
"github.com/khlieng/dispatch/Godeps/_workspace/src/github.com/stretchr/testify/assert"
2015-06-11 04:27:48 +00:00
)
func TestGetSetUsers(t *testing.T) {
channelStore := NewChannelStore()
users := []string{"a,b"}
channelStore.SetUsers(users, "srv", "#chan")
assert.Equal(t, channelStore.GetUsers("srv", "#chan"), users)
}
func TestAddRemoveUser(t *testing.T) {
channelStore := NewChannelStore()
channelStore.AddUser("user", "srv", "#chan")
channelStore.AddUser("user2", "srv", "#chan")
assert.Equal(t, channelStore.GetUsers("srv", "#chan"), []string{"user", "user2"})
channelStore.RemoveUser("user", "srv", "#chan")
assert.Equal(t, []string{"user2"}, channelStore.GetUsers("srv", "#chan"))
}
func TestRemoveUserAll(t *testing.T) {
channelStore := NewChannelStore()
channelStore.AddUser("user", "srv", "#chan1")
channelStore.AddUser("user", "srv", "#chan2")
channelStore.RemoveUserAll("user", "srv")
assert.Empty(t, channelStore.GetUsers("srv", "#chan1"))
assert.Empty(t, channelStore.GetUsers("srv", "#chan2"))
}
func TestRenameUser(t *testing.T) {
channelStore := NewChannelStore()
channelStore.AddUser("user", "srv", "#chan1")
channelStore.AddUser("user", "srv", "#chan2")
channelStore.RenameUser("user", "new", "srv")
assert.Equal(t, []string{"new"}, channelStore.GetUsers("srv", "#chan1"))
assert.Equal(t, []string{"new"}, channelStore.GetUsers("srv", "#chan2"))
}
func TestMode(t *testing.T) {
channelStore := NewChannelStore()
channelStore.AddUser("+user", "srv", "#chan")
channelStore.SetMode("srv", "#chan", "user", "o", "v")
assert.Equal(t, []string{"@user"}, channelStore.GetUsers("srv", "#chan"))
channelStore.SetMode("srv", "#chan", "user", "v", "")
assert.Equal(t, []string{"+user"}, channelStore.GetUsers("srv", "#chan"))
channelStore.SetMode("srv", "#chan", "user", "", "v")
assert.Equal(t, []string{"user"}, channelStore.GetUsers("srv", "#chan"))
}
func TestTopic(t *testing.T) {
channelStore := NewChannelStore()
assert.Equal(t, "", channelStore.GetTopic("srv", "#chan"))
channelStore.SetTopic("the topic", "srv", "#chan")
assert.Equal(t, "the topic", channelStore.GetTopic("srv", "#chan"))
}
2015-12-28 23:34:32 +00:00
func TestFindUserChannels(t *testing.T) {
channelStore := NewChannelStore()
channelStore.AddUser("user", "srv", "#chan1")
channelStore.AddUser("user", "srv", "#chan2")
channelStore.AddUser("user2", "srv", "#chan3")
channelStore.AddUser("user", "srv2", "#chan4")
2015-12-29 10:32:10 +00:00
channels := channelStore.FindUserChannels("user", "srv")
assert.Len(t, channels, 2)
assert.Contains(t, channels, "#chan1")
assert.Contains(t, channels, "#chan2")
2015-12-28 23:34:32 +00:00
}