Merge pull request #69027 from vainu-arto/aws-add-has-cluster-tags-tests
AWS: Add tests for awsTagging.hasClusterTag
This commit is contained in:
commit
25607dea8c
@ -57,6 +57,12 @@ func TestFindClusterID(t *testing.T) {
|
|||||||
},
|
},
|
||||||
ExpectedNew: "a",
|
ExpectedNew: "a",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Tags: map[string]string{
|
||||||
|
TagNameKubernetesClusterPrefix + "a": "shared",
|
||||||
|
},
|
||||||
|
ExpectedNew: "a",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Tags: map[string]string{
|
Tags: map[string]string{
|
||||||
TagNameKubernetesClusterPrefix + "a": "",
|
TagNameKubernetesClusterPrefix + "a": "",
|
||||||
@ -108,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