From c5e5c9efa6a3548602f8ca1b3051a34e44fa0324 Mon Sep 17 00:00:00 2001 From: 1riatsila1 Date: Wed, 6 Nov 2024 10:49:37 +0400 Subject: [PATCH] feat: live acceptance tests for wired and wireless networks --- test/live/config/config.go | 4 + test/live/resources/wired_network_test.go | 93 ++++++++++++++++++++ test/live/resources/wireless_network_test.go | 93 ++++++++++++++++++++ 3 files changed, 190 insertions(+) create mode 100644 test/live/config/config.go create mode 100644 test/live/resources/wired_network_test.go create mode 100644 test/live/resources/wireless_network_test.go diff --git a/test/live/config/config.go b/test/live/config/config.go new file mode 100644 index 00000000..648df027 --- /dev/null +++ b/test/live/config/config.go @@ -0,0 +1,4 @@ +package config + +const WiredNetworkUid = "ethernet-658f93b6ea49" +const WirelessNetworkUid = "ssid-35e69ecab0c3" diff --git a/test/live/resources/wired_network_test.go b/test/live/resources/wired_network_test.go new file mode 100644 index 00000000..4283b371 --- /dev/null +++ b/test/live/resources/wired_network_test.go @@ -0,0 +1,93 @@ +package resource_test + +import ( + "github.com/aruba-uxi/terraform-provider-configuration/test/live/config" + "github.com/aruba-uxi/terraform-provider-configuration/test/live/provider" + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/tfversion" +) + +func TestWiredNetworkResource(t *testing.T) { + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + // we required terraform 1.7.0 and above for the `removed` block + tfversion.RequireAbove(tfversion.Version1_7_0), + }, + Steps: []resource.TestStep{ + // Creating a wired_network is not allowed + { + Config: provider.ProviderConfig + ` + resource "uxi_wired_network" "my_wired_network" { + name = "name" + }`, + + ExpectError: regexp.MustCompile( + `(?s)creating a wired_network is not supported; wired_networks can only be\s*imported`, + ), + }, + // Importing a wired_network + { + Config: provider.ProviderConfig + ` + resource "uxi_wired_network" "wired_network_0" { + name = "tf-provider-acceptance-tests-ethernet-0" + } + + import { + to = uxi_wired_network.wired_network_0 + id = "` + config.WiredNetworkUid + `" + }`, + + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr( + "uxi_wired_network.wired_network_0", + "name", + "tf-provider-acceptance-tests-ethernet-0", + ), + resource.TestCheckResourceAttr( + "uxi_wired_network.wired_network_0", + "id", + config.WiredNetworkUid, + ), + ), + }, + // ImportState testing + { + ResourceName: "uxi_wired_network.wired_network_0", + ImportState: true, + ImportStateVerify: true, + }, + // Updating a wired_network is not allowed + { + Config: provider.ProviderConfig + ` + resource "uxi_wired_network" "wired_network_0" { + name = "tf-provider-acceptance-tests-ethernet-0-updated-name" + }`, + ExpectError: regexp.MustCompile( + `(?s)updating a wired_network is not supported; wired_networks can only be updated\s*through the dashboard`, + ), + }, + // Deleting a wired_network is not allowed + { + Config: provider.ProviderConfig, + ExpectError: regexp.MustCompile( + `(?s)deleting a wired_network is not supported; wired_networks can only removed\s*from state`, + ), + }, + // Remove wired_network from state + { + Config: provider.ProviderConfig + ` + removed { + from = uxi_wired_network.wired_network_0 + + lifecycle { + destroy = false + } + }`, + }, + }, + }) +} diff --git a/test/live/resources/wireless_network_test.go b/test/live/resources/wireless_network_test.go new file mode 100644 index 00000000..ff2a6689 --- /dev/null +++ b/test/live/resources/wireless_network_test.go @@ -0,0 +1,93 @@ +package resource_test + +import ( + "github.com/aruba-uxi/terraform-provider-configuration/test/live/config" + "github.com/aruba-uxi/terraform-provider-configuration/test/live/provider" + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/tfversion" +) + +func TestWirelessNetworkResource(t *testing.T) { + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + // we required terraform 1.7.0 and above for the `removed` block + tfversion.RequireAbove(tfversion.Version1_7_0), + }, + Steps: []resource.TestStep{ + // Creating a wireless_network is not allowed + { + Config: provider.ProviderConfig + ` + resource "uxi_wireless_network" "wireless_network_0" { + name = "name" + }`, + + ExpectError: regexp.MustCompile( + `(?s)creating a wireless_network is not supported; wireless_networks can only be\s*imported`, + ), + }, + // Importing a wireless_network + { + Config: provider.ProviderConfig + ` + resource "uxi_wireless_network" "wireless_network_0" { + name = "tf-provider-acceptance-tests-ssid-0" + } + + import { + to = uxi_wireless_network.wireless_network_0 + id = "` + config.WirelessNetworkUid + `" + }`, + + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr( + "uxi_wireless_network.wireless_network_0", + "name", + "tf-provider-acceptance-tests-ssid-0", + ), + resource.TestCheckResourceAttr( + "uxi_wireless_network.wireless_network_0", + "id", + config.WirelessNetworkUid, + ), + ), + }, + // ImportState testing + { + ResourceName: "uxi_wireless_network.wireless_network_0", + ImportState: true, + ImportStateVerify: true, + }, + // Updating a wireless_network is not allowed + { + Config: provider.ProviderConfig + ` + resource "uxi_wireless_network" "wireless_network_0" { + name = "tf-provider-acceptance-tests-ssid-0-updated-name" + }`, + ExpectError: regexp.MustCompile( + `(?s)updating a wireless_network is not supported; wireless_networks can only be\s*updated through the dashboard`, + ), + }, + // Deleting a wireless_network is not allowed + { + Config: provider.ProviderConfig + ``, + ExpectError: regexp.MustCompile( + `(?s)deleting a wireless_network is not supported; wireless_networks can only\s*removed from state`, + ), + }, + // Remove wireless_network from state + { + Config: provider.ProviderConfig + ` + removed { + from = uxi_wireless_network.wireless_network_0 + + lifecycle { + destroy = false + } + }`, + }, + }, + }) +}