fix: adjust to new generator and sdk use
Some checks failed
CI Workflow / Check GoReleaser config (pull_request) Successful in 5s
CI Workflow / Test readiness for publishing provider (pull_request) Failing after 3m33s
CI Workflow / CI run tests (pull_request) Failing after 4m51s
CI Workflow / CI run build and linting (pull_request) Failing after 4m37s
CI Workflow / Code coverage report (pull_request) Has been skipped
Some checks failed
CI Workflow / Check GoReleaser config (pull_request) Successful in 5s
CI Workflow / Test readiness for publishing provider (pull_request) Failing after 3m33s
CI Workflow / CI run tests (pull_request) Failing after 4m51s
CI Workflow / CI run build and linting (pull_request) Failing after 4m37s
CI Workflow / Code coverage report (pull_request) Has been skipped
This commit is contained in:
parent
ca0f646526
commit
826bb5b36a
36 changed files with 2089 additions and 1166 deletions
306
stackit/internal/wait/sqlserverflexbeta/wait_test.go
Normal file
306
stackit/internal/wait/sqlserverflexbeta/wait_test.go
Normal file
|
|
@ -0,0 +1,306 @@
|
|||
package sqlserverflexbeta
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
||||
"github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex/v3beta1api"
|
||||
)
|
||||
|
||||
func TestCreateInstanceWaitHandler(t *testing.T) {
|
||||
instanceID := utils.Ptr("foo")
|
||||
tests := []struct {
|
||||
desc string
|
||||
instanceID string
|
||||
instanceGetFails bool
|
||||
instanceState string
|
||||
instanceNetwork v3beta1api.InstanceNetwork
|
||||
usersGetErrorStatus int
|
||||
wantErr bool
|
||||
wantRes *v3beta1api.GetInstanceResponse
|
||||
}{
|
||||
{
|
||||
desc: "create_succeeded_default_values",
|
||||
instanceID: "instance1",
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateSuccess,
|
||||
instanceNetwork: v3beta1api.InstanceNetwork{
|
||||
AccessScope: (*v3beta1api.InstanceNetworkAccessScope)(utils.Ptr("PUBLIC")),
|
||||
Acl: nil,
|
||||
InstanceAddress: utils.Ptr("10.0.0.1"),
|
||||
RouterAddress: utils.Ptr("10.0.0.2"),
|
||||
},
|
||||
wantErr: false,
|
||||
wantRes: &v3beta1api.GetInstanceResponse{
|
||||
BackupSchedule: "",
|
||||
Edition: "",
|
||||
Encryption: nil,
|
||||
FlavorId: "",
|
||||
Id: "instance1",
|
||||
IsDeletable: false,
|
||||
Name: "",
|
||||
Network: v3beta1api.InstanceNetwork{
|
||||
AccessScope: (*v3beta1api.InstanceNetworkAccessScope)(utils.Ptr("PUBLIC")),
|
||||
Acl: nil,
|
||||
InstanceAddress: utils.Ptr("10.0.0.1"),
|
||||
RouterAddress: utils.Ptr("10.0.0.2"),
|
||||
},
|
||||
Replicas: 0,
|
||||
RetentionDays: 0,
|
||||
Status: v3beta1api.Status(InstanceStateSuccess),
|
||||
Storage: v3beta1api.Storage{},
|
||||
Version: "",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "create_failed",
|
||||
instanceID: *instanceID,
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateFailed,
|
||||
wantErr: true,
|
||||
wantRes: nil,
|
||||
},
|
||||
{
|
||||
desc: "create_failed_2",
|
||||
instanceID: *instanceID,
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateEmpty,
|
||||
wantErr: true,
|
||||
wantRes: nil,
|
||||
},
|
||||
{
|
||||
desc: "instance_get_fails",
|
||||
instanceID: *instanceID,
|
||||
instanceGetFails: true,
|
||||
wantErr: true,
|
||||
wantRes: nil,
|
||||
},
|
||||
{
|
||||
desc: "timeout",
|
||||
instanceID: *instanceID,
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateProcessing,
|
||||
wantErr: true,
|
||||
wantRes: nil,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(
|
||||
tt.desc, func(t *testing.T) {
|
||||
|
||||
listRolesMock := func(_ v3beta1api.ApiListRolesRequestRequest) (*v3beta1api.ListRolesResponse, error) {
|
||||
return &v3beta1api.ListRolesResponse{
|
||||
Roles: []string{},
|
||||
}, nil
|
||||
}
|
||||
|
||||
listUsersMock := func(_ v3beta1api.ApiListUsersRequestRequest) (*v3beta1api.ListUserResponse, error) {
|
||||
aux := int64(0)
|
||||
return &v3beta1api.ListUserResponse{
|
||||
Pagination: v3beta1api.Pagination{
|
||||
TotalRows: aux,
|
||||
},
|
||||
Users: []v3beta1api.ListUser{},
|
||||
}, nil
|
||||
}
|
||||
|
||||
mockCall := func(_ v3beta1api.ApiGetInstanceRequestRequest) (*v3beta1api.GetInstanceResponse, error) {
|
||||
if tt.instanceGetFails {
|
||||
return nil, &oapierror.GenericOpenAPIError{
|
||||
StatusCode: 500,
|
||||
}
|
||||
}
|
||||
|
||||
return &v3beta1api.GetInstanceResponse{
|
||||
Id: tt.instanceID,
|
||||
Status: v3beta1api.Status(tt.instanceState),
|
||||
Network: tt.instanceNetwork,
|
||||
Storage: v3beta1api.Storage{},
|
||||
}, nil
|
||||
}
|
||||
|
||||
apiClient := v3beta1api.DefaultAPIServiceMock{
|
||||
GetInstanceRequestExecuteMock: &mockCall,
|
||||
ListUsersRequestExecuteMock: &listUsersMock,
|
||||
ListRolesRequestExecuteMock: &listRolesMock,
|
||||
}
|
||||
|
||||
handler := CreateInstanceWaitHandler(context.Background(), apiClient, "", tt.instanceID, "")
|
||||
|
||||
gotRes, err := handler.SetTimeout(10 * time.Millisecond).SetSleepBeforeWait(1 * time.Millisecond).WaitWithContext(context.Background())
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Fatalf("handler error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
if diff := cmp.Diff(tt.wantRes, gotRes); diff != "" {
|
||||
t.Errorf("model mismatch (-want +got):\n%s", diff)
|
||||
}
|
||||
}
|
||||
if !reflect.DeepEqual(gotRes, tt.wantRes) {
|
||||
t.Fatalf("handler gotRes = %v, want %v", gotRes, tt.wantRes)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateInstanceWaitHandler(t *testing.T) {
|
||||
tests := []struct {
|
||||
desc string
|
||||
instanceGetFails bool
|
||||
instanceState string
|
||||
wantErr bool
|
||||
wantResp bool
|
||||
}{
|
||||
{
|
||||
desc: "update_succeeded",
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateSuccess,
|
||||
wantErr: false,
|
||||
wantResp: true,
|
||||
},
|
||||
{
|
||||
desc: "update_failed",
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateFailed,
|
||||
wantErr: true,
|
||||
wantResp: true,
|
||||
},
|
||||
{
|
||||
desc: "update_failed_2",
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateEmpty,
|
||||
wantErr: true,
|
||||
wantResp: true,
|
||||
},
|
||||
{
|
||||
desc: "get_fails",
|
||||
instanceGetFails: true,
|
||||
wantErr: true,
|
||||
wantResp: false,
|
||||
},
|
||||
{
|
||||
desc: "timeout",
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateProcessing,
|
||||
wantErr: true,
|
||||
wantResp: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(
|
||||
tt.desc, func(t *testing.T) {
|
||||
instanceID := "foo-bar"
|
||||
|
||||
mockCall := func(_ v3beta1api.ApiGetInstanceRequestRequest) (*v3beta1api.GetInstanceResponse, error) {
|
||||
if tt.instanceGetFails {
|
||||
return nil, &oapierror.GenericOpenAPIError{
|
||||
StatusCode: 500,
|
||||
}
|
||||
}
|
||||
|
||||
return &v3beta1api.GetInstanceResponse{
|
||||
Id: instanceID,
|
||||
Status: v3beta1api.Status(tt.instanceState),
|
||||
//Network: tt.instanceNetwork,
|
||||
}, nil
|
||||
}
|
||||
|
||||
apiClient := v3beta1api.DefaultAPIServiceMock{
|
||||
GetInstanceRequestExecuteMock: &mockCall,
|
||||
}
|
||||
|
||||
var wantRes *v3beta1api.GetInstanceResponse
|
||||
if tt.wantResp {
|
||||
wantRes = &v3beta1api.GetInstanceResponse{
|
||||
Id: instanceID,
|
||||
Status: v3beta1api.Status(tt.instanceState),
|
||||
}
|
||||
}
|
||||
|
||||
handler := UpdateInstanceWaitHandler(context.Background(), apiClient, "", instanceID, "")
|
||||
|
||||
gotRes, err := handler.SetTimeout(10 * time.Millisecond).SetSleepBeforeWait(1 * time.Millisecond).WaitWithContext(context.Background())
|
||||
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Fatalf("handler error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
if !cmp.Equal(gotRes, wantRes) {
|
||||
t.Fatalf("handler gotRes = %v, want %v", gotRes, wantRes)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteInstanceWaitHandler(t *testing.T) {
|
||||
tests := []struct {
|
||||
desc string
|
||||
instanceGetFails bool
|
||||
instanceState string
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
desc: "delete_succeeded",
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateSuccess,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
desc: "delete_failed",
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateFailed,
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
desc: "get_fails",
|
||||
instanceGetFails: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(
|
||||
tt.desc, func(t *testing.T) {
|
||||
instanceID := "foo-bar"
|
||||
|
||||
mockCall := func(_ v3beta1api.ApiGetInstanceRequestRequest) (*v3beta1api.GetInstanceResponse, error) {
|
||||
if tt.instanceGetFails {
|
||||
return nil, &oapierror.GenericOpenAPIError{
|
||||
StatusCode: 500,
|
||||
}
|
||||
}
|
||||
|
||||
if tt.instanceState == InstanceStateSuccess {
|
||||
return nil, &oapierror.GenericOpenAPIError{
|
||||
StatusCode: 404,
|
||||
}
|
||||
}
|
||||
|
||||
return &v3beta1api.GetInstanceResponse{
|
||||
Id: instanceID,
|
||||
Status: v3beta1api.Status(tt.instanceState),
|
||||
//Network: tt.instanceNetwork,
|
||||
}, nil
|
||||
}
|
||||
|
||||
apiClient := v3beta1api.DefaultAPIServiceMock{
|
||||
GetInstanceRequestExecuteMock: &mockCall,
|
||||
}
|
||||
|
||||
handler := DeleteInstanceWaitHandler(context.Background(), apiClient, "", instanceID, "")
|
||||
|
||||
_, err := handler.SetTimeout(10 * time.Millisecond).WaitWithContext(context.Background())
|
||||
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Fatalf("handler error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue