|
| 1 | +// Copyright (c) 2024 Cisco Systems, Inc. and its affiliates |
| 2 | +// |
| 3 | +// This Source Code Form is subject to the terms of the Mozilla Public |
| 4 | +// License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 | +// file, You can obtain one at https://mozilla.org/MPL/2.0/. |
| 6 | +// |
| 7 | +// SPDX-License-Identifier: MPL-2.0 |
| 8 | + |
| 9 | +package provider |
| 10 | + |
| 11 | +import ( |
| 12 | + "regexp" |
| 13 | + helper "terraform-provider-ndfc/internal/provider/testing" |
| 14 | + "testing" |
| 15 | + |
| 16 | + "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
| 17 | +) |
| 18 | + |
| 19 | +func TestAccFabricVxlanEvpnResource(t *testing.T) { |
| 20 | + cfg := map[string]string{ |
| 21 | + "FabricType": "fabric_vxlan_evpn", |
| 22 | + "User": helper.GetConfig("ndfc_fabric_vxlan_evpn").NDFC.User, |
| 23 | + "Password": helper.GetConfig("ndfc_fabric_vxlan_evpn").NDFC.Password, |
| 24 | + "Host": helper.GetConfig("ndfc_fabric_vxlan_evpn").NDFC.URL, |
| 25 | + "Insecure": helper.GetConfig("ndfc_fabric_vxlan_evpn").NDFC.Insecure, |
| 26 | + } |
| 27 | + resource.Test(t, resource.TestCase{ |
| 28 | + PreCheck: func() { testAccPreCheck(t, "fabric_vxlan_evpn") }, |
| 29 | + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, |
| 30 | + Steps: []resource.TestStep{ |
| 31 | + { // Create fabric and update bfd_enable |
| 32 | + Config: func() string { |
| 33 | + return helper.GenerateFabricConfig(cfg, helper.Base_file) |
| 34 | + }(), |
| 35 | + //Check: resource.ComposeTestCheckFunc(FabricVxlanEvpnModelHelperStateCheck("ndfc_fabric_vxlan_evpn.test_resource_fabric_vxlan_evpn_1", FabricRsc, path.Empty())...), |
| 36 | + }, { // update bgp_as, it capture failure |
| 37 | + Config: func() string { |
| 38 | + return helper.GenerateFabricConfig(cfg, helper.Bgp_as_change_file) |
| 39 | + }(), |
| 40 | + //Check: resource.ComposeTestCheckFunc(FabricVxlanEvpnModelHelperStateCheck("ndfc_fabric_vxlan_evpn.test_resource_fabric_vxlan_evpn_1", FabricRsc, path.Empty())...), |
| 41 | + ExpectError: regexp.MustCompile("bgp_as cannot be updated"), |
| 42 | + }, { // modify fields like CDP_ENABLE, BFD_ENABLE and MTU with different values and deploy true |
| 43 | + Config: func() string { |
| 44 | + return helper.GenerateFabricConfig(cfg, helper.Modified_file) |
| 45 | + }(), |
| 46 | + //Check: resource.ComposeTestCheckFunc(FabricVxlanEvpnModelHelperStateCheck("ndfc_fabric_vxlan_evpn.test_resource_fabric_vxlan_evpn_1", FabricRsc, path.Empty())...), |
| 47 | + }, |
| 48 | + }, |
| 49 | + }) |
| 50 | + |
| 51 | +} |
| 52 | + |
| 53 | +func TestAccFabricVxlanMsdResource(t *testing.T) { |
| 54 | + cfg := map[string]string{ |
| 55 | + "FabricType": "fabric_vxlan_msd", |
| 56 | + "User": helper.GetConfig("ndfc_fabric_vxlan_msd").NDFC.User, |
| 57 | + "Password": helper.GetConfig("ndfc_fabric_vxlan_msd").NDFC.Password, |
| 58 | + "Host": helper.GetConfig("ndfc_fabric_vxlan_msd").NDFC.URL, |
| 59 | + "Insecure": helper.GetConfig("ndfc_fabric_vxlan_msd").NDFC.Insecure, |
| 60 | + } |
| 61 | + |
| 62 | + resource.Test(t, resource.TestCase{ |
| 63 | + PreCheck: func() { testAccPreCheck(t, "fabric_vxlan_msd") }, |
| 64 | + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, |
| 65 | + Steps: []resource.TestStep{ |
| 66 | + { // Create fabric |
| 67 | + Config: func() string { |
| 68 | + return helper.GenerateFabricConfig(cfg, helper.Base_file) |
| 69 | + }(), |
| 70 | + //Check: resource.ComposeTestCheckFunc(FabricVxlanMsdModelHelperStateCheck("ndfc_fabric_vxlan_msd.test_resource_fabric_vxlan_msd_1", FabricRsc, path.Empty())...), |
| 71 | + }, { // modify fields like ANYCAST_GW_MAC, BGW_ROUTING_TAG and DELAY_RESTORE with different values and deploy true |
| 72 | + Config: func() string { |
| 73 | + return helper.GenerateFabricConfig(cfg, helper.Modified_file) |
| 74 | + }(), |
| 75 | + //Check: resource.ComposeTestCheckFunc(FabricVxlanMsdModelHelperStateCheck("ndfc_fabric_vxlan_msd.test_resource_fabric_vxlan_msd_1", FabricRsc, path.Empty())...), |
| 76 | + }, |
| 77 | + }, |
| 78 | + }) |
| 79 | + |
| 80 | +} |
| 81 | + |
| 82 | +func TestAccFabricLanClassicResource(t *testing.T) { |
| 83 | + cfg := map[string]string{ |
| 84 | + "FabricType": "fabric_lan_classic", |
| 85 | + "User": helper.GetConfig("ndfc_fabric_lan_classic").NDFC.User, |
| 86 | + "Password": helper.GetConfig("ndfc_fabric_lan_classic").NDFC.Password, |
| 87 | + "Host": helper.GetConfig("ndfc_fabric_lan_classic").NDFC.URL, |
| 88 | + "Insecure": helper.GetConfig("ndfc_fabric_lan_classic").NDFC.Insecure, |
| 89 | + } |
| 90 | + resource.Test(t, resource.TestCase{ |
| 91 | + PreCheck: func() { testAccPreCheck(t, "fabric_lan_classic") }, |
| 92 | + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, |
| 93 | + Steps: []resource.TestStep{ |
| 94 | + { // Create fabric and update bfd_enable |
| 95 | + Config: func() string { |
| 96 | + return helper.GenerateFabricConfig(cfg, helper.Base_file) |
| 97 | + }(), |
| 98 | + //Check: resource.ComposeTestCheckFunc(FabricLanClassicModelHelperStateCheck("ndfc_fabric_lan_classic.test_resource_fabric_lan_classic_1", FabricRsc, path.Empty())...), |
| 99 | + }, { // modify fields like CDP_ENABLE, BFD_ENABLE and MTU with different values |
| 100 | + Config: func() string { |
| 101 | + return helper.GenerateFabricConfig(cfg, helper.Modified_file) |
| 102 | + }(), |
| 103 | + //Check: resource.ComposeTestCheckFunc(FabricLanClassicModelHelperStateCheck("ndfc_fabric_lan_classic.test_resource_fabric_lan_classic_1", FabricRsc, path.Empty())...), |
| 104 | + }, |
| 105 | + }, |
| 106 | + }) |
| 107 | + |
| 108 | +} |
| 109 | +func TestAccFabricMsiteExtNetResource(t *testing.T) { |
| 110 | + |
| 111 | + cfg := map[string]string{ |
| 112 | + "FabricType": "fabric_msite_ext_net", |
| 113 | + "User": helper.GetConfig("ndfc_fabric_msite_ext_net").NDFC.User, |
| 114 | + "Password": helper.GetConfig("ndfc_fabric_msite_ext_net").NDFC.Password, |
| 115 | + "Host": helper.GetConfig("ndfc_fabric_msite_ext_net").NDFC.URL, |
| 116 | + "Insecure": helper.GetConfig("ndfc_fabric_msite_ext_net").NDFC.Insecure, |
| 117 | + } |
| 118 | + resource.Test(t, resource.TestCase{ |
| 119 | + PreCheck: func() { testAccPreCheck(t, "fabric_msite_ext_net") }, |
| 120 | + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, |
| 121 | + Steps: []resource.TestStep{ |
| 122 | + { // Create fabric and update bfd_enable |
| 123 | + Config: func() string { |
| 124 | + return helper.GenerateFabricConfig(cfg, helper.Base_file) |
| 125 | + }(), |
| 126 | + //Check: resource.ComposeTestCheckFunc(FabricMsiteExtNetModelHelperStateCheck("ndfc_fabric_msite_ext_net.test_resource_fabric_msite_ext_net_1", FabricRsc, path.Empty())...), |
| 127 | + }, { // update bgp_as, it capture failure |
| 128 | + Config: func() string { |
| 129 | + return helper.GenerateFabricConfig(cfg, helper.Bgp_as_change_file) |
| 130 | + }(), |
| 131 | + //Check: resource.ComposeTestCheckFunc(FabricMsiteExtNetModelHelperStateCheck("ndfc_fabric_msite_ext_net.test_resource_fabric_msite_ext_net_1", FabricRsc, path.Empty())...), |
| 132 | + ExpectError: regexp.MustCompile("bgp_as cannot be updated"), |
| 133 | + }, { // modify fields like CDP_ENABLE, BFD_ENABLE and MTU with different values |
| 134 | + Config: func() string { |
| 135 | + return helper.GenerateFabricConfig(cfg, helper.Modified_file) |
| 136 | + }(), |
| 137 | + //Check: resource.ComposeTestCheckFunc(FabricMsiteExtNetModelHelperStateCheck("ndfc_fabric_msite_ext_net.test_resource_fabric_msite_ext_net_1", FabricRsc, path.Empty())...), |
| 138 | + }, |
| 139 | + }, |
| 140 | + }) |
| 141 | + |
| 142 | +} |
0 commit comments