|
| 1 | +package resources |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/aws/aws-sdk-go-v2/aws" |
| 7 | + shieldtypes "github.com/aws/aws-sdk-go-v2/service/shield/types" |
| 8 | + "github.com/gotidy/ptr" |
| 9 | + "github.com/stretchr/testify/assert" |
| 10 | +) |
| 11 | + |
| 12 | +func Test_ShieldProtectionGroup_String(t *testing.T) { |
| 13 | + a := assert.New(t) |
| 14 | + |
| 15 | + shieldProtectionGroup := ShieldProtectionGroup{ |
| 16 | + ProtectionGroupId: ptr.String("protection-group-id"), |
| 17 | + } |
| 18 | + |
| 19 | + a.Equal("protection-group-id", shieldProtectionGroup.String()) |
| 20 | +} |
| 21 | + |
| 22 | +func Test_ShieldProtectionGroup_Properties(t *testing.T) { |
| 23 | + a := assert.New(t) |
| 24 | + |
| 25 | + aggregation := shieldtypes.ProtectionGroupAggregationSum |
| 26 | + pattern := shieldtypes.ProtectionGroupPatternAll |
| 27 | + resourceType := shieldtypes.ProtectedResourceTypeCloudfrontDistribution |
| 28 | + |
| 29 | + shieldProtectionGroup := ShieldProtectionGroup{ |
| 30 | + ProtectionGroupId: ptr.String("protection-group-id"), |
| 31 | + Aggregation: &aggregation, |
| 32 | + Pattern: &pattern, |
| 33 | + ResourceType: &resourceType, |
| 34 | + Members: &[]string{"arn:aws:cloudfront::123456789012:distribution/EXAMPLE123"}, |
| 35 | + ProtectionGroupArn: ptr.String("arn:aws:shield::123456789012:protection-group/protection-group-id"), |
| 36 | + Tags: &[]shieldtypes.Tag{ |
| 37 | + { |
| 38 | + Key: aws.String("Environment"), |
| 39 | + Value: aws.String("production"), |
| 40 | + }, |
| 41 | + { |
| 42 | + Key: aws.String("Team"), |
| 43 | + Value: aws.String("security"), |
| 44 | + }, |
| 45 | + }, |
| 46 | + } |
| 47 | + |
| 48 | + properties := shieldProtectionGroup.Properties() |
| 49 | + |
| 50 | + a.Equal("protection-group-id", properties.Get("ProtectionGroupId")) |
| 51 | + a.Equal("SUM", properties.Get("Aggregation")) |
| 52 | + a.Equal("ALL", properties.Get("Pattern")) |
| 53 | + a.Equal("CLOUDFRONT_DISTRIBUTION", properties.Get("ResourceType")) |
| 54 | + a.Equal("arn:aws:shield::123456789012:protection-group/protection-group-id", properties.Get("ProtectionGroupArn")) |
| 55 | + a.Equal("production", properties.Get("tag:Environment")) |
| 56 | + a.Equal("security", properties.Get("tag:Team")) |
| 57 | +} |
| 58 | + |
| 59 | +func Test_ShieldProtectionGroup_Properties_EmptyTags(t *testing.T) { |
| 60 | + a := assert.New(t) |
| 61 | + |
| 62 | + aggregation := shieldtypes.ProtectionGroupAggregationSum |
| 63 | + pattern := shieldtypes.ProtectionGroupPatternAll |
| 64 | + |
| 65 | + shieldProtectionGroup := ShieldProtectionGroup{ |
| 66 | + ProtectionGroupId: ptr.String("protection-group-id"), |
| 67 | + Aggregation: &aggregation, |
| 68 | + Pattern: &pattern, |
| 69 | + Members: &[]string{}, |
| 70 | + ProtectionGroupArn: ptr.String("arn:aws:shield::123456789012:protection-group/protection-group-id"), |
| 71 | + Tags: &[]shieldtypes.Tag{}, |
| 72 | + } |
| 73 | + |
| 74 | + properties := shieldProtectionGroup.Properties() |
| 75 | + |
| 76 | + a.Equal("protection-group-id", properties.Get("ProtectionGroupId")) |
| 77 | + a.Equal("SUM", properties.Get("Aggregation")) |
| 78 | + a.Equal("ALL", properties.Get("Pattern")) |
| 79 | + a.Equal("arn:aws:shield::123456789012:protection-group/protection-group-id", properties.Get("ProtectionGroupArn")) |
| 80 | +} |
| 81 | + |
| 82 | +func Test_ShieldProtectionGroup_Properties_SpecialCharactersInTags(t *testing.T) { |
| 83 | + a := assert.New(t) |
| 84 | + |
| 85 | + aggregation := shieldtypes.ProtectionGroupAggregationSum |
| 86 | + pattern := shieldtypes.ProtectionGroupPatternAll |
| 87 | + |
| 88 | + shieldProtectionGroup := ShieldProtectionGroup{ |
| 89 | + ProtectionGroupId: ptr.String("protection-group-id"), |
| 90 | + Aggregation: &aggregation, |
| 91 | + Pattern: &pattern, |
| 92 | + Members: &[]string{"arn:aws:cloudfront::123456789012:distribution/EXAMPLE123"}, |
| 93 | + ProtectionGroupArn: ptr.String("arn:aws:shield::123456789012:protection-group/protection-group-id"), |
| 94 | + Tags: &[]shieldtypes.Tag{ |
| 95 | + { |
| 96 | + Key: aws.String("Environment:Stage"), |
| 97 | + Value: aws.String("prod/staging"), |
| 98 | + }, |
| 99 | + { |
| 100 | + Key: aws.String("Cost-Center"), |
| 101 | + Value: aws.String("security-team"), |
| 102 | + }, |
| 103 | + }, |
| 104 | + } |
| 105 | + |
| 106 | + properties := shieldProtectionGroup.Properties() |
| 107 | + |
| 108 | + a.Equal("protection-group-id", properties.Get("ProtectionGroupId")) |
| 109 | + a.Equal("prod/staging", properties.Get("tag:Environment:Stage")) |
| 110 | + a.Equal("security-team", properties.Get("tag:Cost-Center")) |
| 111 | +} |
0 commit comments