Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
- **New**: STACKIT Git module can be used to manage STACKIT Git
- [v0.2.0](services/git/CHANGELOG.md#v020-2025-04-16)
- **Features**: Add new methods to manage the STACKIT Git: `CreateInstance`, `DeleteInstance`, `GetInstance`
- [v0.3.0](services/git/CHANGELOG.md#v030-2025-04-22)
- **Features**: Add waiters to manage the STACKIT Git
- `observability`: [v0.5.0](services/observability/CHANGELOG.md#v050-2025-04-16)
- **Feature:** Add new methods `ListLogsAlertgroups`, `CreateLogsAlertgroups`, `GetLogsAlertgroup`, `UpdateLogsAlertgroup`, `DeleteLogsAlertgroup`

Expand Down
3 changes: 3 additions & 0 deletions services/git/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v0.3.0 (2025-04-22)
- **Features**: Add waiters to manage the STACKIT Git

## v0.2.0 (2025-04-16)
- **Features**: Add new methods to manage the STACKIT Git: `CreateInstance`, `DeleteInstance`, `GetInstance`

Expand Down
19 changes: 13 additions & 6 deletions services/git/wait/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ package wait

import (
"context"
"errors"
"fmt"
"net/http"
"time"

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

func DeleteGitInstanceWaitHandler(ctx context.Context, a APIClientInterface, projectId, instanceId string) *wait.AsyncActionHandler[git.Instance] {
handler := wait.New(func() (waitFinished bool, response *git.Instance, err error) {
instance, err := a.GetInstanceExecute(ctx, projectId, instanceId)
if err != nil {
return false, nil, err
_, err = a.GetInstanceExecute(ctx, projectId, instanceId)
// the instances is still gettable, e.g. not deleted, when the errors is null
if err == nil {
return false, nil, nil
}
if instance != nil {
return false, instance, nil
var oapiError *oapierror.GenericOpenAPIError
if errors.As(err, &oapiError) {
if statusCode := oapiError.StatusCode; statusCode == http.StatusNotFound {
return true, nil, nil
}
}
return true, nil, nil
return false, nil, err
})
handler.SetTimeout(10 * time.Minute)
return handler
Expand Down
17 changes: 11 additions & 6 deletions services/git/wait/wait_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

type apiClientMocked struct {
getFails bool
errorCode int
returnInstance bool
projectId string
instanceId string
Expand All @@ -24,7 +25,7 @@ type apiClientMocked struct {
func (a *apiClientMocked) GetInstanceExecute(_ context.Context, _, _ string) (*git.Instance, error) {
if a.getFails {
return nil, &oapierror.GenericOpenAPIError{
StatusCode: http.StatusInternalServerError,
StatusCode: a.errorCode,
}
}
if !a.returnInstance {
Expand Down Expand Up @@ -166,6 +167,7 @@ func TestDeleteGitInstanceWaitHandler(t *testing.T) {
wantErr bool
wantReturnedInstance bool
getFails bool
errorCode int
returnInstance bool
getGitResponse *git.Instance
}{
Expand All @@ -175,10 +177,11 @@ func TestDeleteGitInstanceWaitHandler(t *testing.T) {
getFails: true,
},
{
desc: "Instance deletion failed returning existing instance",
wantErr: true,
getFails: false,
wantReturnedInstance: true,
desc: "Instance deletion failed returning existing instance",
wantErr: true,
getFails: false,

wantReturnedInstance: false,
returnInstance: true,
getGitResponse: &git.Instance{
Created: utils.Ptr(time.Now()),
Expand All @@ -192,7 +195,8 @@ func TestDeleteGitInstanceWaitHandler(t *testing.T) {
{
desc: "Instance deletion successful",
wantErr: false,
getFails: false,
getFails: true,
errorCode: http.StatusNotFound,
wantReturnedInstance: false,
returnInstance: false,
},
Expand All @@ -203,6 +207,7 @@ func TestDeleteGitInstanceWaitHandler(t *testing.T) {

projectId: uuid.New().String(),
getFails: tt.getFails,
errorCode: tt.errorCode,
returnInstance: tt.returnInstance,
getGitResponse: tt.getGitResponse,
}
Expand Down