@@ -23,7 +23,7 @@ import (
23
23
)
24
24
25
25
func TestFindClusterName (t * testing.T ) {
26
- grid := []struct {
26
+ testCases := []struct {
27
27
Tags map [string ]string
28
28
ExpectedClusterName string
29
29
ExpectError bool
@@ -33,7 +33,19 @@ func TestFindClusterName(t *testing.T) {
33
33
},
34
34
{
35
35
Tags : map [string ]string {
36
- TagNameKubernetesClusterPrefix : TestClusterID ,
36
+ TagNameKubernetesClusterPrefix + TestClusterID : "owned" ,
37
+ },
38
+ ExpectedClusterName : TestClusterID ,
39
+ },
40
+ {
41
+ Tags : map [string ]string {
42
+ TagNameKubernetesClusterPrefix + TestClusterID : "shared" ,
43
+ },
44
+ ExpectedClusterName : TestClusterID ,
45
+ },
46
+ {
47
+ Tags : map [string ]string {
48
+ TagNameKubernetesClusterPrefix + TestClusterID : "" ,
37
49
},
38
50
ExpectedClusterName : TestClusterID ,
39
51
},
@@ -43,26 +55,33 @@ func TestFindClusterName(t *testing.T) {
43
55
},
44
56
ExpectedClusterName : "" ,
45
57
},
58
+ {
59
+ Tags : map [string ]string {
60
+ TagNameKubernetesClusterPrefix + "a" : "" ,
61
+ TagNameKubernetesClusterPrefix + "b" : "" ,
62
+ },
63
+ ExpectError : true ,
64
+ },
46
65
}
47
- for _ , g := range grid {
66
+ for _ , testCase := range testCases {
48
67
var ec2Tags []* ec2.Tag
49
- for k , v := range g .Tags {
68
+ for k , v := range testCase .Tags {
50
69
ec2Tags = append (ec2Tags , & ec2.Tag {Key : aws .String (k ), Value : aws .String (v )})
51
70
}
52
71
clusterName , err := findClusterName (ec2Tags )
53
- if g .ExpectError {
72
+ if testCase .ExpectError {
54
73
if err == nil {
55
- t .Errorf ("expected error for tags %v" , g .Tags )
74
+ t .Errorf ("expected error for tags %v" , testCase .Tags )
56
75
continue
57
76
}
58
77
} else {
59
78
if err != nil {
60
- t .Errorf ("unexpected error for tags %v: %v" , g .Tags , err )
79
+ t .Errorf ("unexpected error for tags %v: %v" , testCase .Tags , err )
61
80
continue
62
81
}
63
82
64
- if g .ExpectedClusterName != clusterName {
65
- t .Errorf ("unexpected new clusterName for tags %v: %s vs %s" , g .Tags , g .ExpectedClusterName , clusterName )
83
+ if testCase .ExpectedClusterName != clusterName {
84
+ t .Errorf ("unexpected new clusterName for tags %v: %s vs %s" , testCase .Tags , testCase .ExpectedClusterName , clusterName )
66
85
continue
67
86
}
68
87
}
0 commit comments