Skip to content

Commit b85e1d8

Browse files
committed
resource(switch_port_settings): skip acceptance test by default
1 parent d70710e commit b85e1d8

1 file changed

Lines changed: 35 additions & 2 deletions

File tree

internal/provider/resource_switch_port_settings_test.go

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,39 @@ package provider
77
import (
88
"context"
99
"fmt"
10+
"os"
1011
"testing"
1112

1213
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
1314
"github.com/hashicorp/terraform-plugin-testing/terraform"
1415
"github.com/oxidecomputer/oxide.go/oxide"
1516
)
1617

18+
// TestAccCloudResourceSwitchPortSettings_full tests whether Terraform
19+
// can create `oxide_switch_port_settings` resources.
20+
//
21+
// This test overwrites Oxide switch port settings which can cause result in
22+
// network connectivity issues if not careful. Read on to learn how to run this
23+
// test safely.
24+
//
25+
// This test assumes it's running against a simulated Omicron deployment
26+
// started by `cargo xtask omicron-dev run-all`. A simulated deployment
27+
// contains an address lot named `initial-infra` with an address of `0.0.0.0`.
28+
// The ID of this address lot is needed to run this test and is expected to
29+
// be passed to this test via the `OXIDE_TEST_ADDRESS_LOT_ID` environment
30+
// variable. You can query the address lots in your simulated deployment at
31+
// `/v1/system/networking/address-lot` to retrieve the address lot ID.
32+
//
33+
// With all that in mind, you can run this test like so.
34+
//
35+
// TEST_ACC_NAME=TestAccCloudResourceSwitchPortSettings_full OXIDE_TEST_ADDRESS_LOT_ID=<CHANGE_ME> make testacc
36+
//
37+
// A future iteration of this test can make use of the currently
38+
// non-existent `oxide_address_lot` data source to remove the need for
39+
// `OXIDE_TEST_ADDRESS_LOT_ID`. However, since the `oxide_switch_port_settings`
40+
// resource completely overwrites all switch port settings it is still
41+
// considered unsafe to run this test against anything but a simulated Omicron
42+
// deployment.
1743
func TestAccCloudResourceSwitchPortSettings_full(t *testing.T) {
1844
type resourceSwitchPortSettingsConfig struct {
1945
BlockName string
@@ -113,10 +139,11 @@ resource "oxide_switch_port_settings" "{{.BlockName}}" {
113139
]
114140
}
115141
`
142+
// See the doc comment at [TestAccCloudResourceSwitchPortSettings_full].
143+
addressLotID := os.Getenv("OXIDE_TEST_ADDRESS_LOT_ID")
116144

117145
switchPortSettingsName := newResourceName()
118146
blockName := newBlockName("switch-port-settings")
119-
addressLotID := "a7d5849e-c017-4af8-a245-fb3d48fc9912"
120147
resourceName := fmt.Sprintf("oxide_switch_port_settings.%s", blockName)
121148

122149
initialConfig, err := parsedAccConfig(
@@ -144,7 +171,13 @@ resource "oxide_switch_port_settings" "{{.BlockName}}" {
144171
}
145172

146173
resource.ParallelTest(t, resource.TestCase{
147-
PreCheck: func() { testAccPreCheck(t) },
174+
PreCheck: func() {
175+
testAccPreCheck(t)
176+
// See the doc comment at [TestAccCloudResourceSwitchPortSettings_full].
177+
if addressLotID == "" {
178+
t.Skip("Skipping test. Export OXIDE_TEST_ADDRESS_LOT_ID to run.")
179+
}
180+
},
148181
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories(),
149182
CheckDestroy: testAccSwitchPortSettingsDestroy,
150183
Steps: []resource.TestStep{

0 commit comments

Comments
 (0)