Skip to content
Open
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 @@ -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.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)
- **Dependencies:** Bump STACKIT SDK core module from `v0.24.0` to `v0.24.1`
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.13.0
- `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`

Expand Down
2 changes: 1 addition & 1 deletion services/git/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.12.2
v0.13.0
56 changes: 25 additions & 31 deletions services/git/v1betaapi/wait/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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
}
21 changes: 15 additions & 6 deletions services/git/v1betaapi/wait/wait_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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{
Expand Down
Loading