Skip to content

Commit 0f69472

Browse files
committed
test: fixed api precheck not being configured
1 parent 585e5c6 commit 0f69472

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

provider/client/client.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,31 @@
11
package client
22

33
import (
4+
"os"
5+
46
rediscloudApi "github.com/RedisLabs/rediscloud-go-api"
57
)
68

79
type ApiClient struct {
810
Client *rediscloudApi.Client
911
}
12+
13+
// NewClient creates a new ApiClient using environment variables for configuration.
14+
// This is useful for tests that need to create a client before the provider is configured.
15+
func NewClient() (*ApiClient, error) {
16+
var config []rediscloudApi.Option
17+
18+
url := os.Getenv("REDISCLOUD_URL")
19+
if url != "" {
20+
config = append(config, rediscloudApi.BaseURL(url))
21+
}
22+
23+
client, err := rediscloudApi.NewClient(config...)
24+
if err != nil {
25+
return nil, err
26+
}
27+
28+
return &ApiClient{
29+
Client: client,
30+
}, nil
31+
}

provider/rediscloud_essentials_subscription_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ var essentialsMarketplaceFlag = flag.Bool("essentialsMarketplace", false,
2323
func testAccPreCheckEssentialsSubscription(t *testing.T) {
2424
testAccPreCheck(t)
2525

26-
apiClient := testProvider.Meta().(*client.ApiClient)
26+
apiClient, err := client.NewClient()
27+
if err != nil {
28+
t.Fatalf("Failed to create API client: %v", err)
29+
}
30+
2731
subs, err := apiClient.Client.FixedSubscriptions.List(context.TODO())
2832
if err != nil {
2933
t.Fatalf("Failed to list essentials subscriptions: %v", err)

0 commit comments

Comments
 (0)