Skip to content

Commit

Permalink
feat: live acceptance tests for service tests (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
1riatsila1 authored Nov 7, 2024
1 parent d45609e commit 25f92ea
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
2 changes: 2 additions & 0 deletions test/live/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ const WiredNetworkUid = "ethernet-658f93b6ea49"
const WiredNetworkName = "tf-provider-acceptance-tests-ethernet-0"
const WirelessNetworkUid = "ssid-35e69ecab0c3"
const WirelessNetworkName = "tf-provider-acceptance-tests-ssid-0"
const ServiceTestUid = "f0e703cb-9170-4da9-aa64-acf7379af3c3"
const ServiceTestName = "tf-provider-acceptance-test-0"
93 changes: 93 additions & 0 deletions test/live/resources/service_test.go
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
}
}`,
},
},
})
}

0 comments on commit 25f92ea

Please sign in to comment.