Skip to content

Commit

Permalink
[provider_test] skip tests for deprecated resource and APIs with repl…
Browse files Browse the repository at this point in the history
…ication delay (#2691)
  • Loading branch information
nkzou authored Nov 22, 2024
1 parent 1202c0e commit aa851de
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 137 deletions.
180 changes: 90 additions & 90 deletions datadog/tests/data_source_datadog_application_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,96 +9,96 @@ import (
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

func TestAccDatadogApplicationKeyDatasource_matchId(t *testing.T) {
if isRecording() || isReplaying() {
t.Skip("This test doesn't support recording or replaying")
}
t.Parallel()
ctx, providers, accProviders := testAccFrameworkMuxProviders(context.Background(), t)

applicationKeyName := uniqueEntityName(ctx, t)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: accProviders,
CheckDestroy: testAccCheckDatadogApplicationKeyDestroy(providers.frameworkProvider),
Steps: []resource.TestStep{
{
Config: testAccDatasourceApplicationKeyIdConfig(applicationKeyName),
Check: resource.ComposeTestCheckFunc(
testAccCheckDatadogApplicationKeyExists(providers.frameworkProvider, "datadog_application_key.app_key_1"),
resource.TestCheckResourceAttr("datadog_application_key.app_key_1", "name", fmt.Sprintf("%s 1", applicationKeyName)),
resource.TestCheckResourceAttr("datadog_application_key.app_key_2", "name", fmt.Sprintf("%s 2", applicationKeyName)),
resource.TestCheckResourceAttr("data.datadog_application_key.app_key", "name", fmt.Sprintf("%s 1", applicationKeyName)),
resource.TestCheckResourceAttrSet("data.datadog_application_key.app_key", "id"),
),
},
},
})
}

func TestAccDatadogApplicationKeyDatasource_matchName(t *testing.T) {
if isRecording() || isReplaying() {
t.Skip("This test doesn't support recording or replaying")
}
t.Parallel()
ctx, providers, accProviders := testAccFrameworkMuxProviders(context.Background(), t)
applicationKeyName := uniqueEntityName(ctx, t)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: accProviders,
CheckDestroy: testAccCheckDatadogApplicationKeyDestroy(providers.frameworkProvider),
Steps: []resource.TestStep{
{
Config: testAccDatasourceApplicationKeyNameConfig(applicationKeyName),
Check: resource.ComposeTestCheckFunc(
testAccCheckDatadogApplicationKeyExists(providers.frameworkProvider, "datadog_application_key.app_key_1"),
resource.TestCheckResourceAttr("datadog_application_key.app_key_1", "name", fmt.Sprintf("%s 1", applicationKeyName)),
resource.TestCheckResourceAttr("datadog_application_key.app_key_2", "name", fmt.Sprintf("%s 2", applicationKeyName)),
resource.TestCheckResourceAttr("data.datadog_application_key.app_key", "name", fmt.Sprintf("%s 1", applicationKeyName)),
resource.TestCheckResourceAttrSet("data.datadog_application_key.app_key", "id"),
),
},
{
Config: testAccDatasourceAppKeyExactMatch(applicationKeyName),
Check: resource.ComposeTestCheckFunc(
testAccCheckDatadogApplicationKeyExists(providers.frameworkProvider, "datadog_application_key.app_key_1"),
resource.TestCheckResourceAttr("datadog_application_key.app_key_1", "name", applicationKeyName),
resource.TestCheckResourceAttr("datadog_application_key.app_key_2", "name", fmt.Sprintf("%s 2", applicationKeyName)),
resource.TestCheckResourceAttr("data.datadog_application_key.app_key", "name", applicationKeyName),
resource.TestCheckResourceAttrSet("data.datadog_application_key.app_key", "id"),
),
},
},
})
}

func TestAccDatadogApplicationKeyDatasource_exactMatchName(t *testing.T) {
if isRecording() || isReplaying() {
t.Skip("This test doesn't support recording or replaying")
}
t.Parallel()
ctx, providers, accProviders := testAccFrameworkMuxProviders(context.Background(), t)
applicationKeyName := uniqueEntityName(ctx, t)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: accProviders,
CheckDestroy: testAccCheckDatadogApplicationKeyDestroy(providers.frameworkProvider),
Steps: []resource.TestStep{
{
Config: testAccDatasourceAppKeyExactMatch(applicationKeyName),
Check: resource.ComposeTestCheckFunc(
testAccCheckDatadogApplicationKeyExists(providers.frameworkProvider, "datadog_application_key.app_key_1"),
resource.TestCheckResourceAttr("datadog_application_key.app_key_1", "name", applicationKeyName),
resource.TestCheckResourceAttr("datadog_application_key.app_key_2", "name", fmt.Sprintf("%s 2", applicationKeyName)),
resource.TestCheckResourceAttr("data.datadog_application_key.app_key", "name", applicationKeyName),
resource.TestCheckResourceAttrSet("data.datadog_application_key.app_key", "id"),
),
},
},
})
}
// func TestAccDatadogApplicationKeyDatasource_matchId(t *testing.T) {
// if isRecording() || isReplaying() {
// t.Skip("This test doesn't support recording or replaying")
// }
// t.Parallel()
// ctx, providers, accProviders := testAccFrameworkMuxProviders(context.Background(), t)

// applicationKeyName := uniqueEntityName(ctx, t)
// resource.Test(t, resource.TestCase{
// PreCheck: func() { testAccPreCheck(t) },
// ProtoV5ProviderFactories: accProviders,
// CheckDestroy: testAccCheckDatadogApplicationKeyDestroy(providers.frameworkProvider),
// Steps: []resource.TestStep{
// {
// Config: testAccDatasourceApplicationKeyIdConfig(applicationKeyName),
// Check: resource.ComposeTestCheckFunc(
// testAccCheckDatadogApplicationKeyExists(providers.frameworkProvider, "datadog_application_key.app_key_1"),
// resource.TestCheckResourceAttr("datadog_application_key.app_key_1", "name", fmt.Sprintf("%s 1", applicationKeyName)),
// resource.TestCheckResourceAttr("datadog_application_key.app_key_2", "name", fmt.Sprintf("%s 2", applicationKeyName)),
// resource.TestCheckResourceAttr("data.datadog_application_key.app_key", "name", fmt.Sprintf("%s 1", applicationKeyName)),
// resource.TestCheckResourceAttrSet("data.datadog_application_key.app_key", "id"),
// ),
// },
// },
// })
// }

// func TestAccDatadogApplicationKeyDatasource_matchName(t *testing.T) {
// if isRecording() || isReplaying() {
// t.Skip("This test doesn't support recording or replaying")
// }
// t.Parallel()
// ctx, providers, accProviders := testAccFrameworkMuxProviders(context.Background(), t)
// applicationKeyName := uniqueEntityName(ctx, t)

// resource.Test(t, resource.TestCase{
// PreCheck: func() { testAccPreCheck(t) },
// ProtoV5ProviderFactories: accProviders,
// CheckDestroy: testAccCheckDatadogApplicationKeyDestroy(providers.frameworkProvider),
// Steps: []resource.TestStep{
// {
// Config: testAccDatasourceApplicationKeyNameConfig(applicationKeyName),
// Check: resource.ComposeTestCheckFunc(
// testAccCheckDatadogApplicationKeyExists(providers.frameworkProvider, "datadog_application_key.app_key_1"),
// resource.TestCheckResourceAttr("datadog_application_key.app_key_1", "name", fmt.Sprintf("%s 1", applicationKeyName)),
// resource.TestCheckResourceAttr("datadog_application_key.app_key_2", "name", fmt.Sprintf("%s 2", applicationKeyName)),
// resource.TestCheckResourceAttr("data.datadog_application_key.app_key", "name", fmt.Sprintf("%s 1", applicationKeyName)),
// resource.TestCheckResourceAttrSet("data.datadog_application_key.app_key", "id"),
// ),
// },
// {
// Config: testAccDatasourceAppKeyExactMatch(applicationKeyName),
// Check: resource.ComposeTestCheckFunc(
// testAccCheckDatadogApplicationKeyExists(providers.frameworkProvider, "datadog_application_key.app_key_1"),
// resource.TestCheckResourceAttr("datadog_application_key.app_key_1", "name", applicationKeyName),
// resource.TestCheckResourceAttr("datadog_application_key.app_key_2", "name", fmt.Sprintf("%s 2", applicationKeyName)),
// resource.TestCheckResourceAttr("data.datadog_application_key.app_key", "name", applicationKeyName),
// resource.TestCheckResourceAttrSet("data.datadog_application_key.app_key", "id"),
// ),
// },
// },
// })
// }

// func TestAccDatadogApplicationKeyDatasource_exactMatchName(t *testing.T) {
// if isRecording() || isReplaying() {
// t.Skip("This test doesn't support recording or replaying")
// }
// t.Parallel()
// ctx, providers, accProviders := testAccFrameworkMuxProviders(context.Background(), t)
// applicationKeyName := uniqueEntityName(ctx, t)

// resource.Test(t, resource.TestCase{
// PreCheck: func() { testAccPreCheck(t) },
// ProtoV5ProviderFactories: accProviders,
// CheckDestroy: testAccCheckDatadogApplicationKeyDestroy(providers.frameworkProvider),
// Steps: []resource.TestStep{
// {
// Config: testAccDatasourceAppKeyExactMatch(applicationKeyName),
// Check: resource.ComposeTestCheckFunc(
// testAccCheckDatadogApplicationKeyExists(providers.frameworkProvider, "datadog_application_key.app_key_1"),
// resource.TestCheckResourceAttr("datadog_application_key.app_key_1", "name", applicationKeyName),
// resource.TestCheckResourceAttr("datadog_application_key.app_key_2", "name", fmt.Sprintf("%s 2", applicationKeyName)),
// resource.TestCheckResourceAttr("data.datadog_application_key.app_key", "name", applicationKeyName),
// resource.TestCheckResourceAttrSet("data.datadog_application_key.app_key", "id"),
// ),
// },
// },
// })
// }

func TestAccDatadogApplicationKeyDatasource_matchIdError(t *testing.T) {
if isRecording() || isReplaying() {
Expand Down
71 changes: 25 additions & 46 deletions datadog/tests/resource_datadog_application_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ func TestAccDatadogApplicationKey_Update(t *testing.T) {
applicationKeyName := uniqueEntityName(ctx, t)
applicationKeyNameUpdate := applicationKeyName + "-2"
resourceName := "datadog_application_key.foo"
var keyValue string

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -34,15 +33,6 @@ func TestAccDatadogApplicationKey_Update(t *testing.T) {
testAccCheckDatadogApplicationKeyExists(providers.frameworkProvider, resourceName),
resource.TestCheckResourceAttr(resourceName, "name", applicationKeyName),
resource.TestCheckResourceAttrSet(resourceName, "key"),
func(s *terraform.State) error {
resource, ok := s.RootModule().Resources[resourceName]
if !ok {
return fmt.Errorf("Resource not found: %s", resourceName)
}
// Store the key value for later comparison after update
keyValue = resource.Primary.Attributes["key"]
return nil
},
),
},
{
Expand All @@ -52,48 +42,37 @@ func TestAccDatadogApplicationKey_Update(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "name", applicationKeyNameUpdate),
testAccCheckDatadogApplicationKeyNameMatches(providers.frameworkProvider, resourceName),
resource.TestCheckResourceAttrSet(resourceName, "key"),
func(s *terraform.State) error {
resource, ok := s.RootModule().Resources[resourceName]
if !ok {
return fmt.Errorf("Resource not found: %s", resourceName)
}
stateKeyValue := resource.Primary.Attributes["key"]
if stateKeyValue != keyValue {
return fmt.Errorf("application key value %s does not match expected value %s", stateKeyValue, keyValue)
}
return nil
},
),
},
},
})
}

func TestDatadogApplicationKey_import(t *testing.T) {
if isRecording() || isReplaying() {
t.Skip("This test doesn't support recording or replaying")
}
t.Parallel()
resourceName := "datadog_application_key.foo"
ctx, providers, accProviders := testAccFrameworkMuxProviders(context.Background(), t)
applicationKeyName := uniqueEntityName(ctx, t)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: accProviders,
CheckDestroy: testAccCheckDatadogApplicationKeyDestroy(providers.frameworkProvider),
Steps: []resource.TestStep{
{
Config: testAccCheckDatadogApplicationKeyConfigRequired(applicationKeyName),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
// func TestDatadogApplicationKey_import(t *testing.T) {
// if isRecording() || isReplaying() {
// t.Skip("This test doesn't support recording or replaying")
// }
// t.Parallel()
// resourceName := "datadog_application_key.foo"
// ctx, providers, accProviders := testAccFrameworkMuxProviders(context.Background(), t)
// applicationKeyName := uniqueEntityName(ctx, t)

// resource.Test(t, resource.TestCase{
// PreCheck: func() { testAccPreCheck(t) },
// ProtoV5ProviderFactories: accProviders,
// CheckDestroy: testAccCheckDatadogApplicationKeyDestroy(providers.frameworkProvider),
// Steps: []resource.TestStep{
// {
// Config: testAccCheckDatadogApplicationKeyConfigRequired(applicationKeyName),
// },
// {
// ResourceName: resourceName,
// ImportState: true,
// ImportStateVerify: true,
// },
// },
// })
// }

func testAccCheckDatadogApplicationKeyConfigRequired(uniq string) string {
return fmt.Sprintf(`
Expand Down
5 changes: 4 additions & 1 deletion datadog/tests/resource_datadog_domain_allowlist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import (
)

func TestAccDatadogDomainAllowlist_CreateUpdate(t *testing.T) {

if !isReplaying() {
// Skip in non-replay mode due to backend replication delay issues.
t.Skip("This test only runs in replay mode")
}
_, providers, accProviders := testAccFrameworkMuxProviders(context.Background(), t)

// When generating the casette, it may be necessary to add sleep functions before the check
Expand Down

0 comments on commit aa851de

Please sign in to comment.