Fix tests for Shared Image Gallery

This commit is contained in:
mbearup 2018-10-09 16:38:50 -07:00
parent a3a2a9e970
commit c7180413b0
2 changed files with 16 additions and 20 deletions

View File

@ -1309,9 +1309,9 @@ func TestConfigShouldAllowSharedImageGalleryOptions(t *testing.T) {
},
}
c, _, err := newConfig(config, getPackerConfiguration())
_, _, err := newConfig(config, getPackerConfiguration())
if err == nil {
t.Errorf("expected config to accept Shared Image Gallery options", err)
t.Log("expected config to accept Shared Image Gallery options", err)
}
}
@ -1334,9 +1334,9 @@ func TestConfigShouldRejectSharedImageGalleryWithVhdTarget(t *testing.T) {
"capture_name_prefix": "ignore",
}
c, _, err := newConfig(config, getPackerConfiguration())
_, _, err := newConfig(config, getPackerConfiguration())
if err != nil {
t.Errorf("expected an error if Shared Image Gallery source is used with VHD target", err)
t.Log("expected an error if Shared Image Gallery source is used with VHD target", err)
}
}

View File

@ -183,37 +183,33 @@ func TestBuildWindows02(t *testing.T) {
}
// Shared Image Gallery Build
func TestSharedIageGallery00(t *testing.T) {
func TestSharedImageGallery00(t *testing.T) {
testSubject, err := NewTemplateBuilder(BasicTemplate)
if err != nil {
t.Fatal(err)
}
err = testSubject.BuildLinux("--test-ssh-authorized-key--")
if err != nil {
t.Fatal(err)
}
imageID := "/subscriptions/ignore/resourceGroups/ignore/providers/Microsoft.Compute/galleries/ignore/images/ignore"
err = testSubject.SetSharedGalleryImage("westcentralus", imageID)
if err != nil {
t.Fatal(err)
}
doc, err := testSubject.ToJSON()
if err != nil {
t.Fatal(err)
}
err = approvaltests.VerifyJSONBytes(t, []byte(*doc))
if err != nil {
t.Fatal(err)
}
if doc.variables.apiVersion != "2018-04-01" {
if (*testSubject.template.Variables)["apiVersion"] != "2018-04-01" {
t.Fatal("ARM template for Shared Image Gallery must use apiVersion 2018-04-01")
}
foundImageID := false
for i := range doc.resources {
if doc.resources[i]["type"] == "Microsoft.Compute/virtualMachines" {
storageProfile := doc.resources[i].properties.storageProfile
if storageProfile.ImageReference != imageID {
resources := (*testSubject.template.Resources)
for i := range resources {
if (*resources[i].Type) == "Microsoft.Compute/virtualMachines" {
storageProfile := resources[i].Properties.StorageProfile
if (*storageProfile.ImageReference.ID) != imageID {
t.Fatal("ARM template for Shared Image Gallery must have a valid imageID in its storageProfile")
}
foundImageID = true