Update tests for Azure Shared Image Gallery

This commit is contained in:
mbearup 2018-10-05 16:04:07 -07:00
parent b6bb5d4b4d
commit 5373b8586d
2 changed files with 51 additions and 1 deletions

View File

@ -79,13 +79,14 @@ type Config struct {
CaptureNamePrefix string `mapstructure:"capture_name_prefix"`
CaptureContainerName string `mapstructure:"capture_container_name"`
// Compute
// Shared Gallery
SharedGallerySubscription string `mapstructure:"shared_gallery_subscription"`
SharedGalleryResourceGroup string `mapstructure:"shared_gallery_resource_group"`
SharedGalleryName string `mapstructure:"shared_gallery_name"`
SharedGalleryImageName string `mapstructure:"shared_gallery_image_name"`
SharedGalleryImageVersion string `mapstructure:"shared_gallery_image_version"`
// Compute
ImagePublisher string `mapstructure:"image_publisher"`
ImageOffer string `mapstructure:"image_offer"`
ImageSku string `mapstructure:"image_sku"`
@ -601,6 +602,12 @@ func assertRequiredParametersSet(c *Config, errs *packer.MultiError) {
if c.SharedGalleryImageName == "" {
errs = packer.MultiErrorAppend(errs, fmt.Errorf("A shared_gallery_image_name must be specified"))
}
if c.CaptureContainerName != "" {
errs = packer.MultiErrorAppend(errs, fmt.Errorf("VHD Target [capture_container_name] is not supported when using Shared Image Gallery as source. Use managed_image_resource_group_name instead."))
}
if c.CaptureNamePrefix != "" {
errs = packer.MultiErrorAppend(errs, fmt.Errorf("VHD Target [capture_name_prefix] is not supported when using Shared Image Gallery as source. Use managed_image_name instead."))
}
} else if c.ImageUrl == "" && c.CustomManagedImageName == "" {
if c.ImagePublisher == "" {
errs = packer.MultiErrorAppend(errs, fmt.Errorf("An image_publisher must be specified"))

View File

@ -1294,6 +1294,49 @@ func TestConfigShouldAllowAsyncResourceGroupOverrideBadValue(t *testing.T) {
}
}
func TestConfigShouldAllowSharedImageGalleryOptions(t *testing.T) {
config := map[string]interface{}{
"location": "ignore",
"subscription_id": "ignore",
"os_type": "linux",
"shared_gallery_subscription": "ignore",
"shared_gallery_resource_group": "ignore",
"shared_gallery_resource_group": "ignore",
"shared_gallery_name": "ignore",
"shared_gallery_image_name": "ignore",
"shared_gallery_image_version": "ignore",
}
c, _, err := newConfig(config, getPackerConfiguration())
if err == nil {
t.Errorf("expected config to accept Shared Image Gallery options", err)
}
}
func TestConfigShouldRejectSharedImageGalleryWithVhdTarget(t *testing.T) {
config := map[string]interface{}{
"location": "ignore",
"subscription_id": "ignore",
"os_type": "linux",
"shared_gallery_subscription": "ignore",
"shared_gallery_resource_group": "ignore",
"shared_gallery_resource_group": "ignore",
"shared_gallery_name": "ignore",
"shared_gallery_image_name": "ignore",
"shared_gallery_image_version": "ignore",
"resource_group_name": "ignore",
"storage_account": "ignore",
"capture_container_name": "ignore",
"capture_name_prefix": "ignore",
}
c, _, err := newConfig(config, getPackerConfiguration())
if err != nil {
t.Errorf("expected an error if Shared Image Gallery source is used with VHD target", err)
}
}
func getArmBuilderConfiguration() map[string]string {