forked from davecheney/httpstat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
64 lines (53 loc) · 1.51 KB
/
main_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
package main
import (
"testing"
"github.com/mitchellh/hashstructure/v2"
)
func TestParseURL(t *testing.T) {
tests := []struct {
in string
want string
}{
{"https://golang.org", "https://golang.org"},
{"https://golang.org:443/test", "https://golang.org:443/test"},
{"localhost:8080/test", "https://localhost:8080/test"},
{"localhost:80/test", "http://localhost:80/test"},
{"//localhost:8080/test", "https://localhost:8080/test"},
{"//localhost:80/test", "http://localhost:80/test"},
}
for _, test := range tests {
u := parseURL(test.in)
if u.String() != test.want {
t.Errorf("Given: %s\nwant: %s\ngot: %s", test.in, test.want, u.String())
}
}
}
func TestHashConfig(t *testing.T) {
c1 := HTTPServerConfig{
Host: "abcd.ch",
URL: "server101.comp.ch",
IPVersion: "any",
ExtraLabels: map[string]string{
"Allow-Compression": "true",
"Some-Header": "Some-Value",
},
}
c2 := HTTPServerConfig{
Host: "abcd.ch",
URL: "server101.comp.ch",
IPVersion: "any",
ExtraLabels: map[string]string{
"Allow-Compression": "true",
},
}
h1, _ := hashstructure.Hash(c1, hashstructure.FormatV2, nil)
h2, _ := hashstructure.Hash(c2, hashstructure.FormatV2, nil)
if h1 == h2 {
t.Error("comparison of HTTP Config with hashv2 should not have been identical")
}
c2.ExtraLabels["Some-Header"] = "Some-Value"
h2, _ = hashstructure.Hash(c2, hashstructure.FormatV2, nil)
if h1 == h2 {
t.Error("comparison of HTTP Config with hashv2 should not have been identical")
}
}