Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

De-flaking cloudbuild trigger test #4786

Merged
merged 1 commit into from
Oct 31, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}