Skip to content

Commit f207255

Browse files
Make IPv6 acceptance tests conditionally skip based on environment
IPv6 acceptance tests are now conditionally skipped instead of being unconditionally skipped. The tests will: 1. Skip on localhost/127.0.0.1 (assumed to be simulator) by default 2. Run on other API URLs (assumed to be real CloudStack) 3. Can be force-enabled via CLOUDSTACK_ENABLE_IPV6_TESTS=true env var This allows the tests to run on real CloudStack environments with IPv6 support while still skipping on the simulator where IPv6 is not supported for isolated networks. Added testAccPreCheckIPv6Support() helper function that checks: - Standard testAccPreCheck() requirements - CLOUDSTACK_ENABLE_IPV6_TESTS environment variable for override - API URL to detect simulator (localhost/127.0.0.1)
1 parent 1645a83 commit f207255

1 file changed

Lines changed: 26 additions & 8 deletions

File tree

cloudstack/resource_cloudstack_network_test.go

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,20 @@
1717
// under the License.
1818
//
1919

20-
// NOTE: IPv6 acceptance tests (TestAccCloudStackNetwork_ipv6*) are currently
20+
// NOTE: IPv6 acceptance tests (TestAccCloudStackNetwork_ipv6*) are conditionally
2121
// skipped when running against the CloudStack simulator because the simulator
2222
// only supports IPv6 with advanced shared network offerings. These tests will
23-
// work correctly against a real CloudStack environment with proper IPv6 support.
23+
// run on real CloudStack environments with proper IPv6 support. Set the environment
24+
// variable CLOUDSTACK_ENABLE_IPV6_TESTS=true to force-enable IPv6 tests.
2425
// Unit tests for the IPv6 CIDR parsing logic are available in
2526
// resource_cloudstack_network_unit_test.go and do not require a CloudStack instance.
2627

2728
package cloudstack
2829

2930
import (
3031
"fmt"
32+
"os"
33+
"strings"
3134
"testing"
3235

3336
"github.com/apache/cloudstack-go/v2/cloudstack"
@@ -172,12 +175,29 @@ func TestAccCloudStackNetwork_importProject(t *testing.T) {
172175
})
173176
}
174177

178+
// testAccPreCheckIPv6Support checks if IPv6 tests should run.
179+
// IPv6 tests are skipped on the CloudStack simulator unless explicitly enabled
180+
// via the CLOUDSTACK_ENABLE_IPV6_TESTS environment variable.
181+
func testAccPreCheckIPv6Support(t *testing.T) {
182+
testAccPreCheck(t)
183+
184+
// Allow explicit override to enable IPv6 tests
185+
if os.Getenv("CLOUDSTACK_ENABLE_IPV6_TESTS") == "true" {
186+
return
187+
}
188+
189+
// Try to detect if we're running on the simulator by checking the API URL
190+
apiURL := os.Getenv("CLOUDSTACK_API_URL")
191+
if strings.Contains(apiURL, "localhost") || strings.Contains(apiURL, "127.0.0.1") {
192+
t.Skip("Skipping IPv6 test: CloudStack simulator does not support IPv6 for isolated networks. Set CLOUDSTACK_ENABLE_IPV6_TESTS=true to force-enable.")
193+
}
194+
}
195+
175196
func TestAccCloudStackNetwork_ipv6(t *testing.T) {
176-
t.Skip("Skipping IPv6 test: CloudStack simulator only supports IPv6 with advanced shared networks")
177197
var network cloudstack.Network
178198

179199
resource.Test(t, resource.TestCase{
180-
PreCheck: func() { testAccPreCheck(t) },
200+
PreCheck: func() { testAccPreCheckIPv6Support(t) },
181201
Providers: testAccProviders,
182202
CheckDestroy: testAccCheckCloudStackNetworkDestroy,
183203
Steps: []resource.TestStep{
@@ -196,11 +216,10 @@ func TestAccCloudStackNetwork_ipv6(t *testing.T) {
196216
}
197217

198218
func TestAccCloudStackNetwork_ipv6_vpc(t *testing.T) {
199-
t.Skip("Skipping IPv6 test: CloudStack simulator only supports IPv6 with advanced shared networks")
200219
var network cloudstack.Network
201220

202221
resource.Test(t, resource.TestCase{
203-
PreCheck: func() { testAccPreCheck(t) },
222+
PreCheck: func() { testAccPreCheckIPv6Support(t) },
204223
Providers: testAccProviders,
205224
CheckDestroy: testAccCheckCloudStackNetworkDestroy,
206225
Steps: []resource.TestStep{
@@ -218,11 +237,10 @@ func TestAccCloudStackNetwork_ipv6_vpc(t *testing.T) {
218237
}
219238

220239
func TestAccCloudStackNetwork_ipv6_custom_gateway(t *testing.T) {
221-
t.Skip("Skipping IPv6 test: CloudStack simulator only supports IPv6 with advanced shared networks")
222240
var network cloudstack.Network
223241

224242
resource.Test(t, resource.TestCase{
225-
PreCheck: func() { testAccPreCheck(t) },
243+
PreCheck: func() { testAccPreCheckIPv6Support(t) },
226244
Providers: testAccProviders,
227245
CheckDestroy: testAccCheckCloudStackNetworkDestroy,
228246
Steps: []resource.TestStep{

0 commit comments

Comments
 (0)