// Copyright © 2023 Cisco Systems, Inc. and its affiliates.
// All rights reserved.
//
// Licensed under the Mozilla Public License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://mozilla.org/MPL/2.0/
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: MPL-2.0

// Code generated by "gen/generator.go"; DO NOT EDIT.

package provider

// Section below is generated&owned by "gen/generator.go". //template:begin imports
import (
	"fmt"
	"os"
	"testing"

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

// End of section. //template:end imports

// Section below is generated&owned by "gen/generator.go". //template:begin testAcc

func TestAccIosxeEVPNInstance(t *testing.T) {
	if os.Getenv("C9000V") == "" {
		t.Skip("skipping test, set environment variable C9000V")
	}
	var checks []resource.TestCheckFunc
	checks = append(checks, resource.TestCheckResourceAttr("iosxe_evpn_instance.test", "evpn_instance_num", "10"))
	checks = append(checks, resource.TestCheckResourceAttr("iosxe_evpn_instance.test", "vlan_based_replication_type_ingress", "false"))
	checks = append(checks, resource.TestCheckResourceAttr("iosxe_evpn_instance.test", "vlan_based_replication_type_static", "true"))
	checks = append(checks, resource.TestCheckResourceAttr("iosxe_evpn_instance.test", "vlan_based_replication_type_p2mp", "false"))
	checks = append(checks, resource.TestCheckResourceAttr("iosxe_evpn_instance.test", "vlan_based_replication_type_mp2mp", "false"))
	checks = append(checks, resource.TestCheckResourceAttr("iosxe_evpn_instance.test", "vlan_based_encapsulation", "vxlan"))
	if os.Getenv("IOSXE1712") != "" {
		checks = append(checks, resource.TestCheckResourceAttr("iosxe_evpn_instance.test", "vlan_based_auto_route_target_legacy", "false"))
	}
	checks = append(checks, resource.TestCheckResourceAttr("iosxe_evpn_instance.test", "vlan_based_rd", "10:10"))
	if os.Getenv("IOSXE1712") != "" {
		checks = append(checks, resource.TestCheckResourceAttr("iosxe_evpn_instance.test", "vlan_based_route_target_import_legacy", "10:10"))
	}
	if os.Getenv("IOSXE1712") != "" {
		checks = append(checks, resource.TestCheckResourceAttr("iosxe_evpn_instance.test", "vlan_based_route_target_export_legacy", "10:10"))
	}
	if os.Getenv("IOSXE1715") != "" {
		checks = append(checks, resource.TestCheckResourceAttr("iosxe_evpn_instance.test", "vlan_based_route_target_exports.0.route_target", "10:10"))
	}
	if os.Getenv("IOSXE1715") != "" {
		checks = append(checks, resource.TestCheckResourceAttr("iosxe_evpn_instance.test", "vlan_based_route_target_imports.0.route_target", "10:10"))
	}
	checks = append(checks, resource.TestCheckResourceAttr("iosxe_evpn_instance.test", "vlan_based_ip_local_learning_disable", "false"))
	checks = append(checks, resource.TestCheckResourceAttr("iosxe_evpn_instance.test", "vlan_based_ip_local_learning_enable", "true"))
	checks = append(checks, resource.TestCheckResourceAttr("iosxe_evpn_instance.test", "vlan_based_default_gateway_advertise", "enable"))
	checks = append(checks, resource.TestCheckResourceAttr("iosxe_evpn_instance.test", "vlan_based_re_originate_route_type5", "true"))
	resource.Test(t, resource.TestCase{
		PreCheck:                 func() { testAccPreCheck(t) },
		ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
		Steps: []resource.TestStep{
			{
				Config: testAccIosxeEVPNInstanceConfig_all(),
				Check:  resource.ComposeTestCheckFunc(checks...),
			},
			{
				ResourceName:            "iosxe_evpn_instance.test",
				ImportState:             true,
				ImportStateVerify:       true,
				ImportStateIdFunc:       iosxeEVPNInstanceImportStateIdFunc("iosxe_evpn_instance.test"),
				ImportStateVerifyIgnore: []string{"vlan_based_auto_route_target_legacy"},
				Check:                   resource.ComposeTestCheckFunc(checks...),
			},
		},
	})
}

// End of section. //template:end testAcc

// Section below is generated&owned by "gen/generator.go". //template:begin importStateIdFunc

func iosxeEVPNInstanceImportStateIdFunc(resourceName string) resource.ImportStateIdFunc {
	return func(s *terraform.State) (string, error) {
		primary := s.RootModule().Resources[resourceName].Primary
		EvpnInstanceNum := primary.Attributes["evpn_instance_num"]

		return fmt.Sprintf("%s", EvpnInstanceNum), nil
	}
}

// End of section. //template:end importStateIdFunc

// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites
// End of section. //template:end testPrerequisites

// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigMinimal

func testAccIosxeEVPNInstanceConfig_minimum() string {
	config := `resource "iosxe_evpn_instance" "test" {` + "\n"
	config += `	evpn_instance_num = 10` + "\n"
	config += `}` + "\n"
	return config
}

// End of section. //template:end testAccConfigMinimal

// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigAll

func testAccIosxeEVPNInstanceConfig_all() string {
	config := `resource "iosxe_evpn_instance" "test" {` + "\n"
	config += `	evpn_instance_num = 10` + "\n"
	config += `	vlan_based_replication_type_ingress = false` + "\n"
	config += `	vlan_based_replication_type_static = true` + "\n"
	config += `	vlan_based_replication_type_p2mp = false` + "\n"
	config += `	vlan_based_replication_type_mp2mp = false` + "\n"
	config += `	vlan_based_encapsulation = "vxlan"` + "\n"
	if os.Getenv("IOSXE1712") != "" {
		config += `	vlan_based_auto_route_target_legacy = false` + "\n"
	}
	config += `	vlan_based_rd = "10:10"` + "\n"
	if os.Getenv("IOSXE1712") != "" {
		config += `	vlan_based_route_target_import_legacy = "10:10"` + "\n"
	}
	if os.Getenv("IOSXE1712") != "" {
		config += `	vlan_based_route_target_export_legacy = "10:10"` + "\n"
	}
	if os.Getenv("IOSXE1715") != "" {
		config += `	vlan_based_route_target_exports = [{` + "\n"
		config += `		route_target = "10:10"` + "\n"
		config += `	}]` + "\n"
	}
	if os.Getenv("IOSXE1715") != "" {
		config += `	vlan_based_route_target_imports = [{` + "\n"
		config += `		route_target = "10:10"` + "\n"
		config += `	}]` + "\n"
	}
	config += `	vlan_based_ip_local_learning_disable = false` + "\n"
	config += `	vlan_based_ip_local_learning_enable = true` + "\n"
	config += `	vlan_based_default_gateway_advertise = "enable"` + "\n"
	config += `	vlan_based_re_originate_route_type5 = true` + "\n"
	config += `}` + "\n"
	return config
}

// End of section. //template:end testAccConfigAll
