-
Notifications
You must be signed in to change notification settings - Fork 3
/
plan_test.go
96 lines (92 loc) · 3.47 KB
/
plan_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
85
86
87
88
89
90
91
92
93
94
95
96
package tentez
import (
"reflect"
"sort"
"testing"
)
func TestGetTargetNames(t *testing.T) {
cases := []struct {
targets map[TargetType]Targets
expected []string
}{
{
map[TargetType]Targets{},
[]string{},
},
{
map[TargetType]Targets{
TargetTypeAwsListenerRule: AwsListenerRules{
AwsListenerRule{
Name: "hoge",
Target: "arn:aws:elasticloadbalancing:ap-northeast-1:123456789012:listener/app/my-lb/0123456789abcdef/0123456789abcdef/0123456789abcdef",
Switch: Switch{
Old: "arn:aws:elasticloadbalancing:ap-northeast-1:123456789012:targetgroup/my-targets1/0123456789abcdef",
New: "arn:aws:elasticloadbalancing:ap-northeast-1:123456789012:targetgroup/my-targets2/fedcba9876543210",
},
},
AwsListenerRule{
Name: "foo",
Target: "arn:aws:elasticloadbalancing:ap-northeast-1:123456789012:listener/app/my-lb/0123456789abcdef/0123456789abcdef/0123456789abcdef",
Switch: Switch{
Old: "arn:aws:elasticloadbalancing:ap-northeast-1:123456789012:targetgroup/my-targets1/0123456789abcdef",
New: "arn:aws:elasticloadbalancing:ap-northeast-1:123456789012:targetgroup/my-targets2/fedcba9876543210",
},
},
},
},
[]string{"hoge", "foo"},
},
{
map[TargetType]Targets{
TargetTypeAwsListenerRule: AwsListenerRules{
AwsListenerRule{
Name: "hoge",
Target: "arn:aws:elasticloadbalancing:ap-northeast-1:123456789012:listener/app/my-lb/0123456789abcdef/0123456789abcdef/0123456789abcdef",
Switch: Switch{
Old: "arn:aws:elasticloadbalancing:ap-northeast-1:123456789012:targetgroup/my-targets1/0123456789abcdef",
New: "arn:aws:elasticloadbalancing:ap-northeast-1:123456789012:targetgroup/my-targets2/fedcba9876543210",
},
},
AwsListenerRule{
Name: "foo",
Target: "arn:aws:elasticloadbalancing:ap-northeast-1:123456789012:listener/app/my-lb/0123456789abcdef/0123456789abcdef/0123456789abcdef",
Switch: Switch{
Old: "arn:aws:elasticloadbalancing:ap-northeast-1:123456789012:targetgroup/my-targets1/0123456789abcdef",
New: "arn:aws:elasticloadbalancing:ap-northeast-1:123456789012:targetgroup/my-targets2/fedcba9876543210",
},
},
},
TargetTypeAwsListener: AwsListeners{
AwsListener{
Name: "hoge",
Target: "arn:aws:elasticloadbalancing:ap-northeast-1:123456789012:listener/app/my-lb/0123456789abcdef/0123456789abcdef/0123456789abcdef",
Switch: Switch{
Old: "arn:aws:elasticloadbalancing:ap-northeast-1:123456789012:targetgroup/my-targets1/0123456789abcdef",
New: "arn:aws:elasticloadbalancing:ap-northeast-1:123456789012:targetgroup/my-targets2/fedcba9876543210",
},
},
AwsListener{
Name: "",
Target: "arn:aws:elasticloadbalancing:ap-northeast-1:123456789012:listener/app/my-lb/0123456789abcdef/0123456789abcdef/0123456789abcdef",
Switch: Switch{
Old: "arn:aws:elasticloadbalancing:ap-northeast-1:123456789012:targetgroup/my-targets1/0123456789abcdef",
New: "arn:aws:elasticloadbalancing:ap-northeast-1:123456789012:targetgroup/my-targets2/fedcba9876543210",
},
},
},
},
[]string{"hoge", "foo", "hoge", ""},
},
}
for _, c := range cases {
got := getTargetNames(c.targets)
sortSlice(c.expected)
sortSlice(got)
if !reflect.DeepEqual(c.expected, got) {
t.Errorf("expected %v, but got %v", c.expected, got)
}
}
}
func sortSlice(s []string) {
sort.Slice(s, func(i, j int) bool { return s[i] < s[j] })
}