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:
Andre_Harms 2026-01-16 16:23:10 +01:00 committed by GitHub
parent 0150fea302
commit 979220be66
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
26 changed files with 3630 additions and 2759 deletions

View file

@ -1,18 +1,11 @@
package postgresflexalpha
import (
"context"
"fmt"
postgresflex "github.com/mhenselin/terraform-provider-stackitprivatepreview/pkg/postgresflexalpha"
"github.com/stackitcloud/stackit-sdk-go/core/utils"
)
type postgresFlexClientMocked struct {
returnError bool
firstItem int
lastItem int
}
//nolint:unused // TODO: remove when used
type testFlavor struct {
Cpu int64
Description string
@ -24,12 +17,14 @@ type testFlavor struct {
StorageClasses []testFlavorStorageClass
}
//nolint:unused // TODO: remove when used
type testFlavorStorageClass struct {
Class string
MaxIoPerSec int64
MaxThroughInMb int64
}
//nolint:unused // TODO: remove when used
var responseList = []testFlavor{
{
Cpu: 1,
@ -415,6 +410,7 @@ var responseList = []testFlavor{
/* ......................................................... */
}
//nolint:unused // TODO: remove when used
func testFlavorListToResponseFlavorList(f []testFlavor) []postgresflex.ListFlavors {
result := make([]postgresflex.ListFlavors, len(f))
for i, flavor := range f {
@ -423,14 +419,17 @@ func testFlavorListToResponseFlavorList(f []testFlavor) []postgresflex.ListFlavo
return result
}
//nolint:unused // TODO: remove when used
func testFlavorToResponseFlavor(f testFlavor) postgresflex.ListFlavors {
var scList []postgresflex.FlavorStorageClassesStorageClass
for _, fl := range f.StorageClasses {
scList = append(scList, postgresflex.FlavorStorageClassesStorageClass{
Class: utils.Ptr(fl.Class),
MaxIoPerSec: utils.Ptr(fl.MaxIoPerSec),
MaxThroughInMb: utils.Ptr(fl.MaxThroughInMb),
})
scList = append(
scList, postgresflex.FlavorStorageClassesStorageClass{
Class: utils.Ptr(fl.Class),
MaxIoPerSec: utils.Ptr(fl.MaxIoPerSec),
MaxThroughInMb: utils.Ptr(fl.MaxThroughInMb),
},
)
}
return postgresflex.ListFlavors{
Cpu: utils.Ptr(f.Cpu),
@ -444,49 +443,7 @@ func testFlavorToResponseFlavor(f testFlavor) postgresflex.ListFlavors {
}
}
func (c postgresFlexClientMocked) GetFlavorsRequestExecute(
_ context.Context,
_, _ string,
page, size *int64,
_ *postgresflex.FlavorSort,
) (*postgresflex.GetFlavorsResponse, error) {
if c.returnError {
return nil, fmt.Errorf("get flavors failed")
}
var res postgresflex.GetFlavorsResponse
var resFlavors []postgresflex.ListFlavors
myList := responseList[c.firstItem : c.lastItem+1]
firstItem := *page**size - *size
if firstItem > int64(len(myList)) {
firstItem = int64(len(myList))
}
lastItem := firstItem + *size
if lastItem > int64(len(myList)) {
lastItem = int64(len(myList))
}
for _, flv := range myList[firstItem:lastItem] {
resFlavors = append(resFlavors, testFlavorToResponseFlavor(flv))
}
res.Flavors = &resFlavors
totPages := (int64(len(myList))-1) / *size + 1
res.Pagination = &postgresflex.Pagination{
Page: page,
Size: size,
Sort: utils.Ptr("id.asc"),
TotalPages: utils.Ptr(int64(totPages)),
TotalRows: utils.Ptr(int64(len(myList))),
}
return &res, nil
}
//func Test_getAllFlavors(t *testing.T) {
// func Test_getAllFlavors(t *testing.T) {
// type args struct {
// projectId string
// region string
@ -579,7 +536,7 @@ func (c postgresFlexClientMocked) GetFlavorsRequestExecute(
// }
//}
//func Test_loadFlavorId(t *testing.T) {
// func Test_loadFlavorId(t *testing.T) {
// type args struct {
// ctx context.Context
// model *Model