<commit_before>// Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.

package provider

import (
	"fmt"
	"testing"

	"github.com/hashicorp/terraform/helper/resource"
	"github.com/hashicorp/terraform/terraform"
)

const (
	DbHomeRequiredOnlyResource = DbHomeResourceDependencies + `
resource "oci_database_db_home" "test_db_home" {
	#Required
	database {
		#Required
		admin_password = "${var.db_home_database_admin_password}"
		db_name = "${var.db_home_database_db_name}"
	}
	db_system_id = "${oci_database_db_system.test_db_system.id}"
	db_version = "${var.db_home_db_version}"
}
`

	DbHomeResourceConfig = DbHomeResourceDependencies + `
resource "oci_database_db_home" "test_db_home" {
	#Required
	database {
		#Required
		admin_password = "${var.db_home_database_admin_password}"
		backup_id = "${oci_database_backup.test_backup.id}"
		backup_tde_password = "${var.db_home_database_backup_tde_password}"
		db_name = "${var.db_home_database_db_name}"

		#Optional
		character_set = "${var.db_home_database_character_set}"
		db_backup_config {

			#Optional
			auto_backup_enabled = "${var.db_home_database_db_backup_config_auto_backup_enabled}"
		}
		db_workload = "${var.db_home_database_db_workload}"
		defined_tags = "${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "${var.db_home_database_defined_tags_value}")}"
		freeform_tags = "${var.db_home_database_freeform_tags}"
		ncharacter_set = "${var.db_home_database_ncharacter_set}"
		pdb_name = "${var.db_home_database_pdb_name}"
	}
	db_system_id = "${oci_database_db_system.test_db_system.id}"
	db_version = "${var.db_home_db_version}"

	#Optional
	display_name = "${var.db_home_display_name}"
	source = "${var.db_home_source}"
}
`
	DbHomePropertyVariables = `
variable "db_home_database_admin_password" { default = "<PASSWORD>" }
variable "db_home_database_backup_tde_password" { default = "<PASSWORD>" }
variable "db_home_database_character_set" { default = "AL32UTF8" }
variable "db_home_database_db_backup_config_auto_backup_enabled" { default = false }
variable "db_home_database_db_name" { default = "myTestDb" }
variable "db_home_database_db_workload" { default = "dbWorkload" }
variable "db_home_database_defined_tags_value" { default = "value" }
variable "db_home_database_freeform_tags" { default = {"Department"= "Finance"} }
variable "db_home_database_ncharacter_set" { default = "AL16UTF16" }
variable "db_home_database_pdb_name" { default = "pdbName" }
variable "db_home_display_name" { default = "createdDbHome" }
variable "db_home_source" { default = "DB_BACKUP" }
variable "db_home_db_version" { default = "172.16.58.3" }

`
	DbHomeResourceDependencies = BackupResourceConfig + BackupPropertyVariables
)

func TestDatabaseDbHomeResource_basic(t *testing.T) {
	provider := testAccProvider
	config := testProviderConfig()

	compartmentId := getRequiredEnvSetting("compartment_ocid")
	compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)

	resourceName := "oci_database_db_home.test_db_home"
	datasourceName := "data.oci_database_db_homes.test_db_homes"

	resource.Test(t, resource.TestCase{
		Providers: map[string]terraform.ResourceProvider{
			"oci": provider,
		},
		Steps: []resource.TestStep{
			// verify create
			{
				ImportState:       true,
				ImportStateVerify: true,<commit_msg>fixing dbHome Test after tag change<commit_after>// Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.

package provider

import (
	"fmt"
	"testing"

	"github.com/hashicorp/terraform/helper/resource"
	"github.com/hashicorp/terraform/terraform"
)

const (
	DbHomeRequiredOnlyResource = DbHomeResourceDependencies + `
resource "oci_database_db_home" "test_db_home" {
	#Required
	database {
		#Required
		admin_password = "${var.db_home_database_admin_password}"
		db_name = "${var.db_home_database_db_name}"
	}
	db_system_id = "${oci_database_db_system.test_db_system.id}"
	db_version = "${var.db_home_db_version}"
}
`

	DbHomeResourceConfig = DbHomeResourceDependencies + `
resource "oci_database_db_home" "test_db_home" {
	#Required
	database {
		#Required
		admin_password = "${var.db_home_database_admin_password}"
		backup_id = "${oci_database_backup.test_backup.id}"
		backup_tde_password = "${var.db_home_database_backup_tde_password}"
		db_name = "${var.db_home_database_db_name}"

		#Optional
		character_set = "${var.db_home_database_character_set}"
		db_backup_config {

			#Optional
			auto_backup_enabled = "${var.db_home_database_db_backup_config_auto_backup_enabled}"
		}
		db_workload = "${var.db_home_database_db_workload}"
		defined_tags = "${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "${var.db_home_database_defined_tags_value}")}"
		freeform_tags = "${var.db_home_database_freeform_tags}"
		ncharacter_set = "${var.db_home_database_ncharacter_set}"
		pdb_name = "${var.db_home_database_pdb_name}"
	}
	db_system_id = "${oci_database_db_system.test_db_system.id}"
	db_version = "${var.db_home_db_version}"

	#Optional
	display_name = "${var.db_home_display_name}"
	source = "${var.db_home_source}"
}
`
	DbHomePropertyVariables = `
variable "db_home_database_admin_password" { default = "<PASSWORD>" }
variable "db_home_database_backup_tde_password" { default = "<PASSWORD>" }
variable "db_home_database_character_set" { default = "AL32UTF8" }
variable "db_home_database_db_backup_config_auto_backup_enabled" { default = false }
variable "db_home_database_db_name" { default = "myTestDb" }
variable "db_home_database_db_workload" { default = "dbWorkload" }
variable "db_home_database_defined_tags_value" { default = "value" }
variable "db_home_database_freeform_tags" { default = {"Department"= "Finance"} }
variable "db_home_database_ncharacter_set" { default = "AL16UTF16" }
variable "db_home_database_pdb_name" { default = "pdbName" }
variable "db_home_display_name" { default = "createdDbHome" }
variable "db_home_source" { default = "DB_BACKUP" }
variable "db_home_db_version" { default = "172.16.58.3" }

`
	DbHomeResourceDependencies = BackupResourceConfig + BackupPropertyVariables + DefinedTagsDependencies
)

func TestDatabaseDbHomeResource_basic(t *testing.T) {
	provider := testAccProvider
	config := testProviderConfig()

	compartmentId := getRequiredEnvSetting("compartment_ocid")
	compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)

	resourceName := "oci_database_db_home.test_db_home"
	datasourceName := "data.oci_database_db_homes.test_db_homes"

	resource.Test(t, resource.TestCase{
		Providers: map[string]terraform.ResourceProvider{
			"oci": provider,
		},
		Steps: []resource.TestStep{
			// verify create
			{
				ImportState:       true,
				ImportStateVerify: true,
{'fraction_non_alphanumeric': 0.11941833137485311, 'fraction_numerical': 0.006169212690951821, 'mean_word_length': 6.7375, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '2627097', 'n_tokens_mistral': 2458, 'n_tokens_neox': 2342, 'n_words': 343}