summaryrefslogtreecommitdiff
path: root/vendor/github.com/mitchellh/packer/builder/azure/arm/config_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/mitchellh/packer/builder/azure/arm/config_test.go')
-rw-r--r--vendor/github.com/mitchellh/packer/builder/azure/arm/config_test.go89
1 files changed, 81 insertions, 8 deletions
diff --git a/vendor/github.com/mitchellh/packer/builder/azure/arm/config_test.go b/vendor/github.com/mitchellh/packer/builder/azure/arm/config_test.go
index 83545471..b7523f65 100644
--- a/vendor/github.com/mitchellh/packer/builder/azure/arm/config_test.go
+++ b/vendor/github.com/mitchellh/packer/builder/azure/arm/config_test.go
@@ -1,6 +1,3 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT License. See the LICENSE file in builder/azure for license information.
-
package arm
import (
@@ -9,6 +6,7 @@ import (
"testing"
"time"
+ "github.com/Azure/azure-sdk-for-go/arm/compute"
"github.com/hashicorp/packer/builder/azure/common/constants"
"github.com/hashicorp/packer/packer"
)
@@ -48,6 +46,10 @@ func TestConfigShouldProvideReasonableDefaultValues(t *testing.T) {
if c.ObjectID != "" {
t.Errorf("Expected 'ObjectID' to be nil, but it was '%s'!", c.ObjectID)
}
+
+ if c.managedImageStorageAccountType == "" {
+ t.Errorf("Expected 'managedImageStorageAccountType' to be populated, but it was empty!")
+ }
}
func TestConfigShouldBeAbleToOverrideDefaultedValues(t *testing.T) {
@@ -56,6 +58,7 @@ func TestConfigShouldBeAbleToOverrideDefaultedValues(t *testing.T) {
builderValues["ssh_username"] = "override_username"
builderValues["vm_size"] = "override_vm_size"
builderValues["communicator"] = "ssh"
+ builderValues["managed_image_storage_account_type"] = "Premium_LRS"
c, _, err := newConfig(builderValues, getPackerConfiguration())
@@ -64,23 +67,27 @@ func TestConfigShouldBeAbleToOverrideDefaultedValues(t *testing.T) {
}
if c.Password != "override_password" {
- t.Errorf("Expected 'Password' to be set to 'override_password', but found '%s'!", c.Password)
+ t.Errorf("Expected 'Password' to be set to 'override_password', but found %q!", c.Password)
}
if c.Comm.SSHPassword != "override_password" {
- t.Errorf("Expected 'c.Comm.SSHPassword' to be set to 'override_password', but found '%s'!", c.Comm.SSHPassword)
+ t.Errorf("Expected 'c.Comm.SSHPassword' to be set to 'override_password', but found %q!", c.Comm.SSHPassword)
}
if c.UserName != "override_username" {
- t.Errorf("Expected 'UserName' to be set to 'override_username', but found '%s'!", c.UserName)
+ t.Errorf("Expected 'UserName' to be set to 'override_username', but found %q!", c.UserName)
}
if c.Comm.SSHUsername != "override_username" {
- t.Errorf("Expected 'c.Comm.SSHUsername' to be set to 'override_username', but found '%s'!", c.Comm.SSHUsername)
+ t.Errorf("Expected 'c.Comm.SSHUsername' to be set to 'override_username', but found %q!", c.Comm.SSHUsername)
}
if c.VMSize != "override_vm_size" {
- t.Errorf("Expected 'vm_size' to be set to 'override_vm_size', but found '%s'!", c.VMSize)
+ t.Errorf("Expected 'vm_size' to be set to 'override_vm_size', but found %q!", c.VMSize)
+ }
+
+ if c.managedImageStorageAccountType != compute.PremiumLRS {
+ t.Errorf("Expected 'managed_image_storage_account_type' to be set to 'Premium_LRS', but found %q!", c.managedImageStorageAccountType)
}
}
@@ -782,6 +789,26 @@ func TestConfigShouldRejectVhdAndManagedImageOutput(t *testing.T) {
}
}
+// If the user specified a build of a VHD, but started with a managed image it should be rejected.
+func TestConfigShouldRejectManagedImageSourceAndVhdOutput(t *testing.T) {
+ config := map[string]interface{}{
+ "image_url": "ignore",
+ "location": "ignore",
+ "subscription_id": "ignore",
+ "communicator": "none",
+ "managed_image_resource_group_name": "ignore",
+ "managed_image_name": "ignore",
+
+ // Does not matter for this test case, just pick one.
+ "os_type": constants.Target_Linux,
+ }
+
+ _, _, err := newConfig(config, getPackerConfiguration())
+ if err == nil {
+ t.Fatal("expected config to reject VHD and Managed Image build")
+ }
+}
+
func TestConfigShouldRejectCustomAndPlatformManagedImageBuild(t *testing.T) {
config := map[string]interface{}{
"custom_managed_image_resource_group_name": "ignore",
@@ -826,6 +853,52 @@ func TestConfigShouldRejectCustomAndImageUrlForManagedImageBuild(t *testing.T) {
}
}
+func TestConfigShouldRejectMalformedManageImageStorageAccountTypes(t *testing.T) {
+ config := map[string]interface{}{
+ "custom_managed_image_resource_group_name": "ignore",
+ "custom_managed_image_name": "ignore",
+ "location": "ignore",
+ "subscription_id": "ignore",
+ "communicator": "none",
+ "managed_image_resource_group_name": "ignore",
+ "managed_image_name": "ignore",
+ "managed_image_storage_account_type": "--invalid--",
+
+ // Does not matter for this test case, just pick one.
+ "os_type": constants.Target_Linux,
+ }
+
+ _, _, err := newConfig(config, getPackerConfiguration())
+ if err == nil {
+ t.Fatal("expected config to reject custom and platform input for a managed image build")
+ }
+}
+
+func TestConfigShouldAcceptManagedImageStorageAccountTypes(t *testing.T) {
+ config := map[string]interface{}{
+ "custom_managed_image_resource_group_name": "ignore",
+ "custom_managed_image_name": "ignore",
+ "location": "ignore",
+ "subscription_id": "ignore",
+ "communicator": "none",
+ "managed_image_resource_group_name": "ignore",
+ "managed_image_name": "ignore",
+
+ // Does not matter for this test case, just pick one.
+ "os_type": constants.Target_Linux,
+ }
+
+ storage_account_types := []string{"Premium_LRS", "Standard_LRS"}
+
+ for _, x := range storage_account_types {
+ config["managed_image_storage_account_type"] = x
+ _, _, err := newConfig(config, getPackerConfiguration())
+ if err != nil {
+ t.Fatalf("expected config to accept a managed_image_storage_account_type of %q", x)
+ }
+ }
+}
+
func getArmBuilderConfiguration() map[string]string {
m := make(map[string]string)
for _, v := range requiredConfigValues {