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
|
|
@ -10,101 +10,34 @@ import (
|
|||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
||||
|
||||
postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v3alpha1api"
|
||||
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v3alpha1api"
|
||||
)
|
||||
|
||||
// Used for testing instance operations
|
||||
type apiClientInstanceMocked struct {
|
||||
instanceId string
|
||||
instanceState string
|
||||
instanceNetwork postgresflex.InstanceNetwork
|
||||
instanceIsForceDeleted bool
|
||||
instanceGetFails bool
|
||||
usersGetErrorStatus int
|
||||
}
|
||||
|
||||
func (a *apiClientInstanceMocked) GetInstanceRequest(
|
||||
_ context.Context,
|
||||
_, _, _ string,
|
||||
) postgresflex.ApiGetInstanceRequestRequest {
|
||||
return postgresflex.ApiGetInstanceRequestRequest{}
|
||||
}
|
||||
|
||||
func (a *apiClientInstanceMocked) GetInstanceRequestExecute(
|
||||
_ context.Context,
|
||||
_, _, _ string,
|
||||
) (*postgresflex.GetInstanceResponse, error) {
|
||||
if a.instanceGetFails {
|
||||
return nil, &oapierror.GenericOpenAPIError{
|
||||
StatusCode: 500,
|
||||
}
|
||||
}
|
||||
|
||||
if a.instanceIsForceDeleted {
|
||||
return nil, &oapierror.GenericOpenAPIError{
|
||||
StatusCode: 404,
|
||||
}
|
||||
}
|
||||
|
||||
return &postgresflex.GetInstanceResponse{
|
||||
Id: a.instanceId,
|
||||
Status: postgresflex.Status(a.instanceState),
|
||||
Network: a.instanceNetwork,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (a *apiClientInstanceMocked) ListUsersRequest(
|
||||
_ context.Context,
|
||||
_, _, _ string,
|
||||
) postgresflex.ApiListUsersRequestRequest {
|
||||
return postgresflex.ApiListUsersRequestRequest{}
|
||||
}
|
||||
|
||||
func (a *apiClientInstanceMocked) ListUsersRequestExecute(
|
||||
_ context.Context,
|
||||
_, _, _ string,
|
||||
) (*postgresflex.ListUserResponse, error) {
|
||||
if a.usersGetErrorStatus != 0 {
|
||||
return nil, &oapierror.GenericOpenAPIError{
|
||||
StatusCode: a.usersGetErrorStatus,
|
||||
}
|
||||
}
|
||||
|
||||
aux := int32(0)
|
||||
return &postgresflex.ListUserResponse{
|
||||
Pagination: postgresflex.Pagination{
|
||||
TotalRows: aux,
|
||||
},
|
||||
Users: []postgresflex.ListUser{},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func TestCreateInstanceWaitHandler(t *testing.T) {
|
||||
tests := []struct {
|
||||
desc string
|
||||
instanceGetFails bool
|
||||
instanceState string
|
||||
instanceNetwork postgresflex.InstanceNetwork
|
||||
instanceNetwork v3alpha1api.InstanceNetwork
|
||||
usersGetErrorStatus int
|
||||
wantErr bool
|
||||
wantRes *postgresflex.GetInstanceResponse
|
||||
wantRes *v3alpha1api.GetInstanceResponse
|
||||
}{
|
||||
{
|
||||
desc: "create_succeeded",
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateSuccess,
|
||||
instanceNetwork: postgresflex.InstanceNetwork{
|
||||
instanceNetwork: v3alpha1api.InstanceNetwork{
|
||||
AccessScope: nil,
|
||||
Acl: nil,
|
||||
InstanceAddress: utils.Ptr("10.0.0.1"),
|
||||
RouterAddress: utils.Ptr("10.0.0.1"),
|
||||
},
|
||||
wantErr: false,
|
||||
wantRes: &postgresflex.GetInstanceResponse{
|
||||
wantRes: &v3alpha1api.GetInstanceResponse{
|
||||
Id: "foo-bar",
|
||||
Status: InstanceStateSuccess,
|
||||
Network: postgresflex.InstanceNetwork{
|
||||
Network: v3alpha1api.InstanceNetwork{
|
||||
AccessScope: nil,
|
||||
Acl: nil,
|
||||
InstanceAddress: utils.Ptr("10.0.0.1"),
|
||||
|
|
@ -116,7 +49,7 @@ func TestCreateInstanceWaitHandler(t *testing.T) {
|
|||
desc: "create_failed",
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateFailed,
|
||||
instanceNetwork: postgresflex.InstanceNetwork{
|
||||
instanceNetwork: v3alpha1api.InstanceNetwork{
|
||||
AccessScope: nil,
|
||||
Acl: nil,
|
||||
InstanceAddress: utils.Ptr("10.0.0.1"),
|
||||
|
|
@ -129,7 +62,7 @@ func TestCreateInstanceWaitHandler(t *testing.T) {
|
|||
desc: "create_failed_2",
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateEmpty,
|
||||
instanceNetwork: postgresflex.InstanceNetwork{
|
||||
instanceNetwork: v3alpha1api.InstanceNetwork{
|
||||
AccessScope: nil,
|
||||
Acl: nil,
|
||||
InstanceAddress: utils.Ptr("10.0.0.1"),
|
||||
|
|
@ -148,7 +81,7 @@ func TestCreateInstanceWaitHandler(t *testing.T) {
|
|||
desc: "users_get_fails",
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateSuccess,
|
||||
instanceNetwork: postgresflex.InstanceNetwork{
|
||||
instanceNetwork: v3alpha1api.InstanceNetwork{
|
||||
AccessScope: nil,
|
||||
Acl: nil,
|
||||
InstanceAddress: utils.Ptr("10.0.0.1"),
|
||||
|
|
@ -162,7 +95,7 @@ func TestCreateInstanceWaitHandler(t *testing.T) {
|
|||
desc: "users_get_fails_2",
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateSuccess,
|
||||
instanceNetwork: postgresflex.InstanceNetwork{
|
||||
instanceNetwork: v3alpha1api.InstanceNetwork{
|
||||
AccessScope: nil,
|
||||
Acl: nil,
|
||||
InstanceAddress: utils.Ptr("10.0.0.1"),
|
||||
|
|
@ -170,10 +103,10 @@ func TestCreateInstanceWaitHandler(t *testing.T) {
|
|||
},
|
||||
usersGetErrorStatus: 400,
|
||||
wantErr: true,
|
||||
wantRes: &postgresflex.GetInstanceResponse{
|
||||
wantRes: &v3alpha1api.GetInstanceResponse{
|
||||
Id: "foo-bar",
|
||||
Status: InstanceStateSuccess,
|
||||
Network: postgresflex.InstanceNetwork{
|
||||
Network: v3alpha1api.InstanceNetwork{
|
||||
AccessScope: nil,
|
||||
Acl: nil,
|
||||
InstanceAddress: utils.Ptr("10.0.0.1"),
|
||||
|
|
@ -185,8 +118,8 @@ func TestCreateInstanceWaitHandler(t *testing.T) {
|
|||
desc: "fail when response has no instance address",
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateSuccess,
|
||||
instanceNetwork: postgresflex.InstanceNetwork{
|
||||
AccessScope: (*postgresflex.InstanceNetworkAccessScope)(utils.Ptr("SNA")),
|
||||
instanceNetwork: v3alpha1api.InstanceNetwork{
|
||||
AccessScope: (*v3alpha1api.InstanceNetworkAccessScope)(utils.Ptr("SNA")),
|
||||
Acl: nil,
|
||||
InstanceAddress: nil,
|
||||
RouterAddress: utils.Ptr("10.0.0.1"),
|
||||
|
|
@ -198,8 +131,8 @@ func TestCreateInstanceWaitHandler(t *testing.T) {
|
|||
desc: "timeout",
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateProgressing,
|
||||
instanceNetwork: postgresflex.InstanceNetwork{
|
||||
AccessScope: (*postgresflex.InstanceNetworkAccessScope)(utils.Ptr("SNA")),
|
||||
instanceNetwork: v3alpha1api.InstanceNetwork{
|
||||
AccessScope: (*v3alpha1api.InstanceNetworkAccessScope)(utils.Ptr("SNA")),
|
||||
Acl: nil,
|
||||
InstanceAddress: utils.Ptr("10.0.0.1"),
|
||||
RouterAddress: utils.Ptr("10.0.0.1"),
|
||||
|
|
@ -211,22 +144,44 @@ func TestCreateInstanceWaitHandler(t *testing.T) {
|
|||
for _, tt := range tests {
|
||||
t.Run(
|
||||
tt.desc, func(t *testing.T) {
|
||||
instanceId := "foo-bar"
|
||||
instanceID := "foo-bar"
|
||||
|
||||
apiClientMock := postgresflex.DefaultAPIServiceMock{
|
||||
CreateInstanceRequestExecuteMock: nil,
|
||||
GetInstanceRequestExecuteMock: nil,
|
||||
listUsersMock := func(_ v3alpha1api.ApiListUsersRequestRequest) (*v3alpha1api.ListUserResponse, error) {
|
||||
if tt.usersGetErrorStatus != 0 {
|
||||
return nil, &oapierror.GenericOpenAPIError{
|
||||
StatusCode: tt.usersGetErrorStatus,
|
||||
}
|
||||
}
|
||||
|
||||
aux := int32(0)
|
||||
return &v3alpha1api.ListUserResponse{
|
||||
Pagination: v3alpha1api.Pagination{
|
||||
TotalRows: aux,
|
||||
},
|
||||
Users: []v3alpha1api.ListUser{},
|
||||
}, nil
|
||||
}
|
||||
|
||||
//apiClient := &apiClientInstanceMocked{
|
||||
// instanceId: instanceId,
|
||||
// instanceState: tt.instanceState,
|
||||
// instanceNetwork: tt.instanceNetwork,
|
||||
// instanceGetFails: tt.instanceGetFails,
|
||||
// usersGetErrorStatus: tt.usersGetErrorStatus,
|
||||
//}
|
||||
getInstanceMock := func(_ v3alpha1api.ApiGetInstanceRequestRequest) (*v3alpha1api.GetInstanceResponse, error) {
|
||||
if tt.instanceGetFails {
|
||||
return nil, &oapierror.GenericOpenAPIError{
|
||||
StatusCode: 500,
|
||||
}
|
||||
}
|
||||
|
||||
handler := CreateInstanceWaitHandler(context.Background(), apiClientMock, "", "", instanceId)
|
||||
return &v3alpha1api.GetInstanceResponse{
|
||||
Id: instanceID,
|
||||
Status: v3alpha1api.Status(tt.instanceState),
|
||||
Network: tt.instanceNetwork,
|
||||
}, nil
|
||||
}
|
||||
|
||||
apiClientMock := v3alpha1api.DefaultAPIServiceMock{
|
||||
GetInstanceRequestExecuteMock: &getInstanceMock,
|
||||
ListUsersRequestExecuteMock: &listUsersMock,
|
||||
}
|
||||
|
||||
handler := CreateInstanceWaitHandler(context.Background(), apiClientMock, "", "", instanceID)
|
||||
|
||||
gotRes, err := handler.SetTimeout(10 * time.Millisecond).SetSleepBeforeWait(1 * time.Millisecond).WaitWithContext(context.Background())
|
||||
if (err != nil) != tt.wantErr {
|
||||
|
|
@ -246,25 +201,25 @@ func TestUpdateInstanceWaitHandler(t *testing.T) {
|
|||
desc string
|
||||
instanceGetFails bool
|
||||
instanceState string
|
||||
instanceNetwork postgresflex.InstanceNetwork
|
||||
instanceNetwork v3alpha1api.InstanceNetwork
|
||||
wantErr bool
|
||||
wantRes *postgresflex.GetInstanceResponse
|
||||
wantRes *v3alpha1api.GetInstanceResponse
|
||||
}{
|
||||
{
|
||||
desc: "update_succeeded",
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateSuccess,
|
||||
instanceNetwork: postgresflex.InstanceNetwork{
|
||||
instanceNetwork: v3alpha1api.InstanceNetwork{
|
||||
AccessScope: nil,
|
||||
Acl: nil,
|
||||
InstanceAddress: utils.Ptr("10.0.0.1"),
|
||||
RouterAddress: utils.Ptr("10.0.0.1"),
|
||||
},
|
||||
wantErr: false,
|
||||
wantRes: &postgresflex.GetInstanceResponse{
|
||||
wantRes: &v3alpha1api.GetInstanceResponse{
|
||||
Id: "foo-bar",
|
||||
Status: postgresflex.Status(InstanceStateSuccess),
|
||||
Network: postgresflex.InstanceNetwork{
|
||||
Status: v3alpha1api.Status(InstanceStateSuccess),
|
||||
Network: v3alpha1api.InstanceNetwork{
|
||||
AccessScope: nil,
|
||||
Acl: nil,
|
||||
InstanceAddress: utils.Ptr("10.0.0.1"),
|
||||
|
|
@ -276,17 +231,17 @@ func TestUpdateInstanceWaitHandler(t *testing.T) {
|
|||
desc: "update_failed",
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateFailed,
|
||||
instanceNetwork: postgresflex.InstanceNetwork{
|
||||
instanceNetwork: v3alpha1api.InstanceNetwork{
|
||||
AccessScope: nil,
|
||||
Acl: nil,
|
||||
InstanceAddress: utils.Ptr("10.0.0.1"),
|
||||
RouterAddress: utils.Ptr("10.0.0.1"),
|
||||
},
|
||||
wantErr: true,
|
||||
wantRes: &postgresflex.GetInstanceResponse{
|
||||
wantRes: &v3alpha1api.GetInstanceResponse{
|
||||
Id: "foo-bar",
|
||||
Status: postgresflex.Status(InstanceStateFailed),
|
||||
Network: postgresflex.InstanceNetwork{
|
||||
Status: v3alpha1api.Status(InstanceStateFailed),
|
||||
Network: v3alpha1api.InstanceNetwork{
|
||||
AccessScope: nil,
|
||||
Acl: nil,
|
||||
InstanceAddress: utils.Ptr("10.0.0.1"),
|
||||
|
|
@ -298,7 +253,7 @@ func TestUpdateInstanceWaitHandler(t *testing.T) {
|
|||
desc: "update_failed_2",
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateEmpty,
|
||||
instanceNetwork: postgresflex.InstanceNetwork{
|
||||
instanceNetwork: v3alpha1api.InstanceNetwork{
|
||||
AccessScope: nil,
|
||||
Acl: nil,
|
||||
InstanceAddress: utils.Ptr("10.0.0.1"),
|
||||
|
|
@ -317,7 +272,7 @@ func TestUpdateInstanceWaitHandler(t *testing.T) {
|
|||
desc: "timeout",
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateProgressing,
|
||||
instanceNetwork: postgresflex.InstanceNetwork{
|
||||
instanceNetwork: v3alpha1api.InstanceNetwork{
|
||||
AccessScope: nil,
|
||||
Acl: nil,
|
||||
InstanceAddress: utils.Ptr("10.0.0.1"),
|
||||
|
|
@ -330,16 +285,38 @@ func TestUpdateInstanceWaitHandler(t *testing.T) {
|
|||
for _, tt := range tests {
|
||||
t.Run(
|
||||
tt.desc, func(t *testing.T) {
|
||||
instanceId := "foo-bar"
|
||||
instanceID := "foo-bar"
|
||||
|
||||
apiClient := &apiClientInstanceMocked{
|
||||
instanceId: instanceId,
|
||||
instanceState: tt.instanceState,
|
||||
instanceNetwork: tt.instanceNetwork,
|
||||
instanceGetFails: tt.instanceGetFails,
|
||||
listUsersMock := func(_ v3alpha1api.ApiListUsersRequestRequest) (*v3alpha1api.ListUserResponse, error) {
|
||||
aux := int32(0)
|
||||
return &v3alpha1api.ListUserResponse{
|
||||
Pagination: v3alpha1api.Pagination{
|
||||
TotalRows: aux,
|
||||
},
|
||||
Users: []v3alpha1api.ListUser{},
|
||||
}, nil
|
||||
}
|
||||
|
||||
handler := PartialUpdateInstanceWaitHandler(context.Background(), apiClient, "", "", instanceId)
|
||||
getInstanceMock := func(_ v3alpha1api.ApiGetInstanceRequestRequest) (*v3alpha1api.GetInstanceResponse, error) {
|
||||
if tt.instanceGetFails {
|
||||
return nil, &oapierror.GenericOpenAPIError{
|
||||
StatusCode: 500,
|
||||
}
|
||||
}
|
||||
|
||||
return &v3alpha1api.GetInstanceResponse{
|
||||
Id: instanceID,
|
||||
Status: v3alpha1api.Status(tt.instanceState),
|
||||
Network: tt.instanceNetwork,
|
||||
}, nil
|
||||
}
|
||||
|
||||
apiClientMock := v3alpha1api.DefaultAPIServiceMock{
|
||||
GetInstanceRequestExecuteMock: &getInstanceMock,
|
||||
ListUsersRequestExecuteMock: &listUsersMock,
|
||||
}
|
||||
|
||||
handler := PartialUpdateInstanceWaitHandler(context.Background(), apiClientMock, "", "", instanceID)
|
||||
|
||||
gotRes, err := handler.SetTimeout(10 * time.Millisecond).WaitWithContext(context.Background())
|
||||
if (err != nil) != tt.wantErr {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue