github.com/aclaygray/packer@v1.3.2/post-processor/vagrant/azure_test.go (about) 1 package vagrant 2 3 import ( 4 "strings" 5 "testing" 6 7 "github.com/hashicorp/packer/packer" 8 ) 9 10 func TestAzureProvider_impl(t *testing.T) { 11 var _ Provider = new(AzureProvider) 12 } 13 14 func TestAzureProvider_KeepInputArtifact(t *testing.T) { 15 p := new(AzureProvider) 16 17 if !p.KeepInputArtifact() { 18 t.Fatal("should keep input artifact") 19 } 20 } 21 22 func TestAzureProvider_ManagedImage(t *testing.T) { 23 p := new(AzureProvider) 24 ui := testUi() 25 artifact := &packer.MockArtifact{ 26 StringValue: `Azure.ResourceManagement.VMImage: 27 28 OSType: Linux 29 ManagedImageResourceGroupName: packerruns 30 ManagedImageName: packer-1533651633 31 ManagedImageId: /subscriptions/e6229913-d9c3-4ddd-99a4-9e1ef3beaa1b/resourceGroups/packerruns/providers/Microsoft.Compute/images/packer-1533675589 32 ManagedImageLocation: westus`, 33 } 34 35 vagrantfile, _, err := p.Process(ui, artifact, "foo") 36 if err != nil { 37 t.Fatalf("should not have error: %s", err) 38 } 39 result := `azure.location = "westus"` 40 if !strings.Contains(vagrantfile, result) { 41 t.Fatalf("wrong substitution: %s", vagrantfile) 42 } 43 result = `azure.vm_managed_image_id = "/subscriptions/e6229913-d9c3-4ddd-99a4-9e1ef3beaa1b/resourceGroups/packerruns/providers/Microsoft.Compute/images/packer-1533675589"` 44 if !strings.Contains(vagrantfile, result) { 45 t.Fatalf("wrong substitution: %s", vagrantfile) 46 } 47 // DO NOT set resource group in Vagrantfile, it should be separate from the image 48 result = `azure.resource_group_name` 49 if strings.Contains(vagrantfile, result) { 50 t.Fatalf("wrong substitution: %s", vagrantfile) 51 } 52 result = `azure.vm_operating_system` 53 if strings.Contains(vagrantfile, result) { 54 t.Fatalf("wrong substitution: %s", vagrantfile) 55 } 56 } 57 58 func TestAzureProvider_VHD(t *testing.T) { 59 p := new(AzureProvider) 60 ui := testUi() 61 artifact := &packer.MockArtifact{ 62 IdValue: "https://packerbuildswest.blob.core.windows.net/system/Microsoft.Compute/Images/images/packer-osDisk.96ed2120-591d-4900-95b0-ee8e985f2213.vhd", 63 StringValue: `Azure.ResourceManagement.VMImage: 64 65 OSType: Linux 66 StorageAccountLocation: westus 67 OSDiskUri: https://packerbuildswest.blob.core.windows.net/system/Microsoft.Compute/Images/images/packer-osDisk.96ed2120-591d-4900-95b0-ee8e985f2213.vhd 68 OSDiskUriReadOnlySas: https://packerbuildswest.blob.core.windows.net/system/Microsoft.Compute/Images/images/packer-osDisk.96ed2120-591d-4900-95b0-ee8e985f2213.vhd?se=2018-09-07T18%3A36%3A34Z&sig=xUiFvwAviPYoP%2Bc91vErqvwYR1eK4x%2BAx7YLMe84zzU%3D&sp=r&sr=b&sv=2016-05-31 69 TemplateUri: https://packerbuildswest.blob.core.windows.net/system/Microsoft.Compute/Images/images/packer-vmTemplate.96ed2120-591d-4900-95b0-ee8e985f2213.json 70 TemplateUriReadOnlySas: https://packerbuildswest.blob.core.windows.net/system/Microsoft.Compute/Images/images/packer-vmTemplate.96ed2120-591d-4900-95b0-ee8e985f2213.json?se=2018-09-07T18%3A36%3A34Z&sig=lDxePyAUCZbfkB5ddiofimXfwk5INn%2F9E2BsnqIKC9Q%3D&sp=r&sr=b&sv=2016-05-31`, 71 } 72 73 vagrantfile, _, err := p.Process(ui, artifact, "foo") 74 if err != nil { 75 t.Fatalf("should not have error: %s", err) 76 } 77 result := `azure.location = "westus"` 78 if !strings.Contains(vagrantfile, result) { 79 t.Fatalf("wrong substitution: %s", vagrantfile) 80 } 81 result = `azure.vm_vhd_uri = "https://packerbuildswest.blob.core.windows.net/system/Microsoft.Compute/Images/images/packer-osDisk.96ed2120-591d-4900-95b0-ee8e985f2213.vhd"` 82 if !strings.Contains(vagrantfile, result) { 83 t.Fatalf("wrong substitution: %s", vagrantfile) 84 } 85 result = `azure.vm_operating_system = "Linux"` 86 if !strings.Contains(vagrantfile, result) { 87 t.Fatalf("wrong substitution: %s", vagrantfile) 88 } 89 // DO NOT set resource group in Vagrantfile, it should be separate from the image 90 result = `azure.resource_group_name` 91 if strings.Contains(vagrantfile, result) { 92 t.Fatalf("wrong substitution: %s", vagrantfile) 93 } 94 }