Skip to content

Commit

Permalink
feat: live acceptance tests for wired and wireless networks
Browse files Browse the repository at this point in the history
  • Loading branch information
1riatsila1 committed Nov 6, 2024
1 parent 3fabd7e commit c5e5c9e
Show file tree
Hide file tree
Showing 3 changed files with 190 additions and 0 deletions.
4 changes: 4 additions & 0 deletions test/live/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package config

const WiredNetworkUid = "ethernet-658f93b6ea49"
const WirelessNetworkUid = "ssid-35e69ecab0c3"
93 changes: 93 additions & 0 deletions test/live/resources/wired_network_test.go
Original file line number Diff line number Diff line change
@@ -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
}
}`,
},
},
})
}
93 changes: 93 additions & 0 deletions test/live/resources/wireless_network_test.go
Original file line number Diff line number Diff line change
@@ -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
}
}`,
},
},
})
}

0 comments on commit c5e5c9e

Please sign in to comment.