2018-05-07 19:53:34 +00:00
|
|
|
package google
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAccCloudBuildTrigger_basic(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
2019-01-09 21:42:12 +00:00
|
|
|
CheckDestroy: testAccCheckCloudBuildTriggerDestroy,
|
2018-05-07 19:53:34 +00:00
|
|
|
Steps: []resource.TestStep{
|
2018-12-14 20:51:11 +00:00
|
|
|
{
|
2019-01-04 21:47:52 +00:00
|
|
|
Config: testGoogleCloudBuildTrigger_basic(),
|
2018-07-25 20:38:35 +00:00
|
|
|
},
|
2018-12-14 20:51:11 +00:00
|
|
|
{
|
2019-01-04 21:47:52 +00:00
|
|
|
ResourceName: "google_cloudbuild_trigger.build_trigger",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
2018-11-12 23:15:39 +00:00
|
|
|
},
|
2018-12-14 20:51:11 +00:00
|
|
|
{
|
2019-01-04 21:47:52 +00:00
|
|
|
Config: testGoogleCloudBuildTrigger_updated(),
|
2018-11-12 23:15:39 +00:00
|
|
|
},
|
2018-12-14 20:51:11 +00:00
|
|
|
{
|
2019-01-04 21:47:52 +00:00
|
|
|
ResourceName: "google_cloudbuild_trigger.build_trigger",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
2018-05-07 19:53:34 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-01-04 21:47:52 +00:00
|
|
|
func testGoogleCloudBuildTrigger_basic() string {
|
2018-05-07 19:53:34 +00:00
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_cloudbuild_trigger" "build_trigger" {
|
|
|
|
description = "acceptance test build trigger"
|
|
|
|
trigger_template {
|
|
|
|
branch_name = "master"
|
|
|
|
repo_name = "some-repo"
|
|
|
|
}
|
|
|
|
build {
|
|
|
|
images = ["gcr.io/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA"]
|
|
|
|
tags = ["team-a", "service-b"]
|
|
|
|
step {
|
|
|
|
name = "gcr.io/cloud-builders/gsutil"
|
2019-01-04 21:47:52 +00:00
|
|
|
args = ["cp", "gs://mybucket/remotefile.zip", "localfile.zip"]
|
2018-05-07 19:53:34 +00:00
|
|
|
}
|
|
|
|
step {
|
|
|
|
name = "gcr.io/cloud-builders/go"
|
2019-01-04 21:47:52 +00:00
|
|
|
args = ["build", "my_package"]
|
2018-05-07 19:53:34 +00:00
|
|
|
}
|
|
|
|
step {
|
|
|
|
name = "gcr.io/cloud-builders/docker"
|
2019-01-04 21:47:52 +00:00
|
|
|
args = ["build", "-t", "gcr.io/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA", "-f", "Dockerfile", "."]
|
2018-05-07 19:53:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-04 21:47:52 +00:00
|
|
|
`)
|
2018-05-07 19:53:34 +00:00
|
|
|
}
|
|
|
|
|
2019-01-04 21:47:52 +00:00
|
|
|
func testGoogleCloudBuildTrigger_updated() string {
|
2018-11-12 23:15:39 +00:00
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_cloudbuild_trigger" "build_trigger" {
|
|
|
|
description = "acceptance test build trigger updated"
|
|
|
|
trigger_template {
|
|
|
|
branch_name = "master-updated"
|
|
|
|
repo_name = "some-repo-updated"
|
|
|
|
}
|
|
|
|
build {
|
|
|
|
images = ["gcr.io/$PROJECT_ID/$REPO_NAME:$SHORT_SHA"]
|
|
|
|
tags = ["team-a", "service-b", "updated"]
|
|
|
|
step {
|
|
|
|
name = "gcr.io/cloud-builders/gsutil"
|
2019-01-04 21:47:52 +00:00
|
|
|
args = ["cp", "gs://mybucket/remotefile.zip", "localfile-updated.zip"]
|
2018-11-12 23:15:39 +00:00
|
|
|
}
|
|
|
|
step {
|
|
|
|
name = "gcr.io/cloud-builders/go"
|
2019-01-04 21:47:52 +00:00
|
|
|
args = ["build", "my_package_updated"]
|
2018-11-12 23:15:39 +00:00
|
|
|
}
|
|
|
|
step {
|
|
|
|
name = "gcr.io/cloud-builders/docker"
|
2019-01-04 21:47:52 +00:00
|
|
|
args = ["build", "-t", "gcr.io/$PROJECT_ID/$REPO_NAME:$SHORT_SHA", "-f", "Dockerfile", "."]
|
2018-11-12 23:15:39 +00:00
|
|
|
}
|
|
|
|
step {
|
|
|
|
name = "gcr.io/$PROJECT_ID/$REPO_NAME:$SHORT_SHA"
|
2019-01-04 21:47:52 +00:00
|
|
|
args = ["test"]
|
2018-11-12 23:15:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-04 21:47:52 +00:00
|
|
|
`)
|
2018-11-12 23:15:39 +00:00
|
|
|
}
|