2015-06-11 04:27:48 +00:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2016-03-01 00:51:26 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2015-06-11 04:27:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetSetUsers(t *testing.T) {
|
|
|
|
channelStore := NewChannelStore()
|
2017-05-10 03:44:59 +00:00
|
|
|
users := []string{"a", "b"}
|
2015-06-11 04:27:48 +00:00
|
|
|
channelStore.SetUsers(users, "srv", "#chan")
|
2017-05-10 03:44:59 +00:00
|
|
|
assert.Equal(t, users, channelStore.GetUsers("srv", "#chan"))
|
2015-06-11 04:27:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestAddRemoveUser(t *testing.T) {
|
|
|
|
channelStore := NewChannelStore()
|
|
|
|
channelStore.AddUser("user", "srv", "#chan")
|
2016-01-22 03:45:41 +00:00
|
|
|
channelStore.AddUser("user", "srv", "#chan")
|
|
|
|
assert.Len(t, channelStore.GetUsers("srv", "#chan"), 1)
|
2015-06-11 04:27:48 +00:00
|
|
|
channelStore.AddUser("user2", "srv", "#chan")
|
2016-01-17 22:33:52 +00:00
|
|
|
assert.Equal(t, []string{"user", "user2"}, channelStore.GetUsers("srv", "#chan"))
|
2015-06-11 04:27:48 +00:00
|
|
|
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"))
|
2017-02-21 12:56:04 +00:00
|
|
|
|
|
|
|
channelStore.AddUser("@gotop", "srv", "#chan3")
|
|
|
|
channelStore.RenameUser("gotop", "stillgotit", "srv")
|
|
|
|
assert.Equal(t, []string{"@stillgotit"}, channelStore.GetUsers("srv", "#chan3"))
|
2015-06-11 04:27:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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", "")
|
2017-05-10 03:44:59 +00:00
|
|
|
assert.Equal(t, []string{"@user"}, channelStore.GetUsers("srv", "#chan"))
|
|
|
|
channelStore.SetMode("srv", "#chan", "user", "", "o")
|
2015-06-11 04:27:48 +00:00
|
|
|
assert.Equal(t, []string{"+user"}, channelStore.GetUsers("srv", "#chan"))
|
2017-05-10 03:44:59 +00:00
|
|
|
channelStore.SetMode("srv", "#chan", "user", "q", "")
|
|
|
|
assert.Equal(t, []string{"~user"}, channelStore.GetUsers("srv", "#chan"))
|
2015-06-11 04:27:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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"))
|
|
|
|
}
|
2017-05-10 03:44:59 +00:00
|
|
|
|
|
|
|
func TestChannelUserMode(t *testing.T) {
|
|
|
|
user := NewChannelStoreUser("&test")
|
|
|
|
assert.Equal(t, "test", user.nick)
|
|
|
|
assert.Equal(t, "a", string(user.modes[0]))
|
|
|
|
assert.Equal(t, "&test", user.String())
|
|
|
|
|
|
|
|
user.removeModes("a")
|
|
|
|
assert.Equal(t, "test", user.String())
|
|
|
|
user.addModes("o")
|
|
|
|
assert.Equal(t, "@test", user.String())
|
|
|
|
user.addModes("q")
|
|
|
|
assert.Equal(t, "~test", user.String())
|
|
|
|
user.addModes("v")
|
|
|
|
assert.Equal(t, "~test", user.String())
|
|
|
|
user.removeModes("qo")
|
|
|
|
assert.Equal(t, "+test", user.String())
|
|
|
|
user.removeModes("v")
|
|
|
|
assert.Equal(t, "test", user.String())
|
|
|
|
}
|