-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
84 lines (80 loc) · 1.78 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"testing"
)
func Test_validAddr(t *testing.T) {
type args struct {
s string
}
tests := []struct {
name string
args args
wantErr bool
}{
{"empty", args{""}, true},
{"only_port", args{":8080"}, false},
{"only_addr", args{"localhost"}, true},
{"full", args{"192.168.10.1:8181"}, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := validAddr(tt.args.s); (err != nil) != tt.wantErr {
t.Errorf("validAddr() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
func Test_trimFirst(t *testing.T) {
type args struct {
s string
}
tests := []struct {
name string
args args
want string
}{
{"empty", args{""}, ""},
{"one", args{"a"}, ""},
{"two", args{"ab"}, "b"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := trimFirst(tt.args.s); got != tt.want {
t.Errorf("trimFirst() = %v, want %v", got, tt.want)
}
})
}
}
func Test_splitToKeyValue(t *testing.T) {
type args struct {
s string
sep string
}
tests := []struct {
name string
args args
want string
want1 string
wantErr bool
}{
{"empty", args{"", ":"}, "", "", true},
{"only_key", args{"key", ":"}, "", "", true},
{"only_value", args{"value", ":"}, "", "", true},
{"key_value", args{"key:value", ":"}, "key", "value", false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, got1, err := splitToKeyValue(tt.args.s, tt.args.sep)
if (err != nil) != tt.wantErr {
t.Errorf("splitToKeyValue() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("splitToKeyValue() got = %v, want %v", got, tt.want)
}
if got1 != tt.want1 {
t.Errorf("splitToKeyValue() got1 = %v, want %v", got1, tt.want1)
}
})
}
}