forked from asciimoo/hister
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig_test.go
More file actions
49 lines (44 loc) · 1.58 KB
/
Copy pathconfig_test.go
File metadata and controls
49 lines (44 loc) · 1.58 KB
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
package config
import "testing"
func TestBasePathPrefix(t *testing.T) {
tests := []struct {
name string
base string
prefix string
}{
{name: "root-no-slash", base: "https://example.com", prefix: ""},
{name: "root-with-slash", base: "https://example.com/", prefix: ""},
{name: "subfolder", base: "https://example.com/subfolder", prefix: "/subfolder"},
{name: "subfolder-trailing", base: "https://example.com/subfolder/", prefix: "/subfolder"},
{name: "nested", base: "https://example.com/a/b", prefix: "/a/b"},
{name: "nested-trailing", base: "https://example.com/a/b/", prefix: "/a/b"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cfg := &Config{Server: Server{BaseURL: tt.base}}
if got := cfg.BasePathPrefix(); got != tt.prefix {
t.Fatalf("BasePathPrefix()=%q, want %q", got, tt.prefix)
}
})
}
}
func TestWebSocketURLHonorsBasePath(t *testing.T) {
tests := []struct {
name string
base string
want string
}{
{name: "http-root", base: "http://example.com:1234", want: "ws://example.com:1234/search"},
{name: "https-root", base: "https://example.com", want: "wss://example.com/search"},
{name: "http-subfolder", base: "http://example.com/subfolder", want: "ws://example.com/subfolder/search"},
{name: "https-nested", base: "https://example.com/a/b/", want: "wss://example.com/a/b/search"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cfg := &Config{Server: Server{BaseURL: tt.base}}
if got := cfg.WebSocketURL(); got != tt.want {
t.Fatalf("WebSocketURL()=%q, want %q", got, tt.want)
}
})
}
}