-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser_test.go
More file actions
37 lines (34 loc) · 1.03 KB
/
parser_test.go
File metadata and controls
37 lines (34 loc) · 1.03 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
package main
import "testing"
func TestParseConnectionDetails(t *testing.T) {
tests := []struct {
input string
wantHost string
wantPort int
wantErr bool
}{
{"127.0.0.1:28016", "127.0.0.1", 28016, false},
{"localhost:28016", "localhost", 28016, false},
{"invalid:port", "", 0, true},
{"missingport", "", 0, true},
{"256.256.256.256:28016", "", 0, true},
{"127.0.0.1:70000", "", 0, true},
{"127.0.0.1:-1", "", 0, true},
{"127.0.0.1:0", "", 0, true},
{"127.0.0.1:65536", "", 0, true},
{"example.com:80", "", 0, true},
}
for _, tt := range tests {
gotHost, gotPort, gotErr := ParseConnectionDetails(tt.input)
if (gotErr != nil) != tt.wantErr {
t.Errorf("ParseConnectionDetails(%q) error = %v, wantErr %v", tt.input, gotErr, tt.wantErr)
continue
}
if gotHost != tt.wantHost {
t.Errorf("ParseConnectionDetails(%q) gotHost = %v, want %v", tt.input, gotHost, tt.wantHost)
}
if gotPort != tt.wantPort {
t.Errorf("ParseConnectionDetails(%q) gotPort = %v, want %v", tt.input, gotPort, tt.wantPort)
}
}
}