Skip to content

Commit 455f74f

Browse files
Deduplicate getCloudStackVersion after merge from main
The merge from main introduced newTestClient and getCloudStackVersion(t) which conflicted with our branch's getCloudStackVersion(cs). Refactor to use main's versions: remove our duplicate, simplify requireMinimumCloudStackVersion to no longer require a client parameter, and simplify testAccPreCheckStaticRouteNexthop to drop inline client creation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 600928e commit 455f74f

1 file changed

Lines changed: 6 additions & 35 deletions

File tree

cloudstack/provider_test.go

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ package cloudstack
2121

2222
import (
2323
"context"
24-
"fmt"
2524
"os"
2625
"regexp"
2726
"strconv"
@@ -178,29 +177,14 @@ func parseCloudStackVersion(version string) int {
178177
return major*1000 + minor
179178
}
180179

181-
// getCloudStackVersion retrieves the CloudStack version from the API.
182-
// Returns the version string and any error encountered.
183-
func getCloudStackVersion(cs *cloudstack.CloudStackClient) (string, error) {
184-
p := cs.Configuration.NewListCapabilitiesParams()
185-
caps, err := cs.Configuration.ListCapabilities(p)
186-
if err != nil {
187-
return "", err
188-
}
189-
190-
if caps != nil && caps.Capabilities != nil && caps.Capabilities.Cloudstackversion != "" {
191-
return caps.Capabilities.Cloudstackversion, nil
192-
}
193-
194-
return "", fmt.Errorf("unable to determine CloudStack version")
195-
}
196-
197180
// requireMinimumCloudStackVersion checks if the CloudStack version meets the minimum requirement.
198181
// If the version is below the minimum, it skips the test with an appropriate message.
199182
// The minVersion parameter should be in the format returned by parseCloudStackVersion (e.g., 4022 for 4.22.0).
200-
func requireMinimumCloudStackVersion(t *testing.T, cs *cloudstack.CloudStackClient, minVersion int, featureName string) {
201-
version, err := getCloudStackVersion(cs)
202-
if err != nil {
203-
t.Skipf("Unable to check CloudStack version: %v", err)
183+
func requireMinimumCloudStackVersion(t *testing.T, minVersion int, featureName string) {
184+
t.Helper()
185+
version := getCloudStackVersion(t)
186+
if version == "" {
187+
t.Skipf("Unable to determine CloudStack version, skipping %s test", featureName)
204188
return
205189
}
206190

@@ -218,21 +202,8 @@ func requireMinimumCloudStackVersion(t *testing.T, cs *cloudstack.CloudStackClie
218202
func testAccPreCheckStaticRouteNexthop(t *testing.T) {
219203
testAccPreCheck(t)
220204

221-
// Create a CloudStack client to check version
222-
config := Config{
223-
APIURL: os.Getenv("CLOUDSTACK_API_URL"),
224-
APIKey: os.Getenv("CLOUDSTACK_API_KEY"),
225-
SecretKey: os.Getenv("CLOUDSTACK_SECRET_KEY"),
226-
Timeout: 900,
227-
}
228-
229-
cs, err := config.NewClient()
230-
if err != nil {
231-
t.Fatalf("Failed to create CloudStack client: %v", err)
232-
}
233-
234205
const minVersionNum = 4022 // 4.22.0
235-
requireMinimumCloudStackVersion(t, cs, minVersionNum, "Static route nexthop parameter")
206+
requireMinimumCloudStackVersion(t, minVersionNum, "Static route nexthop parameter")
236207
}
237208

238209
// newTestClient creates a CloudStack client from environment variables for use in test PreCheck functions.

0 commit comments

Comments
 (0)