From 25855e3730e1daf3a247032f205b5e0815976ab8 Mon Sep 17 00:00:00 2001 From: GokceGK Date: Tue, 5 May 2026 09:28:30 +0200 Subject: [PATCH 1/2] feat (git): refactor wait handler to use helper struct relates to STACKITSDK-373 --- CHANGELOG.md | 2 + examples/iaas/go.mod | 1 - examples/iaas/go.sum | 1 - services/git/CHANGELOG.md | 3 ++ services/git/VERSION | 2 +- services/git/v1betaapi/wait/wait.go | 56 +++++++++++------------- services/git/v1betaapi/wait/wait_test.go | 21 ++++++--- 7 files changed, 46 insertions(+), 40 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 10baedbc7..0f6432a6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -109,6 +109,8 @@ - **Dependencies:** Bump STACKIT SDK core module from `v0.24.1` to `v0.25.0` - [v0.12.2](services/git/CHANGELOG.md#v0122) - **Dependencies:** Bump STACKIT SDK core module from `v0.25.0` to `v0.26.0` + - [v0.12.3](services/git/CHANGELOG.md#v0123) + - `v1betaapi`: **Improvement**: Use new `WaiterHandler` struct in the Git WaitHandler - `iaas`: - [v1.9.1](services/iaas/CHANGELOG.md#v191) - **Dependencies:** Bump STACKIT SDK core module from `v0.24.0` to `v0.24.1` diff --git a/examples/iaas/go.mod b/examples/iaas/go.mod index 64a96d597..e86710556 100644 --- a/examples/iaas/go.mod +++ b/examples/iaas/go.mod @@ -13,5 +13,4 @@ require ( require ( github.com/golang-jwt/jwt/v5 v5.3.1 // indirect github.com/google/uuid v1.6.0 // indirect - github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.22.2 // indirect ) diff --git a/examples/iaas/go.sum b/examples/iaas/go.sum index b4d42ae60..e7c16c95c 100644 --- a/examples/iaas/go.sum +++ b/examples/iaas/go.sum @@ -7,4 +7,3 @@ github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ github.com/stackitcloud/stackit-sdk-go/core v0.26.0 h1:jQEb9gkehfp6VCP6TcYk7BI10cz4l0KM2L6hqYBH2QA= github.com/stackitcloud/stackit-sdk-go/core v0.26.0/go.mod h1:WU1hhxnjXw2EV7CYa1nlEvNpMiRY6CvmIOaHuL3pOaA= github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.22.2 h1:R0H/U3PvsBolLnKqfqLuXvVlFzzGRMANiRulyafZuSU= -github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.22.2/go.mod h1:NEz3f+GV5G++BE9/MmZCsXJyCih7jtg0pZuSyG2sLEs= diff --git a/services/git/CHANGELOG.md b/services/git/CHANGELOG.md index d4a094535..41f53a6b2 100644 --- a/services/git/CHANGELOG.md +++ b/services/git/CHANGELOG.md @@ -1,3 +1,6 @@ +## v0.12.3 +- `v1betaapi`: **Improvement**: Use new `WaiterHandler` struct in the Git WaitHandler + ## v0.12.2 - **Dependencies:** Bump STACKIT SDK core module from `v0.25.0` to `v0.26.0` diff --git a/services/git/VERSION b/services/git/VERSION index c750bd7d5..1af39b364 100644 --- a/services/git/VERSION +++ b/services/git/VERSION @@ -1 +1 @@ -v0.12.2 \ No newline at end of file +v0.12.3 \ No newline at end of file diff --git a/services/git/v1betaapi/wait/wait.go b/services/git/v1betaapi/wait/wait.go index 7fc504363..14319396e 100644 --- a/services/git/v1betaapi/wait/wait.go +++ b/services/git/v1betaapi/wait/wait.go @@ -3,11 +3,8 @@ 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" git "github.com/stackitcloud/stackit-sdk-go/services/git/v1betaapi" ) @@ -21,39 +18,36 @@ const ( INSTANCESTATE_ERROR = "Error" ) -func CreateGitInstanceWaitHandler(ctx context.Context, a git.DefaultAPI, projectId, instanceId string) *wait.AsyncActionHandler[git.Instance] { - handler := wait.New(func() (waitFinished bool, response *git.Instance, err error) { - instance, err := a.GetInstance(ctx, projectId, instanceId).Execute() - if err != nil { - return false, nil, err - } - if instance.Id == instanceId && instance.State == INSTANCESTATE_READY { - return true, instance, nil - } - if instance.Id == instanceId && instance.State == INSTANCESTATE_ERROR { - return true, instance, fmt.Errorf("create failed for Instance with id %s", instanceId) - } - return false, nil, nil - }) +func CreateGitInstanceWaitHandler(ctx context.Context, client git.DefaultAPI, projectId, instanceId string) *wait.AsyncActionHandler[git.Instance] { + waitConfig := wait.WaiterHelper[git.Instance, string]{ + FetchInstance: client.GetInstance(ctx, projectId, instanceId).Execute, + GetState: func(instance *git.Instance) (string, error) { + if instance == nil { + return "", errors.New("empty response") + } + return instance.State, nil + }, + ActiveState: []string{INSTANCESTATE_READY}, + ErrorState: []string{INSTANCESTATE_ERROR}, + } + handler := wait.New(waitConfig.Wait()) handler.SetTimeout(10 * time.Minute) return handler } -func DeleteGitInstanceWaitHandler(ctx context.Context, a git.DefaultAPI, projectId, instanceId string) *wait.AsyncActionHandler[git.Instance] { - handler := wait.New(func() (waitFinished bool, response *git.Instance, err error) { - _, err = a.GetInstance(ctx, projectId, instanceId).Execute() - // the instances is still gettable, e.g. not deleted, when the errors is null - if err == nil { - return false, nil, nil - } - var oapiError *oapierror.GenericOpenAPIError - if errors.As(err, &oapiError) { - if statusCode := oapiError.StatusCode; statusCode == http.StatusNotFound { - return true, nil, nil +func DeleteGitInstanceWaitHandler(ctx context.Context, client git.DefaultAPI, projectId, instanceId string) *wait.AsyncActionHandler[git.Instance] { + waitConfig := wait.WaiterHelper[git.Instance, string]{ + FetchInstance: client.GetInstance(ctx, projectId, instanceId).Execute, + GetState: func(instance *git.Instance) (string, error) { + if instance == nil { + return "", errors.New("empty response") } - } - return false, nil, err - }) + return instance.State, nil + }, + ActiveState: []string{}, + ErrorState: []string{INSTANCESTATE_ERROR}, + } + handler := wait.New(waitConfig.Wait()) handler.SetTimeout(10 * time.Minute) return handler } diff --git a/services/git/v1betaapi/wait/wait_test.go b/services/git/v1betaapi/wait/wait_test.go index ca040ad55..ddfe4ae4d 100644 --- a/services/git/v1betaapi/wait/wait_test.go +++ b/services/git/v1betaapi/wait/wait_test.go @@ -115,15 +115,25 @@ func TestCreateGitInstanceWaitHandler(t *testing.T) { projectId: PROJECT_ID, instanceId: INSTANCE_ID, returnInstance: true, + getGitResponse: nil, + }, + { + desc: "Creation of an instance with a wrong state on the response", + getFails: false, + wantErr: true, + wantResp: false, + projectId: PROJECT_ID, + instanceId: INSTANCE_ID, + returnInstance: true, getGitResponse: &git.Instance{ Created: time.Now(), + Id: INSTANCE_ID, Name: "instance-test", - State: INSTANCESTATE_ERROR, + State: "wrong-state", Url: "https://testing.git.onstackit.cloud", Version: "v1.6.0", }, }, - { desc: "Creation of an instance without state on the response", getFails: false, @@ -189,10 +199,9 @@ func TestDeleteGitInstanceWaitHandler(t *testing.T) { getFails: true, }, { - desc: "Instance deletion failed returning existing instance", - wantErr: true, - getFails: false, - + desc: "Instance deletion failed returning existing instance", + wantErr: true, + getFails: false, wantReturnedInstance: false, returnInstance: true, getGitResponse: &git.Instance{ From 70c56f0c5b8eb3a392210842c2b07d0709814c7f Mon Sep 17 00:00:00 2001 From: GokceGK Date: Wed, 6 May 2026 16:07:35 +0200 Subject: [PATCH 2/2] feat(git): update version relates to STACKITSDK-373 --- CHANGELOG.md | 2 +- services/git/CHANGELOG.md | 2 +- services/git/VERSION | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a0d0cbb0e..e88009fe3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -109,7 +109,7 @@ - **Dependencies:** Bump STACKIT SDK core module from `v0.24.1` to `v0.25.0` - [v0.12.2](services/git/CHANGELOG.md#v0122) - **Dependencies:** Bump STACKIT SDK core module from `v0.25.0` to `v0.26.0` - - [v0.12.3](services/git/CHANGELOG.md#v0123) + - [v0.13.0](services/git/CHANGELOG.md#v0130) - `v1betaapi`: **Improvement**: Use new `WaiterHandler` struct in the Git WaitHandler - `iaas`: - [v1.9.1](services/iaas/CHANGELOG.md#v191) diff --git a/services/git/CHANGELOG.md b/services/git/CHANGELOG.md index 41f53a6b2..d9b121c0b 100644 --- a/services/git/CHANGELOG.md +++ b/services/git/CHANGELOG.md @@ -1,4 +1,4 @@ -## v0.12.3 +## v0.13.0 - `v1betaapi`: **Improvement**: Use new `WaiterHandler` struct in the Git WaitHandler ## v0.12.2 diff --git a/services/git/VERSION b/services/git/VERSION index 1af39b364..6ddc06173 100644 --- a/services/git/VERSION +++ b/services/git/VERSION @@ -1 +1 @@ -v0.12.3 \ No newline at end of file +v0.13.0 \ No newline at end of file