diff --git a/CHANGELOG.md b/CHANGELOG.md index e8ff75217..1baec815f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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` diff --git a/services/git/CHANGELOG.md b/services/git/CHANGELOG.md index c63b5fb69..c1277c33a 100644 --- a/services/git/CHANGELOG.md +++ b/services/git/CHANGELOG.md @@ -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` diff --git a/services/git/wait/wait.go b/services/git/wait/wait.go index a1adfd2ec..bef8246ed 100644 --- a/services/git/wait/wait.go +++ b/services/git/wait/wait.go @@ -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" ) @@ -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 diff --git a/services/git/wait/wait_test.go b/services/git/wait/wait_test.go index 1bb653e96..151798e5c 100644 --- a/services/git/wait/wait_test.go +++ b/services/git/wait/wait_test.go @@ -15,6 +15,7 @@ import ( type apiClientMocked struct { getFails bool + errorCode int returnInstance bool projectId string instanceId string @@ -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 { @@ -166,6 +167,7 @@ func TestDeleteGitInstanceWaitHandler(t *testing.T) { wantErr bool wantReturnedInstance bool getFails bool + errorCode int returnInstance bool getGitResponse *git.Instance }{ @@ -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()), @@ -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, }, @@ -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, }