<commit_before><% autogen_exception -%>
package google

import (
	"fmt"
	"testing"

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

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)

	resource.Test(t, resource.TestCase{
		PreCheck:  func() { testAccPreCheck(t) },
		Providers: testAccProviders,
		Steps: []resource.TestStep{
			{
				Config: testAccDialogflowAgent_full1(projectID, orgID, agentName),
			},
			{
				ResourceName:      "google_dialogflow_agent.foobar",
				ImportState:       true,
				ImportStateVerify: true,
				ImportStateVerifyIgnore: []string{"avatar_uri","tier"},
			},
			{
				Config: testAccDialogflowAgent_full2(projectID, orgID, agentNameUpdate),
			},
			{
				ResourceName:      "google_dialogflow_agent.foobar",
				ImportState:       true,
				ImportStateVerify: true,
				ImportStateVerifyIgnore: []string{"avatar_uri","tier"},
			},
		},
	})
}

func testAccDialogflowAgent_full1(projectID string, orgID string, agentName string) string {
	return fmt.Sprintf(`
	resource "google_project" "agent_project" {
		project_id = "%s"
		name       = "%s"
		org_id     = "%s"
	  }

	resource "google_project_service" "agent_project" {
		project = google_project.agent_project.project_id
		service = "dialogflow.googleapis.com"
	  }
	  
	resource "google_project_iam_member" "agent_create" {
		project = google_project_service.agent_project.project
		role    = "roles/dialogflow.admin"
		member  = "serviceAccount:<EMAIL>-${google_project.agent_project.number}<EMAIL>"
		depends_on = [google_project_service.agent_project]
	  }

	resource "google_dialogflow_agent" "foobar" {
		project = "%s"
		display_name = "%s"
		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"
		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)
}

func testAccDialogflowAgent_full2(projectID string, orgID string, agentName string) string {
	return fmt.Sprintf(`
	resource "google_project" "agent_project" {
		project_id = "%s"
		name       = "%s"
		org_id     = "%s"
	  }

	  resource "google_project_service" "agent_project" {
		project = google_project.agent_project.project_id
		service = "dialogflow.googleapis.com"
	  }
	  
	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}<EMAIL>"
		depends_on = [google_project_service.agent_project]
	  }

	resource "google_dialogflow_agent" "foobar" {
		project = "%s"
		display_name = "%s"
		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"
		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)
}
<commit_msg>Fix and update TestAccDialogflowAgent_update (#3334)<commit_after><% autogen_exception -%>
package google

import (
	"testing"

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

func TestAccDialogflowAgent_update(t *testing.T) {
	t.Parallel()

	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(context),
			},
			{
				ResourceName:            "google_dialogflow_agent.foobar",
				ImportState:             true,
				ImportStateVerify:       true,
				ImportStateVerifyIgnore: []string{"avatar_uri", "tier"},
			},
			{
				Config: testAccDialogflowAgent_full2(context),
			},
			{
				ResourceName:            "google_dialogflow_agent.foobar",
				ImportState:             true,
				ImportStateVerify:       true,
				ImportStateVerifyIgnore: []string{"avatar_uri", "tier"},
			},
		},
	})
}

func testAccDialogflowAgent_full1(context map[string]interface{}) string {
	return Nprintf(`
	resource "google_project" "agent_project" {
		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:${google_service_account.dialogflow_service_account.email}"
	}

	resource "google_dialogflow_agent" "foobar" {
		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://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]
	}
	`, context)
}

func testAccDialogflowAgent_full2(context map[string]interface{}) string {
	return Nprintf(`
	resource "google_project" "agent_project" {
		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:${google_service_account.dialogflow_service_account.email}"
	}

	resource "google_dialogflow_agent" "foobar" {
		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.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]
	}
	  `, context)
}

{'fraction_non_alphanumeric': 0.11982791345058838, 'fraction_numerical': 0.005061369100341643, 'mean_word_length': 4.7862371888726205, 'pattern_counts': {'":': 3, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2892379', 'n_tokens_mistral': 2976, 'n_tokens_neox': 2695, 'n_words': 396}