Skip to content

Commit

Permalink
De-flaking cloudbuild trigger test (#4786)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored and chrisst committed Oct 31, 2019
1 parent ded497b commit ff87b90
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions google/resource_cloudbuild_trigger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,29 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

func TestAccCloudBuildTrigger_basic(t *testing.T) {
t.Parallel()
name := acctest.RandomWithPrefix("tf-test")

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckCloudBuildTriggerDestroy,
Steps: []resource.TestStep{
{
Config: testAccCloudBuildTrigger_basic(),
Config: testAccCloudBuildTrigger_basic(name),
},
{
ResourceName: "google_cloudbuild_trigger.build_trigger",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccCloudBuildTrigger_updated(),
Config: testAccCloudBuildTrigger_updated(name),
},
{
ResourceName: "google_cloudbuild_trigger.build_trigger",
Expand All @@ -37,22 +39,23 @@ func TestAccCloudBuildTrigger_basic(t *testing.T) {

func TestAccCloudBuildTrigger_disable(t *testing.T) {
t.Parallel()
name := acctest.RandomWithPrefix("tf-test")

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckCloudBuildTriggerDestroy,
Steps: []resource.TestStep{
{
Config: testAccCloudBuildTrigger_basic(),
Config: testAccCloudBuildTrigger_basic(name),
},
{
ResourceName: "google_cloudbuild_trigger.build_trigger",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccCloudBuildTrigger_basicDisabled(),
Config: testAccCloudBuildTrigger_basicDisabled(name),
},
{
ResourceName: "google_cloudbuild_trigger.build_trigger",
Expand Down Expand Up @@ -83,9 +86,10 @@ func TestAccCloudBuildTrigger_fullStep(t *testing.T) {
})
}

func testAccCloudBuildTrigger_basic() string {
func testAccCloudBuildTrigger_basic(name string) string {
return fmt.Sprintf(`
resource "google_cloudbuild_trigger" "build_trigger" {
name = "%s"
description = "acceptance test build trigger"
trigger_template {
branch_name = "master"
Expand All @@ -109,13 +113,14 @@ resource "google_cloudbuild_trigger" "build_trigger" {
}
}
}
`)
`, name)
}

func testAccCloudBuildTrigger_basicDisabled() string {
func testAccCloudBuildTrigger_basicDisabled(name string) string {
return fmt.Sprintf(`
resource "google_cloudbuild_trigger" "build_trigger" {
disabled = true
name = "%s"
description = "acceptance test build trigger"
trigger_template {
branch_name = "master"
Expand All @@ -139,7 +144,7 @@ resource "google_cloudbuild_trigger" "build_trigger" {
}
}
}
`)
`, name)
}

func testAccCloudBuildTrigger_fullStep() string {
Expand Down Expand Up @@ -168,10 +173,11 @@ resource "google_cloudbuild_trigger" "build_trigger" {
`)
}

func testAccCloudBuildTrigger_updated() string {
func testAccCloudBuildTrigger_updated(name string) string {
return fmt.Sprintf(`
resource "google_cloudbuild_trigger" "build_trigger" {
description = "acceptance test build trigger updated"
name = "%s"
trigger_template {
branch_name = "master-updated"
repo_name = "some-repo-updated"
Expand All @@ -197,5 +203,5 @@ resource "google_cloudbuild_trigger" "build_trigger" {
}
}
}
`)
`, name)
}

0 comments on commit ff87b90

Please sign in to comment.