Skip to content

Commit 3501a22

Browse files
committed
Update tests and waiter with the new region parameter
1 parent d06019b commit 3501a22

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

examples/sqlserverflex/sqlserverflex.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"fmt"
66
"os"
77

8-
"github.com/stackitcloud/stackit-sdk-go/core/config"
98
"github.com/stackitcloud/stackit-sdk-go/core/utils"
109
"github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex"
1110
"github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex/wait"
@@ -15,23 +14,24 @@ func main() {
1514
// Specify the project ID
1615
projectId := "PROJECT_ID"
1716

17+
// Specify the region
18+
region := "REGION"
19+
1820
// Specify instance configuration options
1921
flavorId := "FLAVOR_ID"
2022
version := "VERSION"
2123

2224
ctx := context.Background()
2325

2426
// Create a new API client, that uses default authentication and configuration
25-
sqlserverflexClient, err := sqlserverflex.NewAPIClient(
26-
config.WithRegion("eu01"),
27-
)
27+
sqlserverflexClient, err := sqlserverflex.NewAPIClient()
2828
if err != nil {
2929
fmt.Fprintf(os.Stderr, "Creating API client: %v\n", err)
3030
os.Exit(1)
3131
}
3232

3333
// Get the SQLServer Flex instances for your project
34-
getInstancesResp, err := sqlserverflexClient.ListInstances(ctx, projectId).Execute()
34+
getInstancesResp, err := sqlserverflexClient.ListInstances(ctx, projectId, region).Execute()
3535
if err != nil {
3636
fmt.Fprintf(os.Stderr, "Error when calling `ListInstances`: %v\n", err)
3737
os.Exit(1)
@@ -45,27 +45,27 @@ func main() {
4545
FlavorId: utils.Ptr(flavorId),
4646
Version: utils.Ptr(version),
4747
}
48-
instance, err := sqlserverflexClient.CreateInstance(ctx, projectId).CreateInstancePayload(createInstancePayload).Execute()
48+
instance, err := sqlserverflexClient.CreateInstance(ctx, projectId, region).CreateInstancePayload(createInstancePayload).Execute()
4949
if err != nil {
5050
fmt.Fprintf(os.Stderr, "Error creating SQL Server Flex instance: %v\n", err)
5151
}
5252
instanceId := *instance.Id
5353

54-
_, err = wait.CreateInstanceWaitHandler(ctx, sqlserverflexClient, projectId, instanceId).WaitWithContext(ctx)
54+
_, err = wait.CreateInstanceWaitHandler(ctx, sqlserverflexClient, projectId, instanceId, region).WaitWithContext(ctx)
5555
if err != nil {
5656
fmt.Fprintf(os.Stderr, "Error when waiting for SQL Server Flex instance creation: %v\n", err)
5757
}
5858

5959
fmt.Printf("Created SQL Server Flex instance \"%s\".\n", instanceId)
6060

6161
// Delete an instance
62-
err = sqlserverflexClient.DeleteInstance(ctx, projectId, instanceId).Execute()
62+
err = sqlserverflexClient.DeleteInstance(ctx, projectId, instanceId, region).Execute()
6363

6464
if err != nil {
6565
fmt.Fprintf(os.Stderr, "Error deleting SQL Server Flex instance: %v\n", err)
6666
}
6767

68-
_, err = wait.DeleteInstanceWaitHandler(ctx, sqlserverflexClient, projectId, instanceId).WaitWithContext(ctx)
68+
_, err = wait.DeleteInstanceWaitHandler(ctx, sqlserverflexClient, projectId, instanceId, region).WaitWithContext(ctx)
6969
if err != nil {
7070
fmt.Fprintf(os.Stderr, "Error when waiting for SQL Server Flex instance deletion: %v\n", err)
7171
}

services/sqlserverflex/wait/wait.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ const (
2121

2222
// Interface needed for tests
2323
type APIClientInstanceInterface interface {
24-
GetInstanceExecute(ctx context.Context, projectId, instanceId string) (*sqlserverflex.GetInstanceResponse, error)
24+
GetInstanceExecute(ctx context.Context, projectId, instanceId, region string) (*sqlserverflex.GetInstanceResponse, error)
2525
}
2626

2727
// CreateInstanceWaitHandler will wait for instance creation
28-
func CreateInstanceWaitHandler(ctx context.Context, a APIClientInstanceInterface, projectId, instanceId string) *wait.AsyncActionHandler[sqlserverflex.GetInstanceResponse] {
28+
func CreateInstanceWaitHandler(ctx context.Context, a APIClientInstanceInterface, projectId, instanceId, region string) *wait.AsyncActionHandler[sqlserverflex.GetInstanceResponse] {
2929
handler := wait.New(func() (waitFinished bool, response *sqlserverflex.GetInstanceResponse, err error) {
30-
s, err := a.GetInstanceExecute(ctx, projectId, instanceId)
30+
s, err := a.GetInstanceExecute(ctx, projectId, instanceId, region)
3131
if err != nil {
3232
return false, nil, err
3333
}
@@ -55,9 +55,9 @@ func CreateInstanceWaitHandler(ctx context.Context, a APIClientInstanceInterface
5555
}
5656

5757
// UpdateInstanceWaitHandler will wait for instance update
58-
func UpdateInstanceWaitHandler(ctx context.Context, a APIClientInstanceInterface, projectId, instanceId string) *wait.AsyncActionHandler[sqlserverflex.GetInstanceResponse] {
58+
func UpdateInstanceWaitHandler(ctx context.Context, a APIClientInstanceInterface, projectId, instanceId, region string) *wait.AsyncActionHandler[sqlserverflex.GetInstanceResponse] {
5959
handler := wait.New(func() (waitFinished bool, response *sqlserverflex.GetInstanceResponse, err error) {
60-
s, err := a.GetInstanceExecute(ctx, projectId, instanceId)
60+
s, err := a.GetInstanceExecute(ctx, projectId, instanceId, region)
6161
if err != nil {
6262
return false, nil, err
6363
}
@@ -85,14 +85,14 @@ func UpdateInstanceWaitHandler(ctx context.Context, a APIClientInstanceInterface
8585
}
8686

8787
// PartialUpdateInstanceWaitHandler will wait for instance update
88-
func PartialUpdateInstanceWaitHandler(ctx context.Context, a APIClientInstanceInterface, projectId, instanceId string) *wait.AsyncActionHandler[sqlserverflex.GetInstanceResponse] {
89-
return UpdateInstanceWaitHandler(ctx, a, projectId, instanceId)
88+
func PartialUpdateInstanceWaitHandler(ctx context.Context, a APIClientInstanceInterface, projectId, instanceId, region string) *wait.AsyncActionHandler[sqlserverflex.GetInstanceResponse] {
89+
return UpdateInstanceWaitHandler(ctx, a, projectId, instanceId, region)
9090
}
9191

9292
// DeleteInstanceWaitHandler will wait for instance deletion
93-
func DeleteInstanceWaitHandler(ctx context.Context, a APIClientInstanceInterface, projectId, instanceId string) *wait.AsyncActionHandler[struct{}] {
93+
func DeleteInstanceWaitHandler(ctx context.Context, a APIClientInstanceInterface, projectId, instanceId, region string) *wait.AsyncActionHandler[struct{}] {
9494
handler := wait.New(func() (waitFinished bool, response *struct{}, err error) {
95-
_, err = a.GetInstanceExecute(ctx, projectId, instanceId)
95+
_, err = a.GetInstanceExecute(ctx, projectId, instanceId, region)
9696
if err == nil {
9797
return false, nil, nil
9898
}

services/sqlserverflex/wait/wait_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type apiClientInstanceMocked struct {
1919
instanceGetFails bool
2020
}
2121

22-
func (a *apiClientInstanceMocked) GetInstanceExecute(_ context.Context, _, _ string) (*sqlserverflex.GetInstanceResponse, error) {
22+
func (a *apiClientInstanceMocked) GetInstanceExecute(_ context.Context, _, _, _ string) (*sqlserverflex.GetInstanceResponse, error) {
2323
if a.instanceGetFails {
2424
return nil, &oapierror.GenericOpenAPIError{
2525
StatusCode: 500,
@@ -103,7 +103,7 @@ func TestCreateInstanceWaitHandler(t *testing.T) {
103103
}
104104
}
105105

106-
handler := CreateInstanceWaitHandler(context.Background(), apiClient, "", instanceId)
106+
handler := CreateInstanceWaitHandler(context.Background(), apiClient, "", instanceId, "")
107107

108108
gotRes, err := handler.SetTimeout(10 * time.Millisecond).SetSleepBeforeWait(1 * time.Millisecond).WaitWithContext(context.Background())
109109

@@ -180,7 +180,7 @@ func TestUpdateInstanceWaitHandler(t *testing.T) {
180180
}
181181
}
182182

183-
handler := UpdateInstanceWaitHandler(context.Background(), apiClient, "", instanceId)
183+
handler := UpdateInstanceWaitHandler(context.Background(), apiClient, "", instanceId, "")
184184

185185
gotRes, err := handler.SetTimeout(10 * time.Millisecond).SetSleepBeforeWait(1 * time.Millisecond).WaitWithContext(context.Background())
186186

@@ -230,7 +230,7 @@ func TestDeleteInstanceWaitHandler(t *testing.T) {
230230
instanceState: tt.instanceState,
231231
}
232232

233-
handler := DeleteInstanceWaitHandler(context.Background(), apiClient, "", instanceId)
233+
handler := DeleteInstanceWaitHandler(context.Background(), apiClient, "", instanceId, "")
234234

235235
_, err := handler.SetTimeout(10 * time.Millisecond).WaitWithContext(context.Background())
236236

0 commit comments

Comments
 (0)