github.phpd.cn/hashicorp/packer@v1.3.2/builder/azure/arm/builder_acc_test.go (about)

     1  package arm
     2  
     3  // these tests require the following variables to be set,
     4  // although some test will only use a subset:
     5  //
     6  // * ARM_CLIENT_ID
     7  // * ARM_CLIENT_SECRET
     8  // * ARM_SUBSCRIPTION_ID
     9  // * ARM_OBJECT_ID
    10  // * ARM_STORAGE_ACCOUNT
    11  //
    12  // The subscription in question should have a resource group
    13  // called "packer-acceptance-test" in "South Central US" region. The
    14  // storage account refered to in the above variable should
    15  // be inside this resource group and in "South Central US" as well.
    16  //
    17  // In addition, the PACKER_ACC variable should also be set to
    18  // a non-empty value to enable Packer acceptance tests and the
    19  // options "-v -timeout 90m" should be provided to the test
    20  // command, e.g.:
    21  //   go test -v -timeout 90m -run TestBuilderAcc_.*
    22  
    23  import (
    24  	"testing"
    25  
    26  	"fmt"
    27  	builderT "github.com/hashicorp/packer/helper/builder/testing"
    28  	"os"
    29  )
    30  
    31  const DeviceLoginAcceptanceTest = "DEVICELOGIN_TEST"
    32  
    33  func TestBuilderAcc_ManagedDisk_Windows(t *testing.T) {
    34  	builderT.Test(t, builderT.TestCase{
    35  		PreCheck: func() { testAccPreCheck(t) },
    36  		Builder:  &Builder{},
    37  		Template: testBuilderAccManagedDiskWindows,
    38  	})
    39  }
    40  
    41  func TestBuilderAcc_ManagedDisk_Windows_Build_Resource_Group(t *testing.T) {
    42  	builderT.Test(t, builderT.TestCase{
    43  		PreCheck: func() { testAccPreCheck(t) },
    44  		Builder:  &Builder{},
    45  		Template: testBuilderAccManagedDiskWindowsBuildResourceGroup,
    46  	})
    47  }
    48  
    49  func TestBuilderAcc_ManagedDisk_Windows_DeviceLogin(t *testing.T) {
    50  	if os.Getenv(DeviceLoginAcceptanceTest) == "" {
    51  		t.Skip(fmt.Sprintf(
    52  			"Device Login Acceptance tests skipped unless env '%s' set, as its requires manual step during execution",
    53  			DeviceLoginAcceptanceTest))
    54  		return
    55  	}
    56  	builderT.Test(t, builderT.TestCase{
    57  		PreCheck: func() { testAccPreCheck(t) },
    58  		Builder:  &Builder{},
    59  		Template: testBuilderAccManagedDiskWindowsDeviceLogin,
    60  	})
    61  }
    62  
    63  func TestBuilderAcc_ManagedDisk_Linux(t *testing.T) {
    64  	builderT.Test(t, builderT.TestCase{
    65  		PreCheck: func() { testAccPreCheck(t) },
    66  		Builder:  &Builder{},
    67  		Template: testBuilderAccManagedDiskLinux,
    68  	})
    69  }
    70  
    71  func TestBuilderAcc_ManagedDisk_Linux_DeviceLogin(t *testing.T) {
    72  	if os.Getenv(DeviceLoginAcceptanceTest) == "" {
    73  		t.Skip(fmt.Sprintf(
    74  			"Device Login Acceptance tests skipped unless env '%s' set, as its requires manual step during execution",
    75  			DeviceLoginAcceptanceTest))
    76  		return
    77  	}
    78  	builderT.Test(t, builderT.TestCase{
    79  		PreCheck: func() { testAccPreCheck(t) },
    80  		Builder:  &Builder{},
    81  		Template: testBuilderAccManagedDiskLinuxDeviceLogin,
    82  	})
    83  }
    84  
    85  func TestBuilderAcc_Blob_Windows(t *testing.T) {
    86  	builderT.Test(t, builderT.TestCase{
    87  		PreCheck: func() { testAccPreCheck(t) },
    88  		Builder:  &Builder{},
    89  		Template: testBuilderAccBlobWindows,
    90  	})
    91  }
    92  
    93  func TestBuilderAcc_Blob_Linux(t *testing.T) {
    94  	builderT.Test(t, builderT.TestCase{
    95  		PreCheck: func() { testAccPreCheck(t) },
    96  		Builder:  &Builder{},
    97  		Template: testBuilderAccBlobLinux,
    98  	})
    99  }
   100  
   101  func testAccPreCheck(*testing.T) {}
   102  
   103  const testBuilderAccManagedDiskWindows = `
   104  {
   105  	"variables": {
   106  	  "client_id": "{{env ` + "`ARM_CLIENT_ID`" + `}}",
   107  	  "client_secret": "{{env ` + "`ARM_CLIENT_SECRET`" + `}}",
   108  	  "subscription_id": "{{env ` + "`ARM_SUBSCRIPTION_ID`" + `}}"
   109  	},
   110  	"builders": [{
   111  	  "type": "test",
   112  
   113  	  "client_id": "{{user ` + "`client_id`" + `}}",
   114  	  "client_secret": "{{user ` + "`client_secret`" + `}}",
   115  	  "subscription_id": "{{user ` + "`subscription_id`" + `}}",
   116  
   117  	  "managed_image_resource_group_name": "packer-acceptance-test",
   118  	  "managed_image_name": "testBuilderAccManagedDiskWindows-{{timestamp}}",
   119  
   120  	  "os_type": "Windows",
   121  	  "image_publisher": "MicrosoftWindowsServer",
   122  	  "image_offer": "WindowsServer",
   123  	  "image_sku": "2012-R2-Datacenter",
   124  
   125  	  "communicator": "winrm",
   126  	  "winrm_use_ssl": "true",
   127  	  "winrm_insecure": "true",
   128  	  "winrm_timeout": "3m",
   129  	  "winrm_username": "packer",
   130  	  "async_resourcegroup_delete": "true",
   131  
   132  	  "location": "South Central US",
   133  	  "vm_size": "Standard_DS2_v2"
   134  	}]
   135  }
   136  `
   137  const testBuilderAccManagedDiskWindowsBuildResourceGroup = `
   138  {
   139  	"variables": {
   140  	  "client_id": "{{env ` + "`ARM_CLIENT_ID`" + `}}",
   141  	  "client_secret": "{{env ` + "`ARM_CLIENT_SECRET`" + `}}",
   142  	  "subscription_id": "{{env ` + "`ARM_SUBSCRIPTION_ID`" + `}}"
   143  	},
   144  	"builders": [{
   145  	  "type": "test",
   146  
   147  	  "client_id": "{{user ` + "`client_id`" + `}}",
   148  	  "client_secret": "{{user ` + "`client_secret`" + `}}",
   149  	  "subscription_id": "{{user ` + "`subscription_id`" + `}}",
   150  
   151  	  "build_resource_group_name" : "packer-acceptance-test",
   152  	  "managed_image_resource_group_name": "packer-acceptance-test",
   153  	  "managed_image_name": "testBuilderAccManagedDiskWindows-{{timestamp}}",
   154  
   155  	  "os_type": "Windows",
   156  	  "image_publisher": "MicrosoftWindowsServer",
   157  	  "image_offer": "WindowsServer",
   158  	  "image_sku": "2012-R2-Datacenter",
   159  
   160  	  "communicator": "winrm",
   161  	  "winrm_use_ssl": "true",
   162  	  "winrm_insecure": "true",
   163  	  "winrm_timeout": "3m",
   164  	  "winrm_username": "packer",
   165  	  "async_resourcegroup_delete": "true",
   166  
   167  	  "vm_size": "Standard_DS2_v2"
   168  	}]
   169  }
   170  `
   171  
   172  const testBuilderAccManagedDiskWindowsDeviceLogin = `
   173  {
   174  	"variables": {
   175  	  "subscription_id": "{{env ` + "`ARM_SUBSCRIPTION_ID`" + `}}"
   176  	},
   177  	"builders": [{
   178  	  "type": "test",
   179  
   180  	  "subscription_id": "{{user ` + "`subscription_id`" + `}}",
   181  
   182  	  "managed_image_resource_group_name": "packer-acceptance-test",
   183  	  "managed_image_name": "testBuilderAccManagedDiskWindowsDeviceLogin-{{timestamp}}",
   184  
   185  	  "os_type": "Windows",
   186  	  "image_publisher": "MicrosoftWindowsServer",
   187  	  "image_offer": "WindowsServer",
   188  	  "image_sku": "2012-R2-Datacenter",
   189  
   190  	  "communicator": "winrm",
   191  	  "winrm_use_ssl": "true",
   192  	  "winrm_insecure": "true",
   193  	  "winrm_timeout": "3m",
   194  	  "winrm_username": "packer",
   195  
   196  	  "location": "South Central US",
   197  	  "vm_size": "Standard_DS2_v2"
   198  	}]
   199  }
   200  `
   201  
   202  const testBuilderAccManagedDiskLinux = `
   203  {
   204  	"variables": {
   205  	  "client_id": "{{env ` + "`ARM_CLIENT_ID`" + `}}",
   206  	  "client_secret": "{{env ` + "`ARM_CLIENT_SECRET`" + `}}",
   207  	  "subscription_id": "{{env ` + "`ARM_SUBSCRIPTION_ID`" + `}}"
   208  	},
   209  	"builders": [{
   210  	  "type": "test",
   211  
   212  	  "client_id": "{{user ` + "`client_id`" + `}}",
   213  	  "client_secret": "{{user ` + "`client_secret`" + `}}",
   214  	  "subscription_id": "{{user ` + "`subscription_id`" + `}}",
   215  
   216  	  "managed_image_resource_group_name": "packer-acceptance-test",
   217  	  "managed_image_name": "testBuilderAccManagedDiskLinux-{{timestamp}}",
   218  
   219  	  "os_type": "Linux",
   220  	  "image_publisher": "Canonical",
   221  	  "image_offer": "UbuntuServer",
   222  	  "image_sku": "16.04-LTS",
   223  
   224  	  "location": "South Central US",
   225  	  "vm_size": "Standard_DS2_v2"
   226  	}]
   227  }
   228  `
   229  const testBuilderAccManagedDiskLinuxDeviceLogin = `
   230  {
   231  	"variables": {
   232  	  "subscription_id": "{{env ` + "`ARM_SUBSCRIPTION_ID`" + `}}"
   233  	},
   234  	"builders": [{
   235  	  "type": "test",
   236  
   237  	  "subscription_id": "{{user ` + "`subscription_id`" + `}}",
   238  
   239  	  "managed_image_resource_group_name": "packer-acceptance-test",
   240  	  "managed_image_name": "testBuilderAccManagedDiskLinuxDeviceLogin-{{timestamp}}",
   241  
   242  	  "os_type": "Linux",
   243  	  "image_publisher": "Canonical",
   244  	  "image_offer": "UbuntuServer",
   245  	  "image_sku": "16.04-LTS",
   246  	  "async_resourcegroup_delete": "true",
   247  
   248  	  "location": "South Central US",
   249  	  "vm_size": "Standard_DS2_v2"
   250  	}]
   251  }
   252  `
   253  
   254  const testBuilderAccBlobWindows = `
   255  {
   256  	"variables": {
   257  	  "client_id": "{{env ` + "`ARM_CLIENT_ID`" + `}}",
   258  	  "client_secret": "{{env ` + "`ARM_CLIENT_SECRET`" + `}}",
   259  	  "subscription_id": "{{env ` + "`ARM_SUBSCRIPTION_ID`" + `}}",
   260  	  "object_id": "{{env ` + "`ARM_OBJECT_ID`" + `}}",
   261  	  "storage_account": "{{env ` + "`ARM_STORAGE_ACCOUNT`" + `}}"
   262  	},
   263  	"builders": [{
   264  	  "type": "test",
   265  
   266  	  "client_id": "{{user ` + "`client_id`" + `}}",
   267  	  "client_secret": "{{user ` + "`client_secret`" + `}}",
   268  	  "subscription_id": "{{user ` + "`subscription_id`" + `}}",
   269  	  "object_id": "{{user ` + "`object_id`" + `}}",
   270  
   271  	  "storage_account": "{{user ` + "`storage_account`" + `}}",
   272  	  "resource_group_name": "packer-acceptance-test",
   273  	  "capture_container_name": "test",
   274  	  "capture_name_prefix": "testBuilderAccBlobWin",
   275  
   276  	  "os_type": "Windows",
   277  	  "image_publisher": "MicrosoftWindowsServer",
   278  	  "image_offer": "WindowsServer",
   279  	  "image_sku": "2012-R2-Datacenter",
   280  
   281  	  "communicator": "winrm",
   282  	  "winrm_use_ssl": "true",
   283  	  "winrm_insecure": "true",
   284  	  "winrm_timeout": "3m",
   285  	  "winrm_username": "packer",
   286  
   287  	  "location": "South Central US",
   288  	  "vm_size": "Standard_DS2_v2"
   289  	}]
   290  }
   291  `
   292  
   293  const testBuilderAccBlobLinux = `
   294  {
   295  	"variables": {
   296  	  "client_id": "{{env ` + "`ARM_CLIENT_ID`" + `}}",
   297  	  "client_secret": "{{env ` + "`ARM_CLIENT_SECRET`" + `}}",
   298  	  "subscription_id": "{{env ` + "`ARM_SUBSCRIPTION_ID`" + `}}",
   299  	  "storage_account": "{{env ` + "`ARM_STORAGE_ACCOUNT`" + `}}"
   300  	},
   301  	"builders": [{
   302  	  "type": "test",
   303  
   304  	  "client_id": "{{user ` + "`client_id`" + `}}",
   305  	  "client_secret": "{{user ` + "`client_secret`" + `}}",
   306  	  "subscription_id": "{{user ` + "`subscription_id`" + `}}",
   307  
   308  	  "storage_account": "{{user ` + "`storage_account`" + `}}",
   309  	  "resource_group_name": "packer-acceptance-test",
   310  	  "capture_container_name": "test",
   311  	  "capture_name_prefix": "testBuilderAccBlobLinux",
   312  
   313  	  "os_type": "Linux",
   314  	  "image_publisher": "Canonical",
   315  	  "image_offer": "UbuntuServer",
   316  	  "image_sku": "16.04-LTS",
   317  
   318  	  "location": "South Central US",
   319  	  "vm_size": "Standard_DS2_v2"
   320  	}]
   321  }
   322  `