Copilot commented on code in PR #287:
URL:
https://github.com/apache/cloudstack-terraform-provider/pull/287#discussion_r2938400197
##########
cloudstack/provider_test.go:
##########
@@ -145,3 +146,42 @@ func testAccPreCheck(t *testing.T) {
t.Fatal("CLOUDSTACK_SECRET_KEY must be set for acceptance
tests")
}
}
+
+// newTestClient creates a CloudStack client from environment variables for
use in test PreCheck functions.
+// This is needed because PreCheck functions run before the test framework
configures the provider,
+// so testAccProvider.Meta() is nil at that point.
+func newTestClient(t *testing.T) *cloudstack.CloudStackClient {
+ t.Helper()
+ testAccPreCheck(t)
+
+ cfg := Config{
+ APIURL: os.Getenv("CLOUDSTACK_API_URL"),
+ APIKey: os.Getenv("CLOUDSTACK_API_KEY"),
+ SecretKey: os.Getenv("CLOUDSTACK_SECRET_KEY"),
+ HTTPGETOnly: true,
+ Timeout: 60,
+ }
+ cs, err := cfg.NewClient()
+ if err != nil {
+ t.Fatalf("Failed to create CloudStack client: %v", err)
+ }
+ return cs
+}
+
+// getCloudStackVersion returns the CloudStack version from the API
+func getCloudStackVersion(t *testing.T) string {
+ t.Helper()
+ cs := newTestClient(t)
+
+ p := cs.Configuration.NewListCapabilitiesParams()
+ r, err := cs.Configuration.ListCapabilities(p)
+ if err != nil {
+ t.Fatalf("Failed to get CloudStack capabilities: %v", err)
+ }
+
+ if r.Capabilities != nil {
+ return r.Capabilities.Cloudstackversion
+ }
+
+ return ""
Review Comment:
`getCloudStackVersion` returns an empty string when `r.Capabilities` is nil.
Callers use the returned value to decide whether to skip tests; returning ""
will silently run tests under an unknown version (and can reintroduce the exact
failures this helper is trying to avoid). Consider failing the test
(`t.Fatalf`) when capabilities are unexpectedly nil so the outcome is explicit.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]