From a9390d3b5c308ccab7f15748a6187865988dafe2 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 2 May 2018 23:45:17 +0300 Subject: Add more session and config tests --- matrix/matrix_test.go | 27 ++++++++++++++++++++++++++- matrix/rooms/room_test.go | 16 ++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) (limited to 'matrix') diff --git a/matrix/matrix_test.go b/matrix/matrix_test.go index c5acda8..35debe1 100644 --- a/matrix/matrix_test.go +++ b/matrix/matrix_test.go @@ -14,4 +14,29 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -package matrix_test +package matrix + +import ( + "testing" + "maunium.net/go/gomuks/config" + "github.com/stretchr/testify/assert" +) + +func TestContainer_InitClient_Empty(t *testing.T) { + cfg := config.NewConfig("/tmp/gomuks-mxtest-0", "/tmp/gomuks-mxtest-0") + cfg.HS = "https://matrix.org" + c := Container{config: cfg} + assert.Nil(t, c.InitClient()) +} + +func TestContainer_renderMarkdown(t *testing.T) { + text := "**foo** _bar_" + c := Container{} + assert.Equal(t, "foo bar", c.renderMarkdown(text)) +} + +func TestContainer_GetCachePath(t *testing.T) { + cfg := config.NewConfig("/tmp/gomuks-mxtest-1", "/tmp/gomuks-mxtest-1") + c := Container{config: cfg} + assert.Equal(t, "/tmp/gomuks-mxtest-1/media/maunium.net/foobar", c.GetCachePath("maunium.net", "foobar")) +} diff --git a/matrix/rooms/room_test.go b/matrix/rooms/room_test.go index 40624e1..2ad8d54 100644 --- a/matrix/rooms/room_test.go +++ b/matrix/rooms/room_test.go @@ -59,6 +59,22 @@ func TestRoom_GetTopic(t *testing.T) { assert.Equal(t, "test topic", room.GetTopic()) } +func TestRoom_Tags_Empty(t *testing.T) { + room := rooms.NewRoom("!test:maunium.net", "@tulir:maunium.net") + assert.Empty(t, room.RawTags) + tags := room.Tags() + assert.Len(t, tags, 1) + assert.Equal(t, "", tags[0].Tag) + assert.Equal(t, 0.5, tags[0].Order) +} + +func TestRoom_Tags_NotEmpty(t *testing.T) { + room := rooms.NewRoom("!test:maunium.net", "@tulir:maunium.net") + room.RawTags = []rooms.RoomTag{{"foo", 1}, {"bar", 1}} + tags := room.Tags() + assert.Equal(t, room.RawTags, tags) +} + func TestRoom_GetAliases(t *testing.T) { room := rooms.NewRoom("!test:maunium.net", "@tulir:maunium.net") addAliases(room) -- cgit v1.2.3