Skip to content

Commit

Permalink
Add unit test to verify formatting of compute gallery image id
Browse files Browse the repository at this point in the history
  • Loading branch information
shalin patel committed Oct 21, 2022
1 parent 7de91f0 commit 19c9b68
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions azure/converters/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,74 @@ func Test_ImageToPlan(t *testing.T) {
})
}
}

func Test_ComputeImageToSDK(t *testing.T) {
cases := []struct {
name string
image *infrav1.Image
expect func(*GomegaWithT, *compute.ImageReference, error)
}{
{
name: "Should return parsed compute gallery image id",
image: &infrav1.Image{
ComputeGallery: &infrav1.AzureComputeGalleryImage{
ResourceGroup: to.StringPtr("my-resourcegroup"),
SubscriptionID: to.StringPtr("my-subscription-id"),
Gallery: "my-gallery",
Name: "my-image",
Version: "my-version",
},
},
expect: func(g *GomegaWithT, result *compute.ImageReference, err error) {
g.Expect(err).Should(BeNil())
g.Expect(result).To(Equal(&compute.ImageReference{
ID: to.StringPtr("/subscriptions/my-subscription-id/resourceGroups/my-resourcegroup/providers/Microsoft.Compute/galleries/my-gallery/images/my-image/versions/my-version"),
}))
},
},
{
name: "Should return parsed shared gallery image id",
image: &infrav1.Image{
SharedGallery: &infrav1.AzureSharedGalleryImage{
ResourceGroup: "my-resourcegroup",
SubscriptionID: "my-subscription-id",
Gallery: "my-gallery",
Name: "my-image",
Version: "my-version",
},
},
expect: func(g *GomegaWithT, result *compute.ImageReference, err error) {
g.Expect(err).Should(BeNil())
g.Expect(result).To(Equal(&compute.ImageReference{
ID: to.StringPtr("/subscriptions/my-subscription-id/resourceGroups/my-resourcegroup/providers/Microsoft.Compute/galleries/my-gallery/images/my-image/versions/my-version"),
}))
},
},
{
name: "Should return parsed community gallery image id",
image: &infrav1.Image{
ComputeGallery: &infrav1.AzureComputeGalleryImage{
Gallery: "my-gallery",
Name: "my-image",
Version: "my-version",
},
},
expect: func(g *GomegaWithT, result *compute.ImageReference, err error) {
g.Expect(err).Should(BeNil())
g.Expect(result).To(Equal(&compute.ImageReference{
CommunityGalleryImageID: to.StringPtr("/CommunityGalleries/my-gallery/Images/my-image/Versions/my-version"),
}))
},
},
}

for _, c := range cases {
c := c
t.Run(c.name, func(t *testing.T) {
t.Parallel()
g := NewGomegaWithT(t)
result, err := computeImageToSDK(c.image)
c.expect(g, result, err)
})
}
}

0 comments on commit 19c9b68

Please sign in to comment.