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
|
|
@ -14,22 +14,16 @@ func TestMapFieldsCreate(t *testing.T) {
|
|||
const testRegion = "region"
|
||||
tests := []struct {
|
||||
description string
|
||||
input *postgresflexalpha.CreateUserResponse
|
||||
updateRoles *postgresflexalpha.UpdateUserRequestPayload
|
||||
input *postgresflexalpha.GetUserResponse
|
||||
region string
|
||||
expected Model
|
||||
isValid bool
|
||||
}{
|
||||
{
|
||||
"default_values",
|
||||
&postgresflexalpha.CreateUserResponse{
|
||||
Id: utils.Ptr(int64(1)),
|
||||
Password: utils.Ptr(""),
|
||||
&postgresflexalpha.GetUserResponse{
|
||||
Id: utils.Ptr(int64(1)),
|
||||
},
|
||||
&postgresflexalpha.UpdateUserRequestPayload{
|
||||
Roles: &[]postgresflexalpha.UserRole{},
|
||||
},
|
||||
|
||||
testRegion,
|
||||
Model{
|
||||
Id: types.StringValue("pid,region,iid,1"),
|
||||
|
|
@ -37,11 +31,10 @@ func TestMapFieldsCreate(t *testing.T) {
|
|||
InstanceId: types.StringValue("iid"),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
Username: types.StringNull(),
|
||||
Roles: types.SetValueMust(types.StringType, []attr.Value{}),
|
||||
Password: types.StringValue(""),
|
||||
Roles: types.SetNull(types.StringType),
|
||||
Password: types.StringNull(),
|
||||
Host: types.StringNull(),
|
||||
Port: types.Int64Null(),
|
||||
Uri: types.StringNull(),
|
||||
Region: types.StringValue(testRegion),
|
||||
Status: types.StringNull(),
|
||||
ConnectionString: types.StringNull(),
|
||||
|
|
@ -50,16 +43,12 @@ func TestMapFieldsCreate(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"simple_values",
|
||||
&postgresflexalpha.CreateUserResponse{
|
||||
&postgresflexalpha.GetUserResponse{
|
||||
Id: utils.Ptr(int64(1)),
|
||||
Name: utils.Ptr("username"),
|
||||
Password: utils.Ptr("password"),
|
||||
ConnectionString: utils.Ptr("connection_string"),
|
||||
Status: utils.Ptr("status"),
|
||||
},
|
||||
&postgresflexalpha.UpdateUserRequestPayload{
|
||||
Roles: &[]postgresflexalpha.UserRole{},
|
||||
},
|
||||
testRegion,
|
||||
Model{
|
||||
Id: types.StringValue("pid,region,iid,1"),
|
||||
|
|
@ -67,11 +56,10 @@ func TestMapFieldsCreate(t *testing.T) {
|
|||
InstanceId: types.StringValue("iid"),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
Username: types.StringValue("username"),
|
||||
Roles: types.SetValueMust(types.StringType, []attr.Value{}),
|
||||
Password: types.StringValue("password"),
|
||||
Roles: types.SetNull(types.StringType),
|
||||
Password: types.StringNull(),
|
||||
Host: types.StringNull(),
|
||||
Port: types.Int64Null(),
|
||||
Uri: types.StringNull(),
|
||||
Region: types.StringValue(testRegion),
|
||||
Status: types.StringValue("status"),
|
||||
ConnectionString: types.StringValue("connection_string"),
|
||||
|
|
@ -80,16 +68,12 @@ func TestMapFieldsCreate(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"null_fields_and_int_conversions",
|
||||
&postgresflexalpha.CreateUserResponse{
|
||||
&postgresflexalpha.GetUserResponse{
|
||||
Id: utils.Ptr(int64(1)),
|
||||
Name: nil,
|
||||
Password: utils.Ptr(""),
|
||||
ConnectionString: nil,
|
||||
Status: nil,
|
||||
},
|
||||
&postgresflexalpha.UpdateUserRequestPayload{
|
||||
Roles: &[]postgresflexalpha.UserRole{},
|
||||
},
|
||||
testRegion,
|
||||
Model{
|
||||
Id: types.StringValue("pid,region,iid,1"),
|
||||
|
|
@ -97,11 +81,10 @@ func TestMapFieldsCreate(t *testing.T) {
|
|||
InstanceId: types.StringValue("iid"),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
Username: types.StringNull(),
|
||||
Roles: types.SetValueMust(types.StringType, []attr.Value{}),
|
||||
Password: types.StringValue(""),
|
||||
Roles: types.SetNull(types.StringType),
|
||||
Password: types.StringNull(),
|
||||
Host: types.StringNull(),
|
||||
Port: types.Int64Null(),
|
||||
Uri: types.StringNull(),
|
||||
Region: types.StringValue(testRegion),
|
||||
Status: types.StringNull(),
|
||||
ConnectionString: types.StringNull(),
|
||||
|
|
@ -111,35 +94,20 @@ func TestMapFieldsCreate(t *testing.T) {
|
|||
{
|
||||
"nil_response",
|
||||
nil,
|
||||
nil,
|
||||
testRegion,
|
||||
Model{},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"nil_response_2",
|
||||
&postgresflexalpha.CreateUserResponse{},
|
||||
&postgresflexalpha.UpdateUserRequestPayload{},
|
||||
&postgresflexalpha.GetUserResponse{},
|
||||
testRegion,
|
||||
Model{},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"no_resource_id",
|
||||
&postgresflexalpha.CreateUserResponse{},
|
||||
&postgresflexalpha.UpdateUserRequestPayload{},
|
||||
testRegion,
|
||||
Model{},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"no_password",
|
||||
&postgresflexalpha.CreateUserResponse{
|
||||
Id: utils.Ptr(int64(1)),
|
||||
},
|
||||
&postgresflexalpha.UpdateUserRequestPayload{
|
||||
Roles: &[]postgresflexalpha.UserRole{},
|
||||
},
|
||||
&postgresflexalpha.GetUserResponse{},
|
||||
testRegion,
|
||||
Model{},
|
||||
false,
|
||||
|
|
@ -152,11 +120,8 @@ func TestMapFieldsCreate(t *testing.T) {
|
|||
ProjectId: tt.expected.ProjectId,
|
||||
InstanceId: tt.expected.InstanceId,
|
||||
}
|
||||
var roles *[]postgresflexalpha.UserRole
|
||||
if tt.updateRoles != nil {
|
||||
roles = tt.updateRoles.Roles
|
||||
}
|
||||
err := mapFieldsCreate(tt.input, roles, state, tt.region)
|
||||
|
||||
err := mapFields(tt.input, state, tt.region)
|
||||
if !tt.isValid && err == nil {
|
||||
t.Fatalf("Should have failed")
|
||||
}
|
||||
|
|
@ -175,7 +140,6 @@ func TestMapFieldsCreate(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestMapFields(t *testing.T) {
|
||||
t.Skip("Skipping - needs refactoring")
|
||||
const testRegion = "region"
|
||||
tests := []struct {
|
||||
description string
|
||||
|
|
@ -252,7 +216,7 @@ func TestMapFields(t *testing.T) {
|
|||
InstanceId: types.StringValue("iid"),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
Username: types.StringNull(),
|
||||
Roles: types.SetValueMust(types.StringType, []attr.Value{}),
|
||||
Roles: types.SetNull(types.StringType),
|
||||
Host: types.StringNull(),
|
||||
Port: types.Int64Value(2123456789),
|
||||
Region: types.StringValue(testRegion),
|
||||
|
|
@ -424,6 +388,7 @@ func TestToUpdatePayload(t *testing.T) {
|
|||
"role_2",
|
||||
},
|
||||
&postgresflexalpha.UpdateUserRequestPayload{
|
||||
Name: utils.Ptr("username"),
|
||||
Roles: &[]postgresflexalpha.UserRole{
|
||||
"role_1",
|
||||
"role_2",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue