Skip to content

Commit c0c2d5a

Browse files
committed
fix(opensearch) also migrate test code to new sdk
1 parent 41965f4 commit c0c2d5a

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

stackit/internal/services/opensearch/opensearch_acc_test.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import (
99
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
1010
"github.com/hashicorp/terraform-plugin-testing/terraform"
1111
"github.com/stackitcloud/stackit-sdk-go/core/utils"
12-
"github.com/stackitcloud/stackit-sdk-go/services/opensearch"
13-
"github.com/stackitcloud/stackit-sdk-go/services/opensearch/wait"
12+
legacyOpensearch "github.com/stackitcloud/stackit-sdk-go/services/opensearch"
13+
opensearch "github.com/stackitcloud/stackit-sdk-go/services/opensearch/v1api"
14+
"github.com/stackitcloud/stackit-sdk-go/services/opensearch/v1api/wait"
1415
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
1516
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/testutil"
1617
)
@@ -252,23 +253,23 @@ func testAccCheckOpenSearchDestroy(s *terraform.State) error {
252253
instancesToDestroy = append(instancesToDestroy, instanceId)
253254
}
254255

255-
instancesResp, err := client.ListInstances(ctx, testutil.ProjectId).Execute()
256+
instancesResp, err := client.DefaultAPI.ListInstances(ctx, testutil.ProjectId).Execute()
256257
if err != nil {
257258
return fmt.Errorf("getting instancesResp: %w", err)
258259
}
259260

260-
instances := *instancesResp.Instances
261+
instances := instancesResp.Instances
261262
for i := range instances {
262263
if instances[i].InstanceId == nil {
263264
continue
264265
}
265266
if utils.Contains(instancesToDestroy, *instances[i].InstanceId) {
266267
if !checkInstanceDeleteSuccess(&instances[i]) {
267-
err := client.DeleteInstanceExecute(ctx, testutil.ProjectId, *instances[i].InstanceId)
268+
err := client.DefaultAPI.DeleteInstance(ctx, testutil.ProjectId, *instances[i].InstanceId).Execute()
268269
if err != nil {
269270
return fmt.Errorf("destroying instance %s during CheckDestroy: %w", *instances[i].InstanceId, err)
270271
}
271-
_, err = wait.DeleteInstanceWaitHandler(ctx, client, testutil.ProjectId, *instances[i].InstanceId).WaitWithContext(ctx)
272+
_, err = wait.DeleteInstanceWaitHandler(ctx, client.DefaultAPI, testutil.ProjectId, *instances[i].InstanceId).WaitWithContext(ctx)
272273
if err != nil {
273274
return fmt.Errorf("destroying instance %s during CheckDestroy: waiting for deletion %w", *instances[i].InstanceId, err)
274275
}
@@ -279,14 +280,14 @@ func testAccCheckOpenSearchDestroy(s *terraform.State) error {
279280
}
280281

281282
func checkInstanceDeleteSuccess(i *opensearch.Instance) bool {
282-
if *i.LastOperation.Type != opensearch.INSTANCELASTOPERATIONTYPE_DELETE {
283+
if i.LastOperation.Type != string(legacyOpensearch.INSTANCELASTOPERATIONTYPE_DELETE) {
283284
return false
284285
}
285286

286-
if *i.LastOperation.Type == opensearch.INSTANCELASTOPERATIONTYPE_DELETE {
287-
if *i.LastOperation.State != opensearch.INSTANCELASTOPERATIONSTATE_SUCCEEDED {
287+
if i.LastOperation.Type == string(legacyOpensearch.INSTANCELASTOPERATIONTYPE_DELETE) {
288+
if i.LastOperation.State != string(legacyOpensearch.INSTANCELASTOPERATIONSTATE_SUCCEEDED) {
288289
return false
289-
} else if strings.Contains(*i.LastOperation.Description, "DeleteFailed") || strings.Contains(*i.LastOperation.Description, "failed") {
290+
} else if strings.Contains(i.LastOperation.Description, "DeleteFailed") || strings.Contains(i.LastOperation.Description, "failed") {
290291
return false
291292
}
292293
}

stackit/internal/services/opensearch/opensearch_test.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import (
88

99
"github.com/google/uuid"
1010
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
11-
"github.com/stackitcloud/stackit-sdk-go/core/utils"
12-
"github.com/stackitcloud/stackit-sdk-go/services/opensearch"
11+
opensearch "github.com/stackitcloud/stackit-sdk-go/services/opensearch/v1api"
1312
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/testutil"
1413
)
1514

@@ -48,14 +47,14 @@ resource "stackit_opensearch_instance" "instance" {
4847
testutil.MockResponse{
4948
Description: "offerings",
5049
ToJsonBody: &opensearch.ListOfferingsResponse{
51-
Offerings: &[]opensearch.Offering{
50+
Offerings: []opensearch.Offering{
5251
{
53-
Name: new("offering-name"),
54-
Version: utils.Ptr(version),
55-
Plans: &[]opensearch.Plan{
52+
Name: "offering-name",
53+
Version: version,
54+
Plans: []opensearch.Plan{
5655
{
57-
Id: new("plan-id"),
58-
Name: utils.Ptr(planName),
56+
Id: "plan-id",
57+
Name: planName,
5958
},
6059
},
6160
},
@@ -65,7 +64,7 @@ resource "stackit_opensearch_instance" "instance" {
6564
testutil.MockResponse{
6665
Description: "create instance",
6766
ToJsonBody: &opensearch.CreateInstanceResponse{
68-
InstanceId: new(instanceId),
67+
InstanceId: instanceId,
6968
},
7069
},
7170
testutil.MockResponse{Description: "failing waiter", StatusCode: http.StatusInternalServerError},
@@ -127,7 +126,7 @@ resource "stackit_opensearch_credential" "credential" {
127126
testutil.MockResponse{
128127
Description: "create credential",
129128
ToJsonBody: &opensearch.CredentialsResponse{
130-
Id: new(credentialId),
129+
Id: credentialId,
131130
},
132131
},
133132
testutil.MockResponse{Description: "create waiter", StatusCode: http.StatusInternalServerError},

0 commit comments

Comments
 (0)