From f6a1f793fbc76ae313d205370df234c9e11a7a53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ken-H=C3=A5vard=20Lieng?= Date: Thu, 11 Jun 2015 06:27:48 +0200 Subject: [PATCH] Test ChannelStore --- storage/channel_test.go | 59 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 storage/channel_test.go diff --git a/storage/channel_test.go b/storage/channel_test.go new file mode 100644 index 00000000..ff087c20 --- /dev/null +++ b/storage/channel_test.go @@ -0,0 +1,59 @@ +package storage + +import ( + "testing" + + "github.com/khlieng/name_pending/Godeps/_workspace/src/github.com/stretchr/testify/assert" +) + +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")) +}