chore: adjust pagination for postgres database and flavor listing (#20)
* feat: implement pagination for database listing * fix: change database_id attribute type from string to int64 * refactor: rename getDatabase to getDatabaseById for clarity * fix: improve error handling for database not found scenario * feat: add validation for database_id and name attributes; implement separate functions for fetching databases by ID and name * feat: implement database client interface and update database fetching functions * refactor: rename matcher to filter for clarity and update pagination logic * feat: implement flavors retrieval with pagination and filtering support * refactor: rename flavor import for consistency and clarity * feat: add support for InstanceStatePending in wait handler logic * refactor: simplify GetFlavorsRequest and GetFlavorsRequestExecute by removing pagination parameters * refactor: improve readability of test cases by formatting function signatures and restructuring test runs * refactor: remove pagination parameters from GetFlavorsRequest in test case * refactor: simplify function signatures and improve readability in datasource and resource files * refactor: add descriptions for user-related attributes in datasource schema * refactor: enhance user resource schema with additional attributes and improve logging * refactor: delete unused file * refactor: standardize formatting and improve function naming for user resource management * refactor: remove skip from TestMapFields and update roles initialization in resource tests * fix: golangci lint issues * fix: golangci lint issues again * fix: golangci lint issues again
This commit is contained in:
parent
0150fea302
commit
979220be66
26 changed files with 3630 additions and 2759 deletions
|
|
@ -193,7 +193,7 @@ type DefaultApi interface {
|
|||
@param region The region which should be addressed
|
||||
@return ApiGetFlavorsRequestRequest
|
||||
*/
|
||||
GetFlavorsRequest(ctx context.Context, projectId string, region string, page, size *int64, sort *FlavorSort) ApiGetFlavorsRequestRequest
|
||||
GetFlavorsRequest(ctx context.Context, projectId string, region string) ApiGetFlavorsRequestRequest
|
||||
/*
|
||||
GetFlavorsRequestExecute executes the request
|
||||
|
||||
|
|
@ -203,7 +203,7 @@ type DefaultApi interface {
|
|||
@return GetFlavorsResponse
|
||||
|
||||
*/
|
||||
GetFlavorsRequestExecute(ctx context.Context, projectId string, region string, page, size *int64, sort *FlavorSort) (*GetFlavorsResponse, error)
|
||||
GetFlavorsRequestExecute(ctx context.Context, projectId string, region string) (*GetFlavorsResponse, error)
|
||||
/*
|
||||
GetInstanceRequest Get Specific Instance
|
||||
Get information about a specific available instance
|
||||
|
|
@ -2520,27 +2520,21 @@ Get all available flavors for a project.
|
|||
@param region The region which should be addressed
|
||||
@return ApiGetFlavorsRequestRequest
|
||||
*/
|
||||
func (a *APIClient) GetFlavorsRequest(ctx context.Context, projectId string, region string, page, size *int64, sort *FlavorSort) ApiGetFlavorsRequestRequest {
|
||||
func (a *APIClient) GetFlavorsRequest(ctx context.Context, projectId string, region string) ApiGetFlavorsRequestRequest {
|
||||
return GetFlavorsRequestRequest{
|
||||
apiService: a.defaultApi,
|
||||
ctx: ctx,
|
||||
projectId: projectId,
|
||||
region: region,
|
||||
page: page,
|
||||
size: size,
|
||||
sort: sort,
|
||||
}
|
||||
}
|
||||
|
||||
func (a *APIClient) GetFlavorsRequestExecute(ctx context.Context, projectId string, region string, page, size *int64, sort *FlavorSort) (*GetFlavorsResponse, error) {
|
||||
func (a *APIClient) GetFlavorsRequestExecute(ctx context.Context, projectId string, region string) (*GetFlavorsResponse, error) {
|
||||
r := GetFlavorsRequestRequest{
|
||||
apiService: a.defaultApi,
|
||||
ctx: ctx,
|
||||
projectId: projectId,
|
||||
region: region,
|
||||
page: page,
|
||||
size: size,
|
||||
sort: sort,
|
||||
}
|
||||
return r.Execute()
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -142,6 +142,8 @@ func PartialUpdateInstanceWaitHandler(
|
|||
return false, nil, nil
|
||||
case InstanceStateProgressing:
|
||||
return false, nil, nil
|
||||
case InstanceStatePending:
|
||||
return false, nil, nil
|
||||
case InstanceStateTerminating:
|
||||
return false, nil, nil
|
||||
case InstanceStateSuccess:
|
||||
|
|
@ -154,96 +156,3 @@ func PartialUpdateInstanceWaitHandler(
|
|||
handler.SetTimeout(45 * time.Minute)
|
||||
return handler
|
||||
}
|
||||
|
||||
//// DeleteInstanceWaitHandler will wait for instance deletion
|
||||
//func DeleteInstanceWaitHandler(
|
||||
// ctx context.Context,
|
||||
// a APIClientInstanceInterface,
|
||||
// projectId, region, instanceId string,
|
||||
//) *wait.AsyncActionHandler[struct{}] {
|
||||
// handler := wait.New(
|
||||
// func() (waitFinished bool, response *struct{}, err error) {
|
||||
// s, err := a.GetInstanceRequestExecute(ctx, projectId, region, instanceId)
|
||||
// if err != nil {
|
||||
// return false, nil, err
|
||||
// }
|
||||
// if s == nil || s.Id == nil || *s.Id != instanceId || s.Status == nil {
|
||||
// return false, nil, nil
|
||||
// }
|
||||
// // TODO - maybe we want to validate status if no 404 error (only unknown or terminating should be valid)
|
||||
// // switch *s.Status {
|
||||
// // default:
|
||||
// // return true, nil, fmt.Errorf("instance with id %s has unexpected status %s", instanceId, *s.Status)
|
||||
// // case InstanceStateSuccess:
|
||||
// // return false, nil, nil
|
||||
// // case InstanceStateTerminating:
|
||||
// // return false, nil, nil
|
||||
// // }
|
||||
//
|
||||
// // TODO - add tflog for ignored cases
|
||||
// oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
|
||||
// if !ok {
|
||||
// return false, nil, err
|
||||
// }
|
||||
// if oapiErr.StatusCode != 404 {
|
||||
// return false, nil, err
|
||||
// }
|
||||
// return true, nil, nil
|
||||
// },
|
||||
// )
|
||||
// handler.SetTimeout(5 * time.Minute)
|
||||
// return handler
|
||||
//}
|
||||
//
|
||||
//// TODO - remove
|
||||
//// ForceDeleteInstanceWaitHandler will wait for instance deletion
|
||||
//func ForceDeleteInstanceWaitHandler(
|
||||
// ctx context.Context,
|
||||
// a APIClientInstanceInterface,
|
||||
// projectId, region, instanceId string,
|
||||
//) *wait.AsyncActionHandler[struct{}] {
|
||||
// handler := wait.New(
|
||||
// func() (waitFinished bool, response *struct{}, err error) {
|
||||
// _, err = a.GetInstanceRequestExecute(ctx, projectId, region, instanceId)
|
||||
// if err == nil {
|
||||
// return false, nil, nil
|
||||
// }
|
||||
// oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
|
||||
// if !ok {
|
||||
// return false, nil, err
|
||||
// }
|
||||
// if oapiErr.StatusCode != 404 {
|
||||
// return false, nil, err
|
||||
// }
|
||||
// return true, nil, nil
|
||||
// },
|
||||
// )
|
||||
// handler.SetTimeout(15 * time.Minute)
|
||||
// return handler
|
||||
//}
|
||||
|
||||
// DeleteUserWaitHandler will wait for delete
|
||||
func DeleteUserWaitHandler(
|
||||
ctx context.Context,
|
||||
a APIClientUserInterface,
|
||||
projectId, region, instanceId string, userId int64,
|
||||
) *wait.AsyncActionHandler[struct{}] {
|
||||
handler := wait.New(
|
||||
func() (waitFinished bool, response *struct{}, err error) {
|
||||
_, err = a.GetUserRequestExecute(ctx, projectId, region, instanceId, userId)
|
||||
if err == nil {
|
||||
return false, nil, nil
|
||||
}
|
||||
oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
|
||||
if !ok {
|
||||
return false, nil, err
|
||||
}
|
||||
if oapiErr.StatusCode != 404 {
|
||||
return false, nil, err
|
||||
}
|
||||
return true, nil, nil
|
||||
},
|
||||
)
|
||||
handler.SetTimeout(1 * time.Minute)
|
||||
return handler
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,10 @@ type apiClientInstanceMocked struct {
|
|||
usersGetErrorStatus int
|
||||
}
|
||||
|
||||
func (a *apiClientInstanceMocked) GetInstanceRequestExecute(_ context.Context, _, _, _ string) (*postgresflex.GetInstanceResponse, error) {
|
||||
func (a *apiClientInstanceMocked) GetInstanceRequestExecute(
|
||||
_ context.Context,
|
||||
_, _, _ string,
|
||||
) (*postgresflex.GetInstanceResponse, error) {
|
||||
if a.instanceGetFails {
|
||||
return nil, &oapierror.GenericOpenAPIError{
|
||||
StatusCode: 500,
|
||||
|
|
@ -43,7 +46,10 @@ func (a *apiClientInstanceMocked) GetInstanceRequestExecute(_ context.Context, _
|
|||
}, nil
|
||||
}
|
||||
|
||||
func (a *apiClientInstanceMocked) ListUsersRequestExecute(_ context.Context, _, _, _ string) (*postgresflex.ListUserResponse, error) {
|
||||
func (a *apiClientInstanceMocked) ListUsersRequestExecute(
|
||||
_ context.Context,
|
||||
_, _, _ string,
|
||||
) (*postgresflex.ListUserResponse, error) {
|
||||
if a.usersGetErrorStatus != 0 {
|
||||
return nil, &oapierror.GenericOpenAPIError{
|
||||
StatusCode: a.usersGetErrorStatus,
|
||||
|
|
@ -59,31 +65,6 @@ func (a *apiClientInstanceMocked) ListUsersRequestExecute(_ context.Context, _,
|
|||
}, nil
|
||||
}
|
||||
|
||||
// Used for testing user operations
|
||||
type apiClientUserMocked struct {
|
||||
getFails bool
|
||||
userId int64
|
||||
isUserDeleted bool
|
||||
}
|
||||
|
||||
func (a *apiClientUserMocked) GetUserRequestExecute(_ context.Context, _, _, _ string, _ int64) (*postgresflex.GetUserResponse, error) {
|
||||
if a.getFails {
|
||||
return nil, &oapierror.GenericOpenAPIError{
|
||||
StatusCode: 500,
|
||||
}
|
||||
}
|
||||
|
||||
if a.isUserDeleted {
|
||||
return nil, &oapierror.GenericOpenAPIError{
|
||||
StatusCode: 404,
|
||||
}
|
||||
}
|
||||
|
||||
return &postgresflex.GetUserResponse{
|
||||
Id: &a.userId,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func TestCreateInstanceWaitHandler(t *testing.T) {
|
||||
tests := []struct {
|
||||
desc string
|
||||
|
|
@ -213,28 +194,30 @@ func TestCreateInstanceWaitHandler(t *testing.T) {
|
|||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.desc, func(t *testing.T) {
|
||||
instanceId := "foo-bar"
|
||||
t.Run(
|
||||
tt.desc, func(t *testing.T) {
|
||||
instanceId := "foo-bar"
|
||||
|
||||
apiClient := &apiClientInstanceMocked{
|
||||
instanceId: instanceId,
|
||||
instanceState: tt.instanceState,
|
||||
instanceNetwork: tt.instanceNetwork,
|
||||
instanceGetFails: tt.instanceGetFails,
|
||||
usersGetErrorStatus: tt.usersGetErrorStatus,
|
||||
}
|
||||
apiClient := &apiClientInstanceMocked{
|
||||
instanceId: instanceId,
|
||||
instanceState: tt.instanceState,
|
||||
instanceNetwork: tt.instanceNetwork,
|
||||
instanceGetFails: tt.instanceGetFails,
|
||||
usersGetErrorStatus: tt.usersGetErrorStatus,
|
||||
}
|
||||
|
||||
handler := CreateInstanceWaitHandler(context.Background(), apiClient, "", "", instanceId)
|
||||
handler := CreateInstanceWaitHandler(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)
|
||||
}
|
||||
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, tt.wantRes) {
|
||||
t.Fatalf("handler gotRes = %v, want %v", gotRes, tt.wantRes)
|
||||
}
|
||||
})
|
||||
if !cmp.Equal(gotRes, tt.wantRes) {
|
||||
t.Fatalf("handler gotRes = %v, want %v", gotRes, tt.wantRes)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -324,160 +307,29 @@ func TestUpdateInstanceWaitHandler(t *testing.T) {
|
|||
wantRes: nil,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.desc, func(t *testing.T) {
|
||||
instanceId := "foo-bar"
|
||||
|
||||
apiClient := &apiClientInstanceMocked{
|
||||
instanceId: instanceId,
|
||||
instanceState: tt.instanceState,
|
||||
instanceNetwork: tt.instanceNetwork,
|
||||
instanceGetFails: tt.instanceGetFails,
|
||||
}
|
||||
|
||||
handler := PartialUpdateInstanceWaitHandler(context.Background(), apiClient, "", "", instanceId)
|
||||
|
||||
gotRes, 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 !cmp.Equal(gotRes, tt.wantRes) {
|
||||
t.Fatalf("handler gotRes = %v, want %v", gotRes, tt.wantRes)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteInstanceWaitHandler(t *testing.T) {
|
||||
tests := []struct {
|
||||
desc string
|
||||
instanceGetFails bool
|
||||
instanceState string
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
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"
|
||||
|
||||
apiClient := &apiClientInstanceMocked{
|
||||
instanceGetFails: tt.instanceGetFails,
|
||||
instanceId: instanceId,
|
||||
instanceState: tt.instanceState,
|
||||
instanceNetwork: tt.instanceNetwork,
|
||||
instanceGetFails: tt.instanceGetFails,
|
||||
}
|
||||
|
||||
handler := DeleteInstanceWaitHandler(context.Background(), apiClient, "", "", instanceId)
|
||||
|
||||
_, err := handler.SetTimeout(10 * time.Millisecond).WaitWithContext(context.Background())
|
||||
handler := PartialUpdateInstanceWaitHandler(context.Background(), apiClient, "", "", instanceId)
|
||||
|
||||
gotRes, 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 !cmp.Equal(gotRes, tt.wantRes) {
|
||||
t.Fatalf("handler gotRes = %v, want %v", gotRes, tt.wantRes)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func TestForceDeleteInstanceWaitHandler(t *testing.T) {
|
||||
tests := []struct {
|
||||
desc string
|
||||
instanceGetFails bool
|
||||
instanceState string
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
desc: "delete_failed",
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateUnknown,
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
desc: "get_fails",
|
||||
instanceGetFails: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(
|
||||
tt.desc, func(t *testing.T) {
|
||||
instanceId := "foo-bar"
|
||||
|
||||
apiClient := &apiClientInstanceMocked{
|
||||
instanceGetFails: tt.instanceGetFails,
|
||||
instanceIsForceDeleted: tt.instanceState == InstanceStateFailed,
|
||||
instanceId: instanceId,
|
||||
instanceState: tt.instanceState,
|
||||
}
|
||||
|
||||
handler := ForceDeleteInstanceWaitHandler(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)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteUserWaitHandler(t *testing.T) {
|
||||
tests := []struct {
|
||||
desc string
|
||||
deleteFails bool
|
||||
getFails bool
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
desc: "delete_succeeded",
|
||||
deleteFails: false,
|
||||
getFails: false,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
desc: "delete_failed",
|
||||
deleteFails: true,
|
||||
getFails: false,
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
desc: "get_fails",
|
||||
deleteFails: false,
|
||||
getFails: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.desc, func(t *testing.T) {
|
||||
userId := int64(1001)
|
||||
|
||||
apiClient := &apiClientUserMocked{
|
||||
getFails: tt.getFails,
|
||||
userId: userId,
|
||||
isUserDeleted: !tt.deleteFails,
|
||||
}
|
||||
|
||||
handler := DeleteUserWaitHandler(context.Background(), apiClient, "", "", "", userId)
|
||||
|
||||
_, 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