aboutsummaryrefslogtreecommitdiff
path: root/matrix/matrix_test.go
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2018-05-11 08:12:11 +0300
committerTulir Asokan <tulir@maunium.net>2018-05-11 08:12:11 +0300
commitb416d7d8b0fd8392efe9666ed53f1c6b47490d2a (patch)
tree920fa93a5fac4606a82dc16b207758f48aeb9a7e /matrix/matrix_test.go
parentd53aa02c0f6cc0b153d227167fcf3b5c74e12d3a (diff)
Add tests for downloading invalid URLs and getting history
Diffstat (limited to 'matrix/matrix_test.go')
-rw-r--r--matrix/matrix_test.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/matrix/matrix_test.go b/matrix/matrix_test.go
index 68ddfc9..cf03d55 100644
--- a/matrix/matrix_test.go
+++ b/matrix/matrix_test.go
@@ -166,6 +166,29 @@ func TestContainer_Download(t *testing.T) {
assert.Equal(t, 1, callCounter)
}
+func TestContainer_Download_InvalidURL(t *testing.T) {
+ c := Container{}
+ data, hs, id, err := c.Download("mxc://invalid mxc")
+ assert.NotNil(t, err)
+ assert.Empty(t, id)
+ assert.Empty(t, hs)
+ assert.Empty(t, data)
+}
+
+func TestContainer_GetHistory(t *testing.T) {
+ c := Container{client: mockClient(func(req *http.Request) (*http.Response, error) {
+ if req.Method != http.MethodGet || req.URL.Path != "/_matrix/client/r0/rooms/!foo:maunium.net/messages" {
+ return nil, fmt.Errorf("unexpected query: %s %s", req.Method, req.URL.Path)
+ }
+ return mockResponse(http.StatusOK, `{"start": "123", "end": "456", "chunk": [{"event_id": "it works"}]}`), nil
+ })}
+
+ history, prevBatch, err := c.GetHistory("!foo:maunium.net", "123", 5)
+ assert.Nil(t, err)
+ assert.Equal(t, "it works", history[0].ID)
+ assert.Equal(t, "456", prevBatch)
+}
+
func mockClient(fn func(*http.Request) (*http.Response, error)) *gomatrix.Client {
client, _ := gomatrix.NewClient("https://example.com", "@user:example.com", "foobar")
client.Client = &http.Client{Transport: MockRoundTripper{RT: fn}}