-
-
Notifications
You must be signed in to change notification settings - Fork 78
/
url_test.go
65 lines (56 loc) · 2.67 KB
/
url_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright (c) 2022 Tulir Asokan
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package mautrix_test
import (
"testing"
"github.com/stretchr/testify/assert"
"maunium.net/go/mautrix"
)
func TestClient_BuildURL(t *testing.T) {
cli, err := mautrix.NewClient("https://example.com", "", "")
assert.NoError(t, err)
assert.Equal(t, cli.HomeserverURL.Scheme, "https")
assert.Equal(t, cli.HomeserverURL.Host, "example.com")
assert.Equal(t, cli.HomeserverURL.Path, "")
built := cli.BuildClientURL("v3", "foo/bar%2F🐈 1", "hello", "world")
assert.Equal(t, "https://example.com/_matrix/client/v3/foo%2Fbar%252F%F0%9F%90%88%201/hello/world", built)
}
func TestClient_BuildURL_HTTP(t *testing.T) {
cli, err := mautrix.NewClient("http://example.com", "", "")
assert.NoError(t, err)
assert.Equal(t, cli.HomeserverURL.Scheme, "http")
assert.Equal(t, cli.HomeserverURL.Host, "example.com")
assert.Equal(t, cli.HomeserverURL.Path, "")
built := cli.BuildClientURL("v3", "foo/bar%2F🐈 1", "hello", "world")
assert.Equal(t, "http://example.com/_matrix/client/v3/foo%2Fbar%252F%F0%9F%90%88%201/hello/world", built)
}
func TestClient_BuildURL_MissingScheme(t *testing.T) {
cli, err := mautrix.NewClient("example.com", "", "")
assert.NoError(t, err)
assert.Equal(t, cli.HomeserverURL.Scheme, "https")
assert.Equal(t, cli.HomeserverURL.Host, "example.com")
assert.Equal(t, cli.HomeserverURL.Path, "")
built := cli.BuildClientURL("v3", "foo/bar%2F🐈 1", "hello", "world")
assert.Equal(t, "https://example.com/_matrix/client/v3/foo%2Fbar%252F%F0%9F%90%88%201/hello/world", built)
}
func TestClient_BuildURL_WithPath(t *testing.T) {
cli, err := mautrix.NewClient("https://example.com/base", "", "")
assert.NoError(t, err)
assert.Equal(t, cli.HomeserverURL.Scheme, "https")
assert.Equal(t, cli.HomeserverURL.Host, "example.com")
assert.Equal(t, cli.HomeserverURL.Path, "/base")
built := cli.BuildClientURL("v3", "foo/bar%2F🐈 1", "hello", "world")
assert.Equal(t, "https://example.com/base/_matrix/client/v3/foo%2Fbar%252F%F0%9F%90%88%201/hello/world", built)
}
func TestClient_BuildURL_MissingSchemeWithPath(t *testing.T) {
cli, err := mautrix.NewClient("example.com/base", "", "")
assert.NoError(t, err)
assert.Equal(t, cli.HomeserverURL.Scheme, "https")
assert.Equal(t, cli.HomeserverURL.Host, "example.com")
assert.Equal(t, cli.HomeserverURL.Path, "/base")
built := cli.BuildClientURL("v3", "foo/bar%2F🐈 1", "hello", "world")
assert.Equal(t, "https://example.com/base/_matrix/client/v3/foo%2Fbar%252F%F0%9F%90%88%201/hello/world", built)
}