-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathruntime_test.go
More file actions
59 lines (54 loc) · 1.78 KB
/
Copy pathruntime_test.go
File metadata and controls
59 lines (54 loc) · 1.78 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
50
51
52
53
54
55
56
57
58
59
package main
import (
"slices"
"strings"
"testing"
)
func TestLoadModerators(t *testing.T) {
got, err := loadModerators(strings.NewReader(" Alice \n\nBob\r\nAlice\n"))
if err != nil {
t.Fatalf("load moderators: %v", err)
}
if len(got) != 2 {
t.Fatalf("moderator count = %d, want 2", len(got))
}
for _, name := range []string{"Alice", "Bob"} {
if _, ok := got[name]; !ok {
t.Fatalf("moderator %q missing from %#v", name, got)
}
}
}
func TestBackendAddresses(t *testing.T) {
if got, want := backendAddresses("primary:19132", "backup:19132"), []string{"primary:19132", "backup:19132"}; !slices.Equal(got, want) {
t.Fatalf("backend addresses = %v, want %v", got, want)
}
if got, want := backendAddresses("primary:19132", "primary:19132"), []string{"primary:19132"}; !slices.Equal(got, want) {
t.Fatalf("duplicate backend addresses = %v, want %v", got, want)
}
}
func TestConfiguredRemoteAddress(t *testing.T) {
if got, want := configuredRemoteAddress("configured:19132", ""), "configured:19132"; got != want {
t.Fatalf("configured remote address = %q, want %q", got, want)
}
if got, want := configuredRemoteAddress("configured:19132", "override:19132"), "override:19132"; got != want {
t.Fatalf("overridden remote address = %q, want %q", got, want)
}
}
func TestShutdownTarget(t *testing.T) {
address, port, ok := shutdownTarget("play.example.com", 19132)
if !ok || address != "play.example.com" || port != 19132 {
t.Fatalf("shutdown target = %q, %d, %t", address, port, ok)
}
for _, test := range []struct {
address string
port int
}{
{"", 19132},
{"play.example.com", 0},
{"play.example.com", 65536},
} {
if _, _, ok := shutdownTarget(test.address, test.port); ok {
t.Fatalf("shutdown target %q:%d unexpectedly valid", test.address, test.port)
}
}
}