-
Notifications
You must be signed in to change notification settings - Fork 0
/
cert_test.go
47 lines (45 loc) · 1.18 KB
/
cert_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
package main
import (
"net/url"
"testing"
)
func TestNormalizeCertURL(t *testing.T) {
expectedOutURL1, _ := url.Parse("https://example.com/v1/cert.pem")
tests := []struct {
inURL string
expectOutURL *url.URL
expectOutURLHost string
expectError bool
}{
{
inURL: "http://example.com/v1/cert.pem",
expectOutURL: expectedOutURL1,
expectOutURLHost: "example.com",
expectError: false,
},
{
inURL: "example.com",
expectError: true,
},
{
inURL: "\n",
expectError: true,
},
}
for _, test := range tests {
outURL, err := normalizeCertURL(test.inURL)
if err != nil && !test.expectError {
t.Errorf("Unexpected error '%s' for URL '%s'", err, test.inURL)
return
}
if err == nil && test.expectError {
t.Errorf("Expected error for URL '%s' but got none", test.inURL)
}
if test.expectOutURL != nil && outURL.String() != test.expectOutURL.String() {
t.Errorf("Expected URL '%s' but got '%s'", test.expectOutURL, outURL)
}
if test.expectOutURLHost != "" && outURL.Host != test.expectOutURLHost {
t.Errorf("Expected URL.Host '%s' but got '%s'", test.expectOutURLHost, outURL.Host)
}
}
}