Skip to content

Commit

Permalink
Fix and update TestAccDialogflowAgent_update (hashicorp#3334)
Browse files Browse the repository at this point in the history
* Fix TestAccDialogflowAgent_update

* Move to self hosted images

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician committed Apr 3, 2020
1 parent f3c888b commit 294755f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 38 deletions.
3 changes: 3 additions & 0 deletions .changelog/3334.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:none

```
86 changes: 48 additions & 38 deletions google/resource_dialogflow_agent_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package google

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
Expand All @@ -11,17 +10,18 @@ import (
func TestAccDialogflowAgent_update(t *testing.T) {
t.Parallel()

agentName := acctest.RandomWithPrefix("tf-test")
agentNameUpdate := acctest.RandomWithPrefix("tf-test")
projectID := acctest.RandomWithPrefix("tf-test")
orgID := getTestOrgFromEnv(t)
context := map[string]interface{}{
"org_id": getTestOrgFromEnv(t),
"billing_account": getTestBillingAccountFromEnv(t),
"random_suffix": acctest.RandString(10),
}

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDialogflowAgent_full1(projectID, orgID, agentName),
Config: testAccDialogflowAgent_full1(context),
},
{
ResourceName: "google_dialogflow_agent.foobar",
Expand All @@ -30,7 +30,7 @@ func TestAccDialogflowAgent_update(t *testing.T) {
ImportStateVerifyIgnore: []string{"avatar_uri", "tier"},
},
{
Config: testAccDialogflowAgent_full2(projectID, orgID, agentNameUpdate),
Config: testAccDialogflowAgent_full2(context),
},
{
ResourceName: "google_dialogflow_agent.foobar",
Expand All @@ -42,78 +42,88 @@ func TestAccDialogflowAgent_update(t *testing.T) {
})
}

func testAccDialogflowAgent_full1(projectID string, orgID string, agentName string) string {
return fmt.Sprintf(`
func testAccDialogflowAgent_full1(context map[string]interface{}) string {
return Nprintf(`
resource "google_project" "agent_project" {
project_id = "%s"
name = "%s"
org_id = "%s"
}
name = "tf-test-dialogflow-%{random_suffix}"
project_id = "tf-test-dialogflow-%{random_suffix}"
org_id = "%{org_id}"
billing_account = "%{billing_account}"
}
resource "google_project_service" "agent_project" {
project = google_project.agent_project.project_id
service = "dialogflow.googleapis.com"
}
disable_dependent_services = false
}
resource "google_service_account" "dialogflow_service_account" {
account_id = "tf-test-dialogflow-%{random_suffix}"
}
resource "google_project_iam_member" "agent_create" {
project = google_project_service.agent_project.project
role = "roles/dialogflow.admin"
member = "serviceAccount:service-${google_project.agent_project.number}@gcp-sa-dialogflow.iam.gserviceaccount.com"
depends_on = [google_project_service.agent_project]
}
member = "serviceAccount:${google_service_account.dialogflow_service_account.email}"
}
resource "google_dialogflow_agent" "foobar" {
project = "%s"
display_name = "%s"
project = google_project.agent_project.project_id
display_name = "tf-test-%{random_suffix}"
default_language_code = "en"
supported_language_codes = ["fr","de","es"]
time_zone = "America/New_York"
description = "Description 1."
avatar_uri = "https://cloud.google.com/_static/images/cloud/icons/favicons/onecloud/super_cloud.png"
avatar_uri = "https://storage.cloud.google.com/dialogflow-test-host-image/cloud-logo.png"
enable_logging = true
match_mode = "MATCH_MODE_ML_ONLY"
classification_threshold = 0.3
api_version = "API_VERSION_V2_BETA_1"
tier = "TIER_STANDARD"
depends_on = [google_project_iam_member.agent_create]
}
`, projectID, projectID, orgID, projectID, agentName)
}
`, context)
}

func testAccDialogflowAgent_full2(projectID string, orgID string, agentName string) string {
return fmt.Sprintf(`
func testAccDialogflowAgent_full2(context map[string]interface{}) string {
return Nprintf(`
resource "google_project" "agent_project" {
project_id = "%s"
name = "%s"
org_id = "%s"
}
name = "tf-test-dialogflow-%{random_suffix}"
project_id = "tf-test-dialogflow-%{random_suffix}"
org_id = "%{org_id}"
billing_account = "%{billing_account}"
}
resource "google_project_service" "agent_project" {
resource "google_project_service" "agent_project" {
project = google_project.agent_project.project_id
service = "dialogflow.googleapis.com"
}
disable_dependent_services = false
}
resource "google_service_account" "dialogflow_service_account" {
account_id = "tf-test-dialogflow-%{random_suffix}"
}
resource "google_project_iam_member" "agent_create" {
project = google_project_service.agent_project.project
role = "roles/dialogflow.admin"
member = "serviceAccount:service-${google_project.agent_project.number}@gcp-sa-dialogflow.iam.gserviceaccount.com"
depends_on = [google_project_service.agent_project]
}
member = "serviceAccount:${google_service_account.dialogflow_service_account.email}"
}
resource "google_dialogflow_agent" "foobar" {
project = "%s"
display_name = "%s"
project = google_project.agent_project.project_id
display_name = "tf-test-%{random_suffix}update"
default_language_code = "en"
supported_language_codes = ["no"]
time_zone = "America/New_York"
description = "Description 2!"
avatar_uri = "https://storage.googleapis.com/gweb-cloudblog-publish/images/f4xvje.max-200x200.PNG"
avatar_uri = "https://storage.cloud.google.com/dialogflow-test-host-image/cloud-logo-2.png"
enable_logging = false
match_mode = "MATCH_MODE_HYBRID"
classification_threshold = 0.7
api_version = "API_VERSION_V2"
tier = "TIER_ENTERPRISE"
depends_on = [google_project_iam_member.agent_create]
}
`, projectID, projectID, orgID, projectID, agentName)
}
`, context)
}

0 comments on commit 294755f

Please sign in to comment.