-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: live acceptance tests for service tests (#67)
- Loading branch information
1 parent
d45609e
commit 25f92ea
Showing
2 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package resource_test | ||
|
||
import ( | ||
"github.com/aruba-uxi/terraform-provider-configuration/test/live/config" | ||
"github.com/aruba-uxi/terraform-provider-configuration/test/live/provider" | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-testing/tfversion" | ||
) | ||
|
||
func TestServiceTestResource(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, | ||
TerraformVersionChecks: []tfversion.TerraformVersionCheck{ | ||
// we required terraform 1.7.0 and above for the `removed` block | ||
tfversion.RequireAbove(tfversion.Version1_7_0), | ||
}, | ||
Steps: []resource.TestStep{ | ||
// Creating a service_test is not allowed | ||
{ | ||
Config: provider.ProviderConfig + ` | ||
resource "uxi_service_test" "my_service_test" { | ||
name = "` + config.ServiceTestName + `" | ||
}`, | ||
|
||
ExpectError: regexp.MustCompile( | ||
`(?s)creating a service_test is not supported; service_tests can only be\s*imported`, | ||
), | ||
}, | ||
// Importing a service_test | ||
{ | ||
Config: provider.ProviderConfig + ` | ||
resource "uxi_service_test" "my_service_test" { | ||
name = "` + config.ServiceTestName + `" | ||
} | ||
import { | ||
to = uxi_service_test.my_service_test | ||
id = "` + config.ServiceTestUid + `" | ||
}`, | ||
|
||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr( | ||
"uxi_service_test.my_service_test", | ||
"name", | ||
config.ServiceTestName, | ||
), | ||
resource.TestCheckResourceAttr( | ||
"uxi_service_test.my_service_test", | ||
"id", | ||
config.ServiceTestUid, | ||
), | ||
), | ||
}, | ||
// ImportState testing | ||
{ | ||
ResourceName: "uxi_service_test.my_service_test", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
// Updating a service_test is not allowed | ||
{ | ||
Config: provider.ProviderConfig + ` | ||
resource "uxi_service_test" "my_service_test" { | ||
name = "` + config.ServiceTestName + `-updated-name" | ||
}`, | ||
ExpectError: regexp.MustCompile( | ||
`(?s)updating a service_test is not supported; service_tests can only be updated\s*through the dashboard`, | ||
), | ||
}, | ||
// Deleting a service_test is not allowed | ||
{ | ||
Config: provider.ProviderConfig + ``, | ||
ExpectError: regexp.MustCompile( | ||
`(?s)deleting a service_test is not supported; service_tests can only removed from\s*state`, | ||
), | ||
}, | ||
// Remove service_test from state | ||
{ | ||
Config: provider.ProviderConfig + ` | ||
removed { | ||
from = uxi_service_test.my_service_test | ||
lifecycle { | ||
destroy = false | ||
} | ||
}`, | ||
}, | ||
}, | ||
}) | ||
} |