AWS: Add tests for awsTagging.hasClusterTag
Among other things these tests verify the fix for issue #64230.
This commit is contained in:
parent
e952c12dfe
commit
986faed326
@ -114,3 +114,68 @@ func TestFindClusterID(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestHasClusterTag(t *testing.T) {
|
||||
awsServices := NewFakeAWSServices(TestClusterId)
|
||||
c, err := newAWSCloud(CloudConfig{}, awsServices)
|
||||
if err != nil {
|
||||
t.Errorf("Error building aws cloud: %v", err)
|
||||
return
|
||||
}
|
||||
grid := []struct {
|
||||
Tags map[string]string
|
||||
Expected bool
|
||||
}{
|
||||
{
|
||||
Tags: map[string]string{},
|
||||
},
|
||||
{
|
||||
Tags: map[string]string{
|
||||
TagNameKubernetesClusterLegacy: TestClusterId,
|
||||
},
|
||||
Expected: true,
|
||||
},
|
||||
{
|
||||
Tags: map[string]string{
|
||||
TagNameKubernetesClusterLegacy: "a",
|
||||
},
|
||||
Expected: false,
|
||||
},
|
||||
{
|
||||
Tags: map[string]string{
|
||||
TagNameKubernetesClusterPrefix + TestClusterId: "owned",
|
||||
},
|
||||
Expected: true,
|
||||
},
|
||||
{
|
||||
Tags: map[string]string{
|
||||
TagNameKubernetesClusterPrefix + TestClusterId: "",
|
||||
},
|
||||
Expected: true,
|
||||
},
|
||||
{
|
||||
Tags: map[string]string{
|
||||
TagNameKubernetesClusterLegacy: "a",
|
||||
TagNameKubernetesClusterPrefix + TestClusterId: "shared",
|
||||
},
|
||||
Expected: true,
|
||||
},
|
||||
{
|
||||
Tags: map[string]string{
|
||||
TagNameKubernetesClusterPrefix + TestClusterId: "shared",
|
||||
TagNameKubernetesClusterPrefix + "b": "shared",
|
||||
},
|
||||
Expected: true,
|
||||
},
|
||||
}
|
||||
for _, g := range grid {
|
||||
var ec2Tags []*ec2.Tag
|
||||
for k, v := range g.Tags {
|
||||
ec2Tags = append(ec2Tags, &ec2.Tag{Key: aws.String(k), Value: aws.String(v)})
|
||||
}
|
||||
result := c.tagging.hasClusterTag(ec2Tags)
|
||||
if result != g.Expected {
|
||||
t.Errorf("Unexpected result for tags %v: %t", g.Tags, result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user