Skip to content

Commit

Permalink
test: add static hash checking for AWSNodeTemplate (aws#4539)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdeal authored Sep 1, 2023
1 parent 1453c2c commit 4e485a9
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions pkg/apis/v1alpha1/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ var _ = Describe("Validation", func() {
var _ = Describe("AWSNodeTemplate Hash", func() {
var awsnodetemplatespec v1alpha1.AWSNodeTemplateSpec
var awsnodetemplate *v1alpha1.AWSNodeTemplate
const awsnodetemplateStaticHash = "8218109239399812816"

BeforeEach(func() {
awsnodetemplatespec = v1alpha1.AWSNodeTemplateSpec{
AWS: v1alpha1.AWS{
Expand Down Expand Up @@ -244,6 +246,33 @@ var _ = Describe("Validation", func() {
}
awsnodetemplate = test.AWSNodeTemplate(awsnodetemplatespec)
})
DescribeTable(
"should match static hash",
func(hash string, specs ...v1alpha1.AWSNodeTemplateSpec) {
specs = append([]v1alpha1.AWSNodeTemplateSpec{awsnodetemplatespec}, specs...)
nodeTemplate := test.AWSNodeTemplate(specs...)
Expect(nodeTemplate.Hash()).To(Equal(hash))
},
Entry("Base AWSNodeTemplate", awsnodetemplateStaticHash),

// Static fields, expect changed hash from base
Entry("InstanceProfile Drift", "7151640568926200147", v1alpha1.AWSNodeTemplateSpec{AWS: v1alpha1.AWS{InstanceProfile: aws.String("profile-2")}}),
Entry("UserData Drift", "7125936663475632400", v1alpha1.AWSNodeTemplateSpec{UserData: aws.String("userdata-test-2")}),
Entry("Tags Drift", "7008297732848636107", v1alpha1.AWSNodeTemplateSpec{AWS: v1alpha1.AWS{Tags: map[string]string{"keyTag-test-3": "valueTag-test-3"}}}),
Entry("MetadataOptions Drift", "3771503890852427396", v1alpha1.AWSNodeTemplateSpec{AWS: v1alpha1.AWS{LaunchTemplate: v1alpha1.LaunchTemplate{MetadataOptions: &v1alpha1.MetadataOptions{HTTPEndpoint: aws.String("test-metadata-2")}}}}),
Entry("BlockDeviceMappings Drift", "13540813918064174930", v1alpha1.AWSNodeTemplateSpec{AWS: v1alpha1.AWS{LaunchTemplate: v1alpha1.LaunchTemplate{BlockDeviceMappings: []*v1alpha1.BlockDeviceMapping{{DeviceName: aws.String("map-device-test-3")}}}}}),
Entry("Context Drift", "14848954101731282288", v1alpha1.AWSNodeTemplateSpec{AWS: v1alpha1.AWS{Context: aws.String("context-2")}}),
Entry("DetailedMonitoring Drift", "1327478230553204075", v1alpha1.AWSNodeTemplateSpec{DetailedMonitoring: aws.Bool(true)}),
Entry("AMIFamily Drift", "11757951095500780022", v1alpha1.AWSNodeTemplateSpec{AWS: v1alpha1.AWS{AMIFamily: aws.String(v1alpha1.AMIFamilyBottlerocket)}}),
Entry("Reorder Tags", "8218109239399812816", v1alpha1.AWSNodeTemplateSpec{AWS: v1alpha1.AWS{Tags: map[string]string{"keyTag-2": "valueTag-2", "keyTag-1": "valueTag-1"}}}),
Entry("Reorder BlockDeviceMapping", "8218109239399812816", v1alpha1.AWSNodeTemplateSpec{AWS: v1alpha1.AWS{LaunchTemplate: v1alpha1.LaunchTemplate{BlockDeviceMappings: []*v1alpha1.BlockDeviceMapping{{DeviceName: aws.String("map-device-2")}, {DeviceName: aws.String("map-device-1")}}}}}),

// Behavior / Dynamic fields, expect same hash as base
Entry("Modified AMISelector", awsnodetemplateStaticHash, v1alpha1.AWSNodeTemplateSpec{AMISelector: map[string]string{"subnet-test-key": "subnet-test-value"}}),
Entry("Modified SubnetSelector", awsnodetemplateStaticHash, v1alpha1.AWSNodeTemplateSpec{AWS: v1alpha1.AWS{SecurityGroupSelector: map[string]string{"subnet-test-key": "subnet-test-value"}}}),
Entry("Modified SecurityGroupSelector", awsnodetemplateStaticHash, v1alpha1.AWSNodeTemplateSpec{AWS: v1alpha1.AWS{SecurityGroupSelector: map[string]string{"subnet-test-key": "subnet-test-value"}}}),
Entry("Modified LaunchTemplateName", awsnodetemplateStaticHash, v1alpha1.AWSNodeTemplateSpec{AWS: v1alpha1.AWS{LaunchTemplate: v1alpha1.LaunchTemplate{LaunchTemplateName: aws.String("foobar")}}}),
)
DescribeTable("should change hash when static fields are updated", func(awsnodetemplatespec v1alpha1.AWSNodeTemplateSpec) {
expectedHash := awsnodetemplate.Hash()
updatedAWSNodeTemplate := test.AWSNodeTemplate(*awsnodetemplatespec.DeepCopy(), awsnodetemplatespec)
Expand Down

0 comments on commit 4e485a9

Please sign in to comment.