-
Notifications
You must be signed in to change notification settings - Fork 24
feat(scf): add delete scf org waiter #3498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
659e317
add delete scf org waiter
fapo85 60997c6
add delete scf org waiter
fapo85 4dd33e4
Merge branch 'stackitcloud:main' into main
fapo85 72b7db8
fix changelog
fapo85 b7646d9
Update services/scf/wait/wait.go
fapo85 bc1df09
create new release section
fapo85 47caeff
Merge remote-tracking branch 'origin/main'
fapo85 b17337e
fix statusDeletingFailed in scf waiter
fapo85 740266e
Merge branch 'main' into main
Fyusel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| v0.2.0 | ||
| v0.2.1 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| 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/scf" | ||
| ) | ||
|
|
||
| const statusDeletingFailed = "deleting_failed" | ||
|
|
||
| // Interfaces needed for tests | ||
| type APIClientInterface interface { | ||
| GetOrganizationExecute(ctx context.Context, projectId, region, orgId string) (*scf.Organization, error) | ||
| } | ||
|
|
||
| // DeleteOrganizationWaitHandler will wait for Organization deletion | ||
| func DeleteOrganizationWaitHandler(ctx context.Context, a APIClientInterface, projectId, region, orgId string) *wait.AsyncActionHandler[scf.Organization] { | ||
| handler := wait.New(func() (waitFinished bool, response *scf.Organization, err error) { | ||
| s, err := a.GetOrganizationExecute(ctx, projectId, region, orgId) | ||
fapo85 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if err != nil { | ||
| var oapiErr *oapierror.GenericOpenAPIError | ||
| ok := errors.As(err, &oapiErr) | ||
| if ok && oapiErr.StatusCode == http.StatusNotFound { | ||
| return true, s, nil | ||
| } | ||
| return false, s, err | ||
| } | ||
| if s == nil { | ||
| return false, nil, errors.New("organization is nil") | ||
| } | ||
| if *s.Status == statusDeletingFailed { | ||
| return true, nil, fmt.Errorf("delete failed for Organization with id %s", orgId) | ||
| } | ||
| return false, s, nil | ||
| }) | ||
| handler.SetTimeout(20 * time.Minute) | ||
| return handler | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| package wait | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/google/uuid" | ||
|
|
||
| "github.com/stackitcloud/stackit-sdk-go/core/oapierror" | ||
| "github.com/stackitcloud/stackit-sdk-go/services/scf" | ||
| ) | ||
|
|
||
| var PROJECT_ID = uuid.New().String() | ||
| var INSTANCE_ID = uuid.New().String() | ||
|
|
||
| const REGION = "eu01" | ||
|
|
||
| type apiClientMocked struct { | ||
| getFails bool | ||
| errorCode int | ||
| returnInstance bool | ||
| projectId string | ||
| instanceId string | ||
| getSCFResponse *scf.Organization | ||
| } | ||
|
|
||
| func (a *apiClientMocked) GetOrganizationExecute(_ context.Context, _, _, _ string) (*scf.Organization, error) { | ||
| if a.getFails { | ||
| return nil, &oapierror.GenericOpenAPIError{ | ||
| StatusCode: a.errorCode, | ||
| } | ||
| } | ||
| if !a.returnInstance { | ||
| return nil, nil | ||
| } | ||
| return a.getSCFResponse, nil | ||
| } | ||
|
|
||
| func TestDeleteOrganizationWaitHandler(t *testing.T) { | ||
| statusDeletingFailed := "deleting_failed" | ||
| tests := []struct { | ||
| desc string | ||
| wantErr bool | ||
| wantReturnedInstance bool | ||
| getFails bool | ||
| errorCode int | ||
| returnInstance bool | ||
| getOrgResponse *scf.Organization | ||
| }{ | ||
| { | ||
| desc: "Instance deletion failed with error", | ||
| wantErr: true, | ||
| getFails: true, | ||
| }, | ||
| { | ||
| desc: "Instance is not found", | ||
| wantErr: false, | ||
| getFails: true, | ||
| errorCode: 404, | ||
| }, | ||
| { | ||
| desc: "Instance is in error state", | ||
| wantErr: true, | ||
| returnInstance: true, | ||
| getOrgResponse: &scf.Organization{ | ||
| Status: &statusDeletingFailed, | ||
| }, | ||
| }, | ||
| { | ||
| desc: "Instance is nil", | ||
| wantErr: true, | ||
| returnInstance: true, | ||
| getOrgResponse: nil, | ||
| }, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.desc, func(t *testing.T) { | ||
| apiClient := &apiClientMocked{ | ||
| projectId: PROJECT_ID, | ||
| instanceId: INSTANCE_ID, | ||
| getFails: tt.getFails, | ||
| errorCode: tt.errorCode, | ||
| returnInstance: tt.returnInstance, | ||
| getSCFResponse: tt.getOrgResponse, | ||
| } | ||
|
|
||
| handler := DeleteOrganizationWaitHandler(context.Background(), apiClient, apiClient.projectId, REGION, apiClient.instanceId) | ||
| response, err := handler.SetTimeout(10 * time.Millisecond).WaitWithContext(context.Background()) | ||
|
|
||
| if (err != nil) != tt.wantErr { | ||
| t.Fatalf("handler error = %v, wantErr %v", err, tt.wantErr) | ||
| } | ||
| if (response != nil) != tt.wantReturnedInstance { | ||
| t.Fatalf("handler gotRes = %v, want nil", response) | ||
| } | ||
| }) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.