// Code generated by "gen/generator.go"; DO NOT EDIT.
// In order to regenerate this file execute `go generate` from the repository root.
// More details can be found in the [README](https://github.com/CiscoDevNet/terraform-provider-aci/blob/master/README.md).

package provider

import (
	"regexp"
	"testing"

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

func TestAccResourceQosDscpClassWithQosCustomPol(t *testing.T) {

	resource.Test(t, resource.TestCase{
		PreCheck:                 func() { testAccPreCheck(t, "both", "1.0(1e)-") },
		ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
		Steps: []resource.TestStep{
			// Create with minimum config and verify default APIC values
			{
				Config:             testConfigQosDscpClassMinDependencyWithQosCustomPolAllowExisting,
				ExpectNonEmptyPlan: false,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.allow_test", "from", "AF11"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.allow_test_2", "from", "AF11"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.allow_test", "to", "AF22"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.allow_test_2", "to", "AF22"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.allow_test", "annotation", "orchestrator:terraform"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.allow_test_2", "annotation", "orchestrator:terraform"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.allow_test", "description", ""),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.allow_test_2", "description", ""),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.allow_test", "name", ""),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.allow_test_2", "name", ""),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.allow_test", "name_alias", ""),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.allow_test_2", "name_alias", ""),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.allow_test", "priority", "unspecified"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.allow_test_2", "priority", "unspecified"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.allow_test", "target", "unspecified"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.allow_test_2", "target", "unspecified"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.allow_test", "target_cos", "unspecified"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.allow_test_2", "target_cos", "unspecified"),
				),
			},
		},
	})

	setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false")
	resource.Test(t, resource.TestCase{
		PreCheck:                 func() { testAccPreCheck(t, "both", "1.0(1e)-") },
		ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
		Steps: []resource.TestStep{
			// Create with minimum config and verify default APIC values
			{
				Config:      testConfigQosDscpClassMinDependencyWithQosCustomPolAllowExisting,
				ExpectError: regexp.MustCompile("Object Already Exists"),
			},
		},
	})

	setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true")
	resource.Test(t, resource.TestCase{
		PreCheck:                 func() { testAccPreCheck(t, "both", "1.0(1e)-") },
		ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
		Steps: []resource.TestStep{
			// Create with minimum config and verify default APIC values
			{
				Config:             testConfigQosDscpClassMinDependencyWithQosCustomPolAllowExisting,
				ExpectNonEmptyPlan: false,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.allow_test", "from", "AF11"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.allow_test_2", "from", "AF11"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.allow_test", "to", "AF22"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.allow_test_2", "to", "AF22"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.allow_test", "annotation", "orchestrator:terraform"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.allow_test_2", "annotation", "orchestrator:terraform"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.allow_test", "description", ""),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.allow_test_2", "description", ""),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.allow_test", "name", ""),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.allow_test_2", "name", ""),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.allow_test", "name_alias", ""),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.allow_test_2", "name_alias", ""),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.allow_test", "priority", "unspecified"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.allow_test_2", "priority", "unspecified"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.allow_test", "target", "unspecified"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.allow_test_2", "target", "unspecified"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.allow_test", "target_cos", "unspecified"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.allow_test_2", "target_cos", "unspecified"),
				),
			},
		},
	})

	resource.Test(t, resource.TestCase{
		PreCheck:                 func() { testAccPreCheck(t, "both", "1.0(1e)-") },
		ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
		Steps: []resource.TestStep{
			// Create with minimum config and verify default APIC values
			{
				Config:             testConfigQosDscpClassMinDependencyWithQosCustomPol,
				ExpectNonEmptyPlan: false,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "from", "AF11"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "to", "AF22"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "annotation", "orchestrator:terraform"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "description", ""),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "name", ""),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "name_alias", ""),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "priority", "unspecified"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "target", "unspecified"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "target_cos", "unspecified"),
				),
			},
			// Update with all config and verify default APIC values
			{
				Config:             testConfigQosDscpClassAllDependencyWithQosCustomPol,
				ExpectNonEmptyPlan: false,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "from", "AF11"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "to", "AF22"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "annotation", "annotation"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "description", "description_1"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "name", "name_1"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "name_alias", "name_alias_1"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "priority", "level1"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "target", "AF11"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "target_cos", "0"),
				),
			},
			// Update with minimum config and verify config is unchanged
			{
				Config:             testConfigQosDscpClassMinDependencyWithQosCustomPol,
				ExpectNonEmptyPlan: false,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "from", "AF11"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "to", "AF22"),
				),
			},
			// Update with empty strings config or default value
			{
				Config:             testConfigQosDscpClassResetDependencyWithQosCustomPol,
				ExpectNonEmptyPlan: false,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "from", "AF11"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "to", "AF22"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "annotation", "orchestrator:terraform"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "description", ""),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "name", ""),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "name_alias", ""),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "priority", "unspecified"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "target", "unspecified"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "target_cos", "unspecified"),
				),
			},
			// Import testing
			{
				ResourceName:      "aci_dscp_to_priority_map.test",
				ImportState:       true,
				ImportStateVerify: true,
			},
			// Update with children
			{
				Config:             testConfigQosDscpClassChildrenDependencyWithQosCustomPol,
				ExpectNonEmptyPlan: false,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "from", "AF11"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "to", "AF22"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "annotation", "orchestrator:terraform"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "description", ""),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "name", ""),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "name_alias", ""),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "priority", "unspecified"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "target", "unspecified"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "target_cos", "unspecified"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "annotations.0.key", "key_0"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "annotations.0.value", "value_1"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "annotations.1.key", "key_1"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "annotations.1.value", "test_value"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "tags.0.key", "key_0"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "tags.0.value", "value_1"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "tags.1.key", "key_1"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "tags.1.value", "test_value"),
				),
			},
			// Refresh State before import testing to ensure that the state is up to date
			{
				RefreshState:       true,
				ExpectNonEmptyPlan: false,
			},
			// Import testing with children
			{
				ResourceName:      "aci_dscp_to_priority_map.test",
				ImportState:       true,
				ImportStateVerify: true,
			},
			// Update with children removed from config
			{
				Config:             testConfigQosDscpClassChildrenRemoveFromConfigDependencyWithQosCustomPol,
				ExpectNonEmptyPlan: false,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "annotations.0.key", "key_0"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "annotations.0.value", "value_1"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "annotations.1.key", "key_1"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "annotations.1.value", "test_value"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "annotations.#", "2"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "tags.0.key", "key_0"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "tags.0.value", "value_1"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "tags.1.key", "key_1"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "tags.1.value", "test_value"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "tags.#", "2"),
				),
			},
			// Update with children first child removed
			{
				Config:             testConfigQosDscpClassChildrenRemoveOneDependencyWithQosCustomPol,
				ExpectNonEmptyPlan: false,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "annotations.0.key", "key_1"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "annotations.0.value", "test_value"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "annotations.#", "1"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "tags.0.key", "key_1"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "tags.0.value", "test_value"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "tags.#", "1"),
				),
			},
			// Update with all children removed
			{
				Config:             testConfigQosDscpClassChildrenRemoveAllDependencyWithQosCustomPol,
				ExpectNonEmptyPlan: false,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "annotations.#", "0"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "tags.#", "0"),
				),
			},
			// Update with minimum config and custom type semantic equivalent values
			{
				Config:             testConfigQosDscpClassCustomTypeDependencyWithQosCustomPol,
				ExpectNonEmptyPlan: false,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "from", "0"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "priority", "1"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "target", "0"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "target_cos", "0"),
					resource.TestCheckResourceAttr("aci_dscp_to_priority_map.test", "to", "0"),
				),
			},
		},
		CheckDestroy: testCheckResourceDestroy,
	})
}

const testConfigQosDscpClassMinDependencyWithQosCustomPolAllowExisting = testConfigQosCustomPolMinDependencyWithFvTenant + `
resource "aci_dscp_to_priority_map" "allow_test" {
  parent_dn = aci_custom_qos_policy.test.id
  from = "AF11"
  to = "AF22"
}
resource "aci_dscp_to_priority_map" "allow_test_2" {
  parent_dn = aci_custom_qos_policy.test.id
  from = "AF11"
  to = "AF22"
  depends_on = [aci_dscp_to_priority_map.allow_test]
}
`

const testConfigQosDscpClassMinDependencyWithQosCustomPol = testConfigQosCustomPolMinDependencyWithFvTenant + `
resource "aci_dscp_to_priority_map" "test" {
  parent_dn = aci_custom_qos_policy.test.id
  from = "AF11"
  to = "AF22"
}
`

const testConfigQosDscpClassAllDependencyWithQosCustomPol = testConfigQosCustomPolMinDependencyWithFvTenant + `
resource "aci_dscp_to_priority_map" "test" {
  parent_dn = aci_custom_qos_policy.test.id
  from = "AF11"
  to = "AF22"
  annotation = "annotation"
  description = "description_1"
  name = "name_1"
  name_alias = "name_alias_1"
  priority = "level1"
  target = "AF11"
  target_cos = "0"
}
`

const testConfigQosDscpClassResetDependencyWithQosCustomPol = testConfigQosCustomPolMinDependencyWithFvTenant + `
resource "aci_dscp_to_priority_map" "test" {
  parent_dn = aci_custom_qos_policy.test.id
  from = "AF11"
  to = "AF22"
  annotation = "orchestrator:terraform"
  description = ""
  name = ""
  name_alias = ""
  priority = "unspecified"
  target = "unspecified"
  target_cos = "unspecified"
}
`
const testConfigQosDscpClassChildrenDependencyWithQosCustomPol = testConfigQosCustomPolMinDependencyWithFvTenant + `
resource "aci_dscp_to_priority_map" "test" {
  parent_dn = aci_custom_qos_policy.test.id
  from = "AF11"
  to = "AF22"
  annotations = [
    {
      key = "key_0"
      value = "value_1"
    },
    {
      key = "key_1"
      value = "test_value"
    },
  ]
  tags = [
    {
      key = "key_0"
      value = "value_1"
    },
    {
      key = "key_1"
      value = "test_value"
    },
  ]
}
`

const testConfigQosDscpClassChildrenRemoveFromConfigDependencyWithQosCustomPol = testConfigQosCustomPolMinDependencyWithFvTenant + `
resource "aci_dscp_to_priority_map" "test" {
  parent_dn = aci_custom_qos_policy.test.id
  from = "AF11"
  to = "AF22"
}
`

const testConfigQosDscpClassChildrenRemoveOneDependencyWithQosCustomPol = testConfigQosCustomPolMinDependencyWithFvTenant + `
resource "aci_dscp_to_priority_map" "test" {
  parent_dn = aci_custom_qos_policy.test.id
  from = "AF11"
  to = "AF22"
  annotations = [ 
	{
	  key = "key_1"
	  value = "test_value"
	},
  ]
  tags = [ 
	{
	  key = "key_1"
	  value = "test_value"
	},
  ]
}
`

const testConfigQosDscpClassChildrenRemoveAllDependencyWithQosCustomPol = testConfigQosCustomPolMinDependencyWithFvTenant + `
resource "aci_dscp_to_priority_map" "test" {
  parent_dn = aci_custom_qos_policy.test.id
  from = "AF11"
  to = "AF22"
  annotations = []
  tags = []
}
`

const testConfigQosDscpClassCustomTypeDependencyWithQosCustomPol = testConfigQosCustomPolMinDependencyWithFvTenant + `
resource "aci_dscp_to_priority_map" "test" {
  parent_dn = aci_custom_qos_policy.test.id
  from = "0"
  priority = "1"
  target = "0"
  target_cos = "0"
  to = "0"
}
`
