Skip to content

Commit

Permalink
Merge pull request #418 from terraform-providers/f-remove-subtests
Browse files Browse the repository at this point in the history
Convert all acceptance tests to individual tests
  • Loading branch information
vancluever authored Mar 3, 2018
2 parents 7a48a7e + 34a2551 commit 79e7cf2
Show file tree
Hide file tree
Showing 27 changed files with 4,435 additions and 4,786 deletions.
68 changes: 26 additions & 42 deletions vsphere/data_source_vsphere_custom_attribute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,34 @@ import (
"github.com/hashicorp/terraform/helper/resource"
)

func TestAccDataSourceVSphereCustomAttribute(t *testing.T) {
var tp *testing.T
testAccDataSourceVSphereCustomAttributeCases := []struct {
name string
testCase resource.TestCase
}{
{
"basic",
resource.TestCase{
PreCheck: func() {
testAccPreCheck(tp)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceVSphereCustomAttributeConfig(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"data.vsphere_custom_attribute.terraform-test-attribute-data",
"name",
testAccDataSourceVSphereCustomAttributeConfigName,
),
resource.TestCheckResourceAttr(
"data.vsphere_custom_attribute.terraform-test-attribute-data",
"managed_object_type",
testAccDataSourceVSphereCustomAttributeConfigType,
),
resource.TestCheckResourceAttrPair(
"data.vsphere_custom_attribute.terraform-test-attribute-data", "id",
"vsphere_custom_attribute.terraform-test-attribute", "id",
),
),
},
},
func TestAccDataSourceVSphereCustomAttribute_basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceVSphereCustomAttributeConfig(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"data.vsphere_custom_attribute.terraform-test-attribute-data",
"name",
testAccDataSourceVSphereCustomAttributeConfigName,
),
resource.TestCheckResourceAttr(
"data.vsphere_custom_attribute.terraform-test-attribute-data",
"managed_object_type",
testAccDataSourceVSphereCustomAttributeConfigType,
),
resource.TestCheckResourceAttrPair(
"data.vsphere_custom_attribute.terraform-test-attribute-data", "id",
"vsphere_custom_attribute.terraform-test-attribute", "id",
),
),
},
},
}

for _, tc := range testAccDataSourceVSphereCustomAttributeCases {
t.Run(tc.name, func(t *testing.T) {
tp = t
resource.Test(t, tc.testCase)
})
}
})
}

const testAccDataSourceVSphereCustomAttributeConfigName = "terraform-test-attribute"
Expand Down
92 changes: 38 additions & 54 deletions vsphere/data_source_vsphere_datacenter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,64 +11,48 @@ import (

var testAccDataSourceVSphereDatacenterExpectedRegexp = regexp.MustCompile("^datacenter-")

func TestAccDataSourceVSphereDatacenter(t *testing.T) {
var tp *testing.T
testAccDataSourceVSphereDatacenterCases := []struct {
name string
testCase resource.TestCase
}{
{
"basic",
resource.TestCase{
PreCheck: func() {
testAccPreCheck(tp)
testAccDataSourceVSphereDatacenterPreCheck(tp)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceVSphereDatacenterConfig(),
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr(
"data.vsphere_datacenter.dc",
"id",
testAccDataSourceVSphereDatacenterExpectedRegexp,
),
),
},
},
},
func TestAccDataSourceVSphereDatacenter_basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccDataSourceVSphereDatacenterPreCheck(t)
},
{
"default",
resource.TestCase{
PreCheck: func() {
testAccPreCheck(tp)
testAccDataSourceVSphereDatacenterPreCheck(tp)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceVSphereDatacenterConfigDefault,
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr(
"data.vsphere_datacenter.dc",
"id",
testAccDataSourceVSphereDatacenterExpectedRegexp,
),
),
},
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceVSphereDatacenterConfig(),
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr(
"data.vsphere_datacenter.dc",
"id",
testAccDataSourceVSphereDatacenterExpectedRegexp,
),
),
},
},
}
})
}

for _, tc := range testAccDataSourceVSphereDatacenterCases {
t.Run(tc.name, func(t *testing.T) {
tp = t
resource.Test(t, tc.testCase)
})
}
func TestAccDataSourceVSphereDatacenter_defaultDatacenter(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccDataSourceVSphereDatacenterPreCheck(t)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceVSphereDatacenterConfigDefault,
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr(
"data.vsphere_datacenter.dc",
"id",
testAccDataSourceVSphereDatacenterExpectedRegexp,
),
),
},
},
})
}

func testAccDataSourceVSphereDatacenterPreCheck(t *testing.T) {
Expand Down
88 changes: 36 additions & 52 deletions vsphere/data_source_vsphere_datastore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,62 +8,46 @@ import (
"github.com/hashicorp/terraform/helper/resource"
)

func TestAccDataSourceVSphereDatastore(t *testing.T) {
var tp *testing.T
testAccDataSourceVSphereDatastoreCases := []struct {
name string
testCase resource.TestCase
}{
{
"basic",
resource.TestCase{
PreCheck: func() {
testAccPreCheck(tp)
testAccDataSourceVSphereDatastorePreCheck(tp)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceVSphereDatastoreConfig(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(
"data.vsphere_datastore.datastore_data", "id",
"vsphere_nas_datastore.datastore", "id",
),
),
},
},
},
func TestAccDataSourceVSphereDatastore_basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccDataSourceVSphereDatastorePreCheck(t)
},
{
"no datacenter and absolute path",
resource.TestCase{
PreCheck: func() {
testAccPreCheck(tp)
testAccDataSourceVSphereDatastorePreCheck(tp)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceVSphereDatastoreConfigAbsolutePath(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(
"data.vsphere_datastore.datastore_data", "id",
"vsphere_nas_datastore.datastore", "id",
),
),
},
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceVSphereDatastoreConfig(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(
"data.vsphere_datastore.datastore_data", "id",
"vsphere_nas_datastore.datastore", "id",
),
),
},
},
}
})
}

for _, tc := range testAccDataSourceVSphereDatastoreCases {
t.Run(tc.name, func(t *testing.T) {
tp = t
resource.Test(t, tc.testCase)
})
}
func TestAccDataSourceVSphereDatastore_noDatacenterAndAbsolutePath(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccDataSourceVSphereDatastorePreCheck(t)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceVSphereDatastoreConfigAbsolutePath(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(
"data.vsphere_datastore.datastore_data", "id",
"vsphere_nas_datastore.datastore", "id",
),
),
},
},
})
}

func testAccDataSourceVSphereDatastorePreCheck(t *testing.T) {
Expand Down
Loading

0 comments on commit 79e7cf2

Please # to comment.