Skip to content

Commit

Permalink
tests(application): ensure resources in parallel tests have unique names
Browse files Browse the repository at this point in the history
  • Loading branch information
onematchfox committed May 4, 2023
1 parent 477d2aa commit f56d254
Showing 1 changed file with 38 additions and 37 deletions.
75 changes: 38 additions & 37 deletions argocd/resource_argocd_application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,58 +13,58 @@ import (
)

func TestAccArgoCDApplication(t *testing.T) {
commonName := acctest.RandomWithPrefix("test-acc")
name := acctest.RandomWithPrefix("test-acc")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccArgoCDApplicationSimple(commonName, "8.0.0", false),
Config: testAccArgoCDApplicationSimple(name, "8.0.0", false),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(
"argocd_application.simple",
"argocd_application."+name,
"metadata.0.uid",
),
resource.TestCheckResourceAttr(
"argocd_application.simple",
"argocd_application."+name,
"spec.0.source.0.target_revision",
"8.0.0",
),
),
},
{
ResourceName: "argocd_application.simple",
ResourceName: "argocd_application." + name,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"wait", "cascade", "metadata.0.generation", "metadata.0.resource_version"},
},
{
// Update
Config: testAccArgoCDApplicationSimple(commonName, "9.0.0", false),
Config: testAccArgoCDApplicationSimple(name, "9.0.0", false),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(
"argocd_application.simple",
"argocd_application."+name,
"metadata.0.uid",
),
resource.TestCheckResourceAttr(
"argocd_application.simple",
"argocd_application."+name,
"spec.0.source.0.target_revision",
"9.0.0",
),
),
},
{
// Update with wait = true
Config: testAccArgoCDApplicationSimple(commonName, "9.4.1", true),
Config: testAccArgoCDApplicationSimple(name, "9.4.1", true),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"argocd_application.simple",
"argocd_application."+name,
"wait",
"true",
),
resource.TestCheckResourceAttr(
"argocd_application.simple",
"argocd_application."+name,
"spec.0.source.0.target_revision",
"9.4.1",
),
Expand Down Expand Up @@ -266,18 +266,18 @@ func TestAccArgoCDApplication_OptionalDestinationNamespace(t *testing.T) {
Config: testAccArgoCDApplication_OptionalDestinationNamespace(acctest.RandomWithPrefix("test-acc")),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(
"argocd_application.simple",
"argocd_application.no_namespace",
"metadata.0.uid",
),
resource.TestCheckResourceAttr(
"argocd_application.simple",
"argocd_application.no_namespace",
"spec.0.destination.0.namespace",
"", // optional strings are maintained in state as blank strings
),
),
},
{
ResourceName: "argocd_application.simple",
ResourceName: "argocd_application.no_namespace",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"wait", "cascade"},
Expand Down Expand Up @@ -578,15 +578,15 @@ func TestAccArgoCDApplication_NoSyncPolicyBlock(t *testing.T) {
Config: testAccArgoCDApplicationNoSyncPolicy(acctest.RandomWithPrefix("test-acc")),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(
"argocd_application.simple",
"argocd_application.no_sync_policy",
"metadata.0.uid",
),
resource.TestCheckNoResourceAttr(
"argocd_application.simple",
"argocd_application.no_sync_policy",
"spec.0.sync_policy.0.retry.0.backoff.0.duration",
),
resource.TestCheckNoResourceAttr(
"argocd_application.simple",
"argocd_application.no_sync_policy",
"spec.0.sync_policy.0.automated.0.prune",
),
),
Expand All @@ -604,15 +604,15 @@ func TestAccArgoCDApplication_EmptySyncPolicyBlock(t *testing.T) {
Config: testAccArgoCDApplicationEmptySyncPolicy(acctest.RandomWithPrefix("test-acc")),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(
"argocd_application.simple",
"argocd_application.empty_sync_policy",
"metadata.0.uid",
),
resource.TestCheckNoResourceAttr(
"argocd_application.simple",
"argocd_application.empty_sync_policy",
"spec.0.sync_policy.0.retry.0.backoff.0.duration",
),
resource.TestCheckNoResourceAttr(
"argocd_application.simple",
"argocd_application.empty_sync_policy",
"spec.0.sync_policy.0.automated.0.prune",
),
),
Expand All @@ -630,15 +630,15 @@ func TestAccArgoCDApplication_NoAutomatedBlock(t *testing.T) {
Config: testAccArgoCDApplicationNoAutomated(acctest.RandomWithPrefix("test-acc")),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(
"argocd_application.simple",
"argocd_application.no_automated",
"metadata.0.uid",
),
resource.TestCheckResourceAttrSet(
"argocd_application.simple",
"argocd_application.no_automated",
"spec.0.sync_policy.0.retry.0.backoff.0.duration",
),
resource.TestCheckNoResourceAttr(
"argocd_application.simple",
"argocd_application.no_automated",
"spec.0.sync_policy.0.automated.0.prune",
),
),
Expand All @@ -656,15 +656,15 @@ func TestAccArgoCDApplication_EmptyAutomatedBlock(t *testing.T) {
Config: testAccArgoCDApplicationEmptyAutomated(acctest.RandomWithPrefix("test-acc")),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(
"argocd_application.simple",
"argocd_application.empty_automated",
"metadata.0.uid",
),
resource.TestCheckResourceAttrSet(
"argocd_application.simple",
"argocd_application.empty_automated",
"spec.0.sync_policy.0.automated.#",
),
resource.TestCheckNoResourceAttr(
"argocd_application.simple",
"argocd_application.empty_automated",
"spec.0.sync_policy.0.automated.0.prune",
),
),
Expand Down Expand Up @@ -977,13 +977,13 @@ func TestAccArgoCDApplication_CustomNamespace(t *testing.T) {
Config: testAccArgoCDApplicationCustomNamespace(name),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(
"argocd_application.simple",
"argocd_application."+name,
"metadata.0.uid",
),
),
},
{
ResourceName: "argocd_application.simple",
ResourceName: "argocd_application." + name,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"wait", "cascade"},
Expand Down Expand Up @@ -1028,21 +1028,22 @@ func TestAccArgoCDApplication_MultipleSources(t *testing.T) {

func TestAccArgoCDApplication_Wait(t *testing.T) {
chartRevision := "9.4.1"
name := acctest.RandomWithPrefix("test-acc")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccArgoCDApplicationSimple(acctest.RandomWithPrefix("test-acc"), chartRevision, true),
Config: testAccArgoCDApplicationSimple(name, chartRevision, true),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"argocd_application.simple",
"argocd_application."+name,
"wait",
"true",
),
resource.TestCheckResourceAttr(
"argocd_application.simple",
"argocd_application."+name,
"spec.0.source.0.target_revision",
chartRevision,
),
Expand All @@ -1054,7 +1055,7 @@ func TestAccArgoCDApplication_Wait(t *testing.T) {

func testAccArgoCDApplicationSimple(name, targetRevision string, wait bool) string {
return fmt.Sprintf(`
resource "argocd_application" "simple" {
resource "argocd_application" "%[1]s" {
metadata {
name = "%[1]s"
namespace = "argocd"
Expand Down Expand Up @@ -1561,7 +1562,7 @@ resource "argocd_application" "ignore_differences_jqpe" {

func testAccArgoCDApplication_OptionalDestinationNamespace(name string) string {
return fmt.Sprintf(`
resource "argocd_application" "simple" {
resource "argocd_application" "no_namespace" {
metadata {
name = "%s"
namespace = "argocd"
Expand All @@ -1585,7 +1586,7 @@ resource "argocd_application" "simple" {

func testAccArgoCDApplicationNoSyncPolicy(name string) string {
return fmt.Sprintf(`
resource "argocd_application" "simple" {
resource "argocd_application" "no_sync_policy" {
metadata {
name = "%s"
namespace = "argocd"
Expand All @@ -1610,7 +1611,7 @@ resource "argocd_application" "simple" {

func testAccArgoCDApplicationEmptySyncPolicy(name string) string {
return fmt.Sprintf(`
resource "argocd_application" "simple" {
resource "argocd_application" "empty_sync_policy" {
metadata {
name = "%s"
namespace = "argocd"
Expand All @@ -1637,7 +1638,7 @@ resource "argocd_application" "simple" {

func testAccArgoCDApplicationNoAutomated(name string) string {
return fmt.Sprintf(`
resource "argocd_application" "simple" {
resource "argocd_application" "no_automated" {
metadata {
name = "%s"
namespace = "argocd"
Expand Down Expand Up @@ -1672,7 +1673,7 @@ resource "argocd_application" "simple" {

func testAccArgoCDApplicationEmptyAutomated(name string) string {
return fmt.Sprintf(`
resource "argocd_application" "simple" {
resource "argocd_application" "empty_automated" {
metadata {
name = "%s"
namespace = "argocd"
Expand Down

0 comments on commit f56d254

Please sign in to comment.