Skip to content

Commit 62152a3

Browse files
authored
Improve waiters test and adding changelog to the git service
Improve waiters test and adding changelog to the git service
2 parents 967675d + 8da96e0 commit 62152a3

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
- **New**: STACKIT Git module can be used to manage STACKIT Git
99
- [v0.2.0](services/git/CHANGELOG.md#v020-2025-04-16)
1010
- **Features**: Add new methods to manage the STACKIT Git: `CreateInstance`, `DeleteInstance`, `GetInstance`
11+
- [v0.3.0](services/git/CHANGELOG.md#v030-2025-04-22)
12+
- **Features**: Add waiters to manage the STACKIT Git
1113
- `observability`: [v0.5.0](services/observability/CHANGELOG.md#v050-2025-04-16)
1214
- **Feature:** Add new methods `ListLogsAlertgroups`, `CreateLogsAlertgroups`, `GetLogsAlertgroup`, `UpdateLogsAlertgroup`, `DeleteLogsAlertgroup`
1315

services/git/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## v0.3.0 (2025-04-22)
2+
- **Features**: Add waiters to manage the STACKIT Git
3+
14
## v0.2.0 (2025-04-16)
25
- **Features**: Add new methods to manage the STACKIT Git: `CreateInstance`, `DeleteInstance`, `GetInstance`
36

services/git/wait/wait.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ package wait
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
7+
"net/http"
68
"time"
79

10+
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
811
"github.com/stackitcloud/stackit-sdk-go/core/wait"
912
"github.com/stackitcloud/stackit-sdk-go/services/git"
1013
)
@@ -43,14 +46,18 @@ func CreateGitInstanceWaitHandler(ctx context.Context, a APIClientInterface, pro
4346

4447
func DeleteGitInstanceWaitHandler(ctx context.Context, a APIClientInterface, projectId, instanceId string) *wait.AsyncActionHandler[git.Instance] {
4548
handler := wait.New(func() (waitFinished bool, response *git.Instance, err error) {
46-
instance, err := a.GetInstanceExecute(ctx, projectId, instanceId)
47-
if err != nil {
48-
return false, nil, err
49+
_, err = a.GetInstanceExecute(ctx, projectId, instanceId)
50+
// the instances is still gettable, e.g. not deleted, when the errors is null
51+
if err == nil {
52+
return false, nil, nil
4953
}
50-
if instance != nil {
51-
return false, instance, nil
54+
var oapiError *oapierror.GenericOpenAPIError
55+
if errors.As(err, &oapiError) {
56+
if statusCode := oapiError.StatusCode; statusCode == http.StatusNotFound {
57+
return true, nil, nil
58+
}
5259
}
53-
return true, nil, nil
60+
return false, nil, err
5461
})
5562
handler.SetTimeout(10 * time.Minute)
5663
return handler

services/git/wait/wait_test.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515

1616
type apiClientMocked struct {
1717
getFails bool
18+
errorCode int
1819
returnInstance bool
1920
projectId string
2021
instanceId string
@@ -24,7 +25,7 @@ type apiClientMocked struct {
2425
func (a *apiClientMocked) GetInstanceExecute(_ context.Context, _, _ string) (*git.Instance, error) {
2526
if a.getFails {
2627
return nil, &oapierror.GenericOpenAPIError{
27-
StatusCode: http.StatusInternalServerError,
28+
StatusCode: a.errorCode,
2829
}
2930
}
3031
if !a.returnInstance {
@@ -166,6 +167,7 @@ func TestDeleteGitInstanceWaitHandler(t *testing.T) {
166167
wantErr bool
167168
wantReturnedInstance bool
168169
getFails bool
170+
errorCode int
169171
returnInstance bool
170172
getGitResponse *git.Instance
171173
}{
@@ -175,10 +177,11 @@ func TestDeleteGitInstanceWaitHandler(t *testing.T) {
175177
getFails: true,
176178
},
177179
{
178-
desc: "Instance deletion failed returning existing instance",
179-
wantErr: true,
180-
getFails: false,
181-
wantReturnedInstance: true,
180+
desc: "Instance deletion failed returning existing instance",
181+
wantErr: true,
182+
getFails: false,
183+
184+
wantReturnedInstance: false,
182185
returnInstance: true,
183186
getGitResponse: &git.Instance{
184187
Created: utils.Ptr(time.Now()),
@@ -192,7 +195,8 @@ func TestDeleteGitInstanceWaitHandler(t *testing.T) {
192195
{
193196
desc: "Instance deletion successful",
194197
wantErr: false,
195-
getFails: false,
198+
getFails: true,
199+
errorCode: http.StatusNotFound,
196200
wantReturnedInstance: false,
197201
returnInstance: false,
198202
},
@@ -203,6 +207,7 @@ func TestDeleteGitInstanceWaitHandler(t *testing.T) {
203207

204208
projectId: uuid.New().String(),
205209
getFails: tt.getFails,
210+
errorCode: tt.errorCode,
206211
returnInstance: tt.returnInstance,
207212
getGitResponse: tt.getGitResponse,
208213
}

0 commit comments

Comments
 (0)