Skip to content

Commit 50c7bed

Browse files
authored
Merge branch 'main' into renovate/sdk
2 parents 31069a0 + 2f0bd8d commit 50c7bed

5 files changed

Lines changed: 47 additions & 37 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@
119119
- **Dependencies:** Bump STACKIT SDK core module from `v0.24.1` to `v0.25.0`
120120
- [v0.12.2](services/git/CHANGELOG.md#v0122)
121121
- **Dependencies:** Bump STACKIT SDK core module from `v0.25.0` to `v0.26.0`
122+
- [v0.13.0](services/git/CHANGELOG.md#v0130)
123+
- `v1betaapi`: **Improvement**: Use new `WaiterHandler` struct in the Git WaitHandler
122124
- `iaas`:
123125
- [v1.9.1](services/iaas/CHANGELOG.md#v191)
124126
- **Dependencies:** Bump STACKIT SDK core module from `v0.24.0` to `v0.24.1`

services/git/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## v0.13.0
2+
- `v1betaapi`: **Improvement**: Use new `WaiterHandler` struct in the Git WaitHandler
3+
14
## v0.12.2
25
- **Dependencies:** Bump STACKIT SDK core module from `v0.25.0` to `v0.26.0`
36

services/git/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.12.2
1+
v0.13.0

services/git/v1betaapi/wait/wait.go

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ package wait
33
import (
44
"context"
55
"errors"
6-
"fmt"
76
"net/http"
87
"time"
98

10-
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
119
"github.com/stackitcloud/stackit-sdk-go/core/wait"
1210
git "github.com/stackitcloud/stackit-sdk-go/services/git/v1betaapi"
1311
)
@@ -21,39 +19,37 @@ const (
2119
INSTANCESTATE_ERROR = "Error"
2220
)
2321

24-
func CreateGitInstanceWaitHandler(ctx context.Context, a git.DefaultAPI, projectId, instanceId string) *wait.AsyncActionHandler[git.Instance] {
25-
handler := wait.New(func() (waitFinished bool, response *git.Instance, err error) {
26-
instance, err := a.GetInstance(ctx, projectId, instanceId).Execute()
27-
if err != nil {
28-
return false, nil, err
29-
}
30-
if instance.Id == instanceId && instance.State == INSTANCESTATE_READY {
31-
return true, instance, nil
32-
}
33-
if instance.Id == instanceId && instance.State == INSTANCESTATE_ERROR {
34-
return true, instance, fmt.Errorf("create failed for Instance with id %s", instanceId)
35-
}
36-
return false, nil, nil
37-
})
22+
func CreateGitInstanceWaitHandler(ctx context.Context, client git.DefaultAPI, projectId, instanceId string) *wait.AsyncActionHandler[git.Instance] {
23+
waitConfig := wait.WaiterHelper[git.Instance, string]{
24+
FetchInstance: client.GetInstance(ctx, projectId, instanceId).Execute,
25+
GetState: func(instance *git.Instance) (string, error) {
26+
if instance == nil {
27+
return "", errors.New("empty response")
28+
}
29+
return instance.State, nil
30+
},
31+
ActiveState: []string{INSTANCESTATE_READY},
32+
ErrorState: []string{INSTANCESTATE_ERROR},
33+
}
34+
handler := wait.New(waitConfig.Wait())
3835
handler.SetTimeout(10 * time.Minute)
3936
return handler
4037
}
4138

42-
func DeleteGitInstanceWaitHandler(ctx context.Context, a git.DefaultAPI, projectId, instanceId string) *wait.AsyncActionHandler[git.Instance] {
43-
handler := wait.New(func() (waitFinished bool, response *git.Instance, err error) {
44-
_, err = a.GetInstance(ctx, projectId, instanceId).Execute()
45-
// the instances is still gettable, e.g. not deleted, when the errors is null
46-
if err == nil {
47-
return false, nil, nil
48-
}
49-
var oapiError *oapierror.GenericOpenAPIError
50-
if errors.As(err, &oapiError) {
51-
if statusCode := oapiError.StatusCode; statusCode == http.StatusNotFound {
52-
return true, nil, nil
39+
func DeleteGitInstanceWaitHandler(ctx context.Context, client git.DefaultAPI, projectId, instanceId string) *wait.AsyncActionHandler[git.Instance] {
40+
waitConfig := wait.WaiterHelper[git.Instance, string]{
41+
FetchInstance: client.GetInstance(ctx, projectId, instanceId).Execute,
42+
GetState: func(instance *git.Instance) (string, error) {
43+
if instance == nil {
44+
return "", errors.New("empty response")
5345
}
54-
}
55-
return false, nil, err
56-
})
46+
return instance.State, nil
47+
},
48+
ActiveState: []string{},
49+
ErrorState: []string{INSTANCESTATE_ERROR},
50+
DeleteHttpErrorStatusCodes: []int{http.StatusNotFound},
51+
}
52+
handler := wait.New(waitConfig.Wait())
5753
handler.SetTimeout(10 * time.Minute)
5854
return handler
5955
}

services/git/v1betaapi/wait/wait_test.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,25 @@ func TestCreateGitInstanceWaitHandler(t *testing.T) {
115115
projectId: PROJECT_ID,
116116
instanceId: INSTANCE_ID,
117117
returnInstance: true,
118+
getGitResponse: nil,
119+
},
120+
{
121+
desc: "Creation of an instance with a wrong state on the response",
122+
getFails: false,
123+
wantErr: true,
124+
wantResp: false,
125+
projectId: PROJECT_ID,
126+
instanceId: INSTANCE_ID,
127+
returnInstance: true,
118128
getGitResponse: &git.Instance{
119129
Created: time.Now(),
130+
Id: INSTANCE_ID,
120131
Name: "instance-test",
121-
State: INSTANCESTATE_ERROR,
132+
State: "wrong-state",
122133
Url: "https://testing.git.onstackit.cloud",
123134
Version: "v1.6.0",
124135
},
125136
},
126-
127137
{
128138
desc: "Creation of an instance without state on the response",
129139
getFails: false,
@@ -189,10 +199,9 @@ func TestDeleteGitInstanceWaitHandler(t *testing.T) {
189199
getFails: true,
190200
},
191201
{
192-
desc: "Instance deletion failed returning existing instance",
193-
wantErr: true,
194-
getFails: false,
195-
202+
desc: "Instance deletion failed returning existing instance",
203+
wantErr: true,
204+
getFails: false,
196205
wantReturnedInstance: false,
197206
returnInstance: true,
198207
getGitResponse: &git.Instance{

0 commit comments

Comments
 (0)