-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmain_test.go
59 lines (55 loc) · 1.82 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
package main
import (
"strings"
"testing"
)
type check struct {
target string
ctx string
rctype string
name string
ns string
ports string
address string
}
func Test_parse(t *testing.T) {
var args []string
args, _, _, _, _ = parse("8080:1222")
if args != nil {
t.Fatal("should be nil")
}
for _, v := range []check{
{"name:8080:1222", "", "pod", "name", "default", "8080:1222", ""},
{"deployment/name:8080:1222", "", "deployment", "deployment/name", "default", "8080:1222", ""},
{"system:service/name:8080:1222", "", "service", "service/name", "system", "8080:1222", ""},
{"ns=system:service/name:8080:1222", "", "service", "service/name", "system", "8080:1222", ""},
{"ctx=minikube:ns=system:deployment/name:8080:1222", "minikube", "deployment", "deployment/name", "system", "8080:1222", ""},
{"ctx=minikube:ns=system:deployment/name:127.0.0.2:8080:1222", "minikube", "deployment", "deployment/name", "system", "8080:1222", "127.0.0.2"},
{"ctx=minikube:system:name:8080:1222", "minikube", "pod", "name", "system", "8080:1222", ""},
} {
args, ctx, name, ports, address := parse(v.target)
if ctx != v.ctx {
t.Fatalf("[%v] context should be %v, got %v", v.target, v.ctx, ctx)
}
if args[1] != v.rctype {
t.Fatalf("[%v] rctype should be %v, got %v", v.target, v.rctype, args[1])
}
if name != v.name {
t.Fatalf("[%v] name should be %v, got %v", v.target, v.name, name)
}
for _, a := range args {
if strings.HasPrefix(a, "--namespace=") {
vv := strings.Split(a, "=")
if vv[1] != v.ns {
t.Fatalf("[%v] ns should be %v, got %v", v.target, v.ns, vv[1])
}
}
}
if ports != v.ports {
t.Fatalf("[%v] ports should be %v, got %v", v.target, v.ports, ports)
}
if address != v.address {
t.Fatalf("[%v] address should be %v, got %v", v.target, v.address, address)
}
}
}