Skip to content

Commit

Permalink
test: Add unit cache tests for subnets (#5978)
Browse files Browse the repository at this point in the history
  • Loading branch information
engedaam authored Apr 8, 2024
1 parent 53fa719 commit f8bfd1e
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions pkg/providers/subnet/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,52 @@ var _ = Describe("SubnetProvider", func() {
Expect(onlyPrivate).To(BeTrue())
})
})
Context("Provider Cache", func() {
It("should resolve subnets from cache that are filtered by id", func() {
expectedSubnets := awsEnv.EC2API.DescribeSubnetsOutput.Clone().Subnets
for _, subnet := range expectedSubnets {
nodeClass.Spec.SubnetSelectorTerms = []v1beta1.SubnetSelectorTerm{
{
ID: *subnet.SubnetId,
},
}
// Call list to request from aws and store in the cache
_, err := awsEnv.SubnetProvider.List(ctx, nodeClass)
Expect(err).To(BeNil())
}

for _, cachedObject := range awsEnv.SubnetCache.Items() {
cachedSubnet := cachedObject.Object.([]*ec2.Subnet)
Expect(cachedSubnet).To(HaveLen(1))
lo.Contains(expectedSubnets, cachedSubnet[0])
}
})
It("should resolve subnets from cache that are filtered by tags", func() {
expectedSubnets := awsEnv.EC2API.DescribeSubnetsOutput.Clone().Subnets
tagSet := lo.Map(expectedSubnets, func(subnet *ec2.Subnet, _ int) map[string]string {
tag, _ := lo.Find(subnet.Tags, func(tag *ec2.Tag) bool {
return lo.FromPtr(tag.Key) == "Name"
})
return map[string]string{"Name": lo.FromPtr(tag.Value)}
})
for _, tag := range tagSet {
nodeClass.Spec.SubnetSelectorTerms = []v1beta1.SubnetSelectorTerm{
{
Tags: tag,
},
}
// Call list to request from aws and store in the cache
_, err := awsEnv.SubnetProvider.List(ctx, nodeClass)
Expect(err).To(BeNil())
}

for _, cachedObject := range awsEnv.SubnetCache.Items() {
cachedSubnet := cachedObject.Object.([]*ec2.Subnet)
Expect(cachedSubnet).To(HaveLen(1))
lo.Contains(expectedSubnets, cachedSubnet[0])
}
})
})
})

func ExpectConsistsOfSubnets(expected, actual []*ec2.Subnet) {
Expand Down

0 comments on commit f8bfd1e

Please sign in to comment.