Skip to content

Commit

Permalink
updating testACC checks
Browse files Browse the repository at this point in the history
  • Loading branch information
poddm committed Jun 21, 2023
1 parent 738f8bf commit a0c7bb6
Showing 1 changed file with 13 additions and 60 deletions.
73 changes: 13 additions & 60 deletions cloudstack/resource_cloudstack_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,17 @@ func TestAccCloudStackConfiguration_basic(t *testing.T) {
var configuration cloudstack.ListConfigurationsResponse

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckCloudStackConfigurationDestroy,
Steps: []resource.TestStep{
{
Config: testAccResourceConfiguration(),
Check: resource.ComposeTestCheckFunc(
testAccCheckCloudStackConfigurationExists("cloudstack_configuration.test", &configuration),
testAccCheckCloudStackConfigurationAttributes(&configuration),
),
},
},
})
}

func TestAccCloudStackConfiguration_update(t *testing.T) {
var configuration cloudstack.ListConfigurationsResponse
// var configuration_update cloudstack.UpdateConfigurationResponse

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccResourceConfiguration(),
Check: resource.ComposeTestCheckFunc(
testAccCheckCloudStackConfigurationExists("cloudstack_configuration.test", &configuration),
testAccCheckCloudStackConfigurationAttributes(&configuration),
resource.TestCheckResourceAttr("cloudstack_configuration.test", "value", "test_host"),
),
},

{
Config: testAccResourceConfiguration_update(),
Check: resource.ComposeTestCheckFunc(
testAccCheckCloudStackConfigurationExists("cloudstack_configuration.test", &configuration),
// testAccCheckCloudStackConfigurationUpdate(&configuration),
resource.TestCheckResourceAttr("cloudstack_configuration.test", "value", "new_test_host"),
),
},
},
})
}
Expand Down Expand Up @@ -102,31 +74,21 @@ func testAccCheckCloudStackConfigurationExists(n string, configuration *cloudsta

func testAccCheckCloudStackConfigurationAttributes(configuration *cloudstack.ListConfigurationsResponse) resource.TestCheckFunc {
return func(s *terraform.State) error {

if configuration.Configurations[0].Name != "host" {
return fmt.Errorf("Bad name: %s", configuration.Configurations[0].Name)
}

if configuration.Configurations[0].Value != "test_host" {
return fmt.Errorf("Bad name: %s", configuration.Configurations[0].Name)
for _, v := range configuration.Configurations {
if v.Name == "host" {
if v.Value != "test_host" {
return fmt.Errorf("Bad value: %s", v.Value)
}
return nil
}
}

return nil
return fmt.Errorf("Bad name: %s", "host")
}
}

func testAccCheckCloudStackConfigurationUpdate(configuration *cloudstack.ListConfigurationsResponse) resource.TestCheckFunc {
return func(s *terraform.State) error {
if configuration.Configurations[0].Name != "host" {
return fmt.Errorf("Bad name: %s", configuration.Configurations[0].Name)
}
func testAccCheckCloudStackConfigurationDestroy(s *terraform.State) error {
return nil

if configuration.Configurations[0].Value != "new_test_host" {
return fmt.Errorf("Bad name: %s", configuration.Configurations[0].Name)
}

return nil
}
}

func testAccResourceConfiguration() string {
Expand All @@ -137,12 +99,3 @@ func testAccResourceConfiguration() string {
}
`)
}

func testAccResourceConfiguration_update() string {
return fmt.Sprintf(`
resource "cloudstack_configuration" "test" {
name = "host"
value = "new_test_host"
}
`)
}

0 comments on commit a0c7bb6

Please sign in to comment.