|
| 1 | +package vra |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "regexp" |
| 6 | + |
| 7 | + "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" |
| 8 | + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" |
| 9 | + |
| 10 | + "testing" |
| 11 | +) |
| 12 | + |
| 13 | +func TestAccDataSourceVRAStorageProfile(t *testing.T) { |
| 14 | + rInt := acctest.RandInt() |
| 15 | + resourceName1 := "vra_storage_profile.this" |
| 16 | + dataSourceName1 := "data.vra_storage_profile.this" |
| 17 | + |
| 18 | + resource.Test(t, resource.TestCase{ |
| 19 | + PreCheck: func() { testAccPreCheckStorageProfile(t) }, |
| 20 | + Providers: testAccProviders, |
| 21 | + CheckDestroy: testAccCheckVRAStorageProfileDestroy, |
| 22 | + Steps: []resource.TestStep{ |
| 23 | + { |
| 24 | + Config: testAccDataSourceVRAStorageProfileNotFound(rInt), |
| 25 | + ExpectError: regexp.MustCompile("vra_storage_profile filter did not match any storage profile"), |
| 26 | + }, |
| 27 | + // TBD: Enable filter by name once this is fixed https://jira.eng.vmware.com/browse/VCOM-13947 |
| 28 | + // { |
| 29 | + // Config: testAccDataSourceVRAStorageProfileNameFilter(rInt), |
| 30 | + // Check: resource.ComposeTestCheckFunc( |
| 31 | + // resource.TestCheckResourceAttrPair(resourceName1, "id", dataSourceName1, "id"), |
| 32 | + // resource.TestCheckResourceAttrPair(resourceName1, "description", dataSourceName1, "description"), |
| 33 | + // resource.TestCheckResourceAttrPair(resourceName1, "name", dataSourceName1, "name"), |
| 34 | + // resource.TestCheckResourceAttrPair(resourceName1, "default_item", dataSourceName1, "default_item"), |
| 35 | + // resource.TestCheckResourceAttrPair(resourceName1, "external_region_id", dataSourceName1, "region_id"), |
| 36 | + // ), |
| 37 | + // }, |
| 38 | + { |
| 39 | + Config: testAccDataSourceVRAStorageProfileExternalRegionIDFilter(rInt), |
| 40 | + Check: resource.ComposeTestCheckFunc( |
| 41 | + resource.TestCheckResourceAttrPair(resourceName1, "id", dataSourceName1, "id"), |
| 42 | + resource.TestCheckResourceAttrPair(resourceName1, "description", dataSourceName1, "description"), |
| 43 | + resource.TestCheckResourceAttrPair(resourceName1, "name", dataSourceName1, "name"), |
| 44 | + resource.TestCheckResourceAttrPair(resourceName1, "default_item", dataSourceName1, "default_item"), |
| 45 | + resource.TestCheckResourceAttrPair(resourceName1, "external_region_id", dataSourceName1, "external_region_id"), |
| 46 | + ), |
| 47 | + }, |
| 48 | + { |
| 49 | + Config: testAccDataSourceVRAStorageProfileByID(rInt), |
| 50 | + Check: resource.ComposeTestCheckFunc( |
| 51 | + resource.TestCheckResourceAttrPair(resourceName1, "id", dataSourceName1, "id"), |
| 52 | + resource.TestCheckResourceAttrPair(resourceName1, "description", dataSourceName1, "description"), |
| 53 | + resource.TestCheckResourceAttrPair(resourceName1, "name", dataSourceName1, "name"), |
| 54 | + resource.TestCheckResourceAttrPair(resourceName1, "default_item", dataSourceName1, "default_item"), |
| 55 | + resource.TestCheckResourceAttrPair(resourceName1, "external_region_id", dataSourceName1, "external_region_id"), |
| 56 | + ), |
| 57 | + }, |
| 58 | + }, |
| 59 | + }) |
| 60 | +} |
| 61 | + |
| 62 | +func testAccDataSourceVRAStorageProfileNotFound(rInt int) string { |
| 63 | + return testAccCheckVRAStorageProfileConfig(rInt) + fmt.Sprintf(` |
| 64 | + data "vra_storage_profile" "this" { |
| 65 | + filter = "externalRegionId eq 'foobar'" |
| 66 | + }`) |
| 67 | +} |
| 68 | + |
| 69 | +// TBD: Enable filter by name once this is fixed https://jira.eng.vmware.com/browse/VCOM-13947 |
| 70 | +// func testAccDataSourceVRAStorageProfileNameFilter(rInt int) string { |
| 71 | +// return testAccCheckVRAStorageProfileConfig(rInt) + fmt.Sprintf(` |
| 72 | +// data "vra_storage_profile" "this" { |
| 73 | +// filter = "name eq '${vra_storage_profile.my-storage-profile.name}'" |
| 74 | +// }`) |
| 75 | +// } |
| 76 | + |
| 77 | +func testAccDataSourceVRAStorageProfileExternalRegionIDFilter(rInt int) string { |
| 78 | + return testAccCheckVRAStorageProfileConfig(rInt) + fmt.Sprintf(` |
| 79 | + data "vra_storage_profile" "this" { |
| 80 | + filter = "externalRegionId eq '${data.vra_region.this.id}'" |
| 81 | + }`) |
| 82 | +} |
| 83 | + |
| 84 | +func testAccDataSourceVRAStorageProfileByID(rInt int) string { |
| 85 | + return testAccCheckVRAStorageProfileConfig(rInt) + fmt.Sprintf(` |
| 86 | + data "vra_storage_profile" "this" { |
| 87 | + id = vra_storage_profile.this.id |
| 88 | + }`) |
| 89 | +} |
0 commit comments