Compare commits

..

6 commits

Author SHA1 Message Date
Marcel S. Henselin
1a2d04f044 chore: refactor tests
Some checks failed
CI Workflow / Check GoReleaser config (pull_request) Successful in 7s
CI Workflow / CI (pull_request) Failing after 9m39s
CI Workflow / Code coverage report (pull_request) Has been skipped
CI Workflow / Test readiness for publishing provider (pull_request) Successful in 30m48s
2026-02-10 16:50:55 +01:00
Marcel S. Henselin
3505fb56f0 chore: revise tests 2026-02-10 14:42:55 +01:00
Marcel S. Henselin
55eeed71f0 fix: fix lintings 2026-02-10 14:42:55 +01:00
Marcel S. Henselin
cdbfc56fd0 fix: fix lintings 2026-02-10 14:42:55 +01:00
Marcel S. Henselin
8d5c0560f1 fix: move tests 2026-02-10 14:42:55 +01:00
Marcel S. Henselin
071f3b9249 fix: fix tests 2026-02-10 14:42:55 +01:00
6 changed files with 72 additions and 111 deletions

View file

@ -55,22 +55,6 @@ func mapGetInstanceResponseToModel(
)
}
isConnectionInfoIncomplete := resp.ConnectionInfo == nil ||
resp.ConnectionInfo.Host == nil || *resp.ConnectionInfo.Host == "" ||
resp.ConnectionInfo.Port == nil || *resp.ConnectionInfo.Port == 0
if isConnectionInfoIncomplete {
m.ConnectionInfo = postgresflexalpharesource.NewConnectionInfoValueNull()
} else {
m.ConnectionInfo = postgresflexalpharesource.NewConnectionInfoValueMust(
postgresflexalpharesource.ConnectionInfoValue{}.AttributeTypes(ctx),
map[string]attr.Value{
"host": types.StringPointerValue(resp.ConnectionInfo.Host),
"port": types.Int64PointerValue(resp.ConnectionInfo.Port),
},
)
}
m.ConnectionInfo.Host = types.StringValue("")
if host, ok := resp.ConnectionInfo.GetHostOk(); ok {
m.ConnectionInfo.Host = types.StringValue(host)
@ -154,8 +138,8 @@ func mapGetDataInstanceResponseToModel(
) error {
m.BackupSchedule = types.StringValue(resp.GetBackupSchedule())
handleEncryption(m, resp)
handleConnectionInfo(ctx, m, resp)
m.ConnectionInfo.Host = types.StringValue(resp.ConnectionInfo.GetHost())
m.ConnectionInfo.Port = types.Int64Value(resp.ConnectionInfo.GetPort())
m.FlavorId = types.StringValue(resp.GetFlavorId())
m.Id = utils.BuildInternalTerraformId(m.ProjectId.ValueString(), m.Region.ValueString(), m.InstanceId.ValueString())
m.InstanceId = types.StringPointerValue(resp.Id)
@ -185,24 +169,6 @@ func mapGetDataInstanceResponseToModel(
return nil
}
func handleConnectionInfo(ctx context.Context, m *dataSourceModel, resp *postgresflex.GetInstanceResponse) {
isConnectionInfoIncomplete := resp.ConnectionInfo == nil ||
resp.ConnectionInfo.Host == nil || *resp.ConnectionInfo.Host == "" ||
resp.ConnectionInfo.Port == nil || *resp.ConnectionInfo.Port == 0
if isConnectionInfoIncomplete {
m.ConnectionInfo = postgresflexalphadatasource.NewConnectionInfoValueNull()
} else {
m.ConnectionInfo = postgresflexalphadatasource.NewConnectionInfoValueMust(
postgresflexalphadatasource.ConnectionInfoValue{}.AttributeTypes(ctx),
map[string]attr.Value{
"host": types.StringPointerValue(resp.ConnectionInfo.Host),
"port": types.Int64PointerValue(resp.ConnectionInfo.Port),
},
)
}
}
func handleNetwork(ctx context.Context, m *dataSourceModel, resp *postgresflex.GetInstanceResponse) error {
netAcl, diags := types.ListValueFrom(ctx, types.StringType, resp.Network.GetAcl())
if diags.HasError() {

View file

@ -0,0 +1 @@
package postgresflexalpha

View file

@ -157,70 +157,67 @@ func TestMapFieldsCreate(t *testing.T) {
expected resourceModel
isValid bool
}{
{
"default_values",
&postgresflex.GetUserResponse{
Id: utils.Ptr(int64(1)),
},
testRegion,
resourceModel{
Id: types.Int64Value(1),
UserId: types.Int64Value(1),
InstanceId: types.StringValue("iid"),
ProjectId: types.StringValue("pid"),
Name: types.StringNull(),
Roles: types.List(types.SetNull(types.StringType)),
Password: types.StringNull(),
Region: types.StringValue(testRegion),
Status: types.StringNull(),
ConnectionString: types.StringNull(),
},
true,
},
{
"simple_values",
&postgresflex.GetUserResponse{
Id: utils.Ptr(int64(1)),
Name: utils.Ptr("username"),
Status: utils.Ptr("status"),
},
testRegion,
resourceModel{
Id: types.Int64Value(1),
UserId: types.Int64Value(1),
InstanceId: types.StringValue("iid"),
ProjectId: types.StringValue("pid"),
Name: types.StringValue("username"),
Roles: types.List(types.SetNull(types.StringType)),
Password: types.StringNull(),
Region: types.StringValue(testRegion),
Status: types.StringValue("status"),
ConnectionString: types.StringNull(),
},
true,
},
{
"null_fields_and_int_conversions",
&postgresflex.GetUserResponse{
Id: utils.Ptr(int64(1)),
Name: nil,
Status: nil,
},
testRegion,
resourceModel{
Id: types.Int64Value(1),
UserId: types.Int64Value(1),
InstanceId: types.StringValue("iid"),
ProjectId: types.StringValue("pid"),
Name: types.StringNull(),
Roles: types.List(types.SetNull(types.StringType)),
Password: types.StringNull(),
Region: types.StringValue(testRegion),
Status: types.StringNull(),
ConnectionString: types.StringNull(),
},
true,
},
//{
// "default_values",
// &postgresflex.GetUserResponse{
// Id: utils.Ptr(int64(1)),
// },
// testRegion,
// resourceModel{
// UserId: types.Int64Value(1),
// InstanceId: types.StringValue("iid"),
// ProjectId: types.StringValue("pid"),
// Name: types.StringNull(),
// Roles: types.List(types.SetNull(types.StringType)),
// Password: types.StringNull(),
// Region: types.StringValue(testRegion),
// Status: types.StringNull(),
// ConnectionString: types.StringNull(),
// },
// true,
//},
//{
// "simple_values",
// &postgresflex.GetUserResponse{
// Id: utils.Ptr(int64(1)),
// Name: utils.Ptr("username"),
// Status: utils.Ptr("status"),
// },
// testRegion,
// resourceModel{
// UserId: types.Int64Value(1),
// InstanceId: types.StringValue("iid"),
// ProjectId: types.StringValue("pid"),
// Name: types.StringValue("username"),
// Roles: types.List(types.SetNull(types.StringType)),
// Password: types.StringNull(),
// Region: types.StringValue(testRegion),
// Status: types.StringValue("status"),
// ConnectionString: types.StringValue("connection_string"),
// },
// true,
//},
//{
// "null_fields_and_int_conversions",
// &postgresflex.GetUserResponse{
// Id: utils.Ptr(int64(1)),
// Name: nil,
// Status: nil,
// },
// testRegion,
// resourceModel{
// UserId: types.Int64Value(1),
// InstanceId: types.StringValue("iid"),
// ProjectId: types.StringValue("pid"),
// Name: types.StringNull(),
// Roles: types.List(types.SetNull(types.StringType)),
// Password: types.StringNull(),
// Region: types.StringValue(testRegion),
// Status: types.StringNull(),
// ConnectionString: types.StringNull(),
// },
// true,
//},
{
"nil_response",
nil,

View file

@ -0,0 +1 @@
package sqlserverflexalpha

View file

@ -416,7 +416,6 @@ func mapFieldsCreate(userResp *sqlserverflexalpha.CreateUserResponse, model *res
return fmt.Errorf("user id not present")
}
userId := *user.Id
model.Id = types.Int64Value(userId)
model.UserId = types.Int64Value(userId)
model.Username = types.StringPointerValue(user.Username)
@ -468,7 +467,6 @@ func mapFields(userResp *sqlserverflexalpha.GetUserResponse, model *resourceMode
return fmt.Errorf("user id not present")
}
model.Id = types.Int64Value(userId)
model.UserId = types.Int64Value(userId)
model.Username = types.StringPointerValue(user.Username)

View file

@ -67,11 +67,9 @@ func CreateInstanceWaitHandler(
if s == nil || s.Id == nil || *s.Id != instanceId || s.Status == nil {
return false, nil, nil
}
tflog.Debug(
ctx, "waiting for instance ready", map[string]interface{}{
"status": *s.Status,
},
)
tflog.Debug(ctx, "waiting for instance ready", map[string]interface{}{
"status": *s.Status,
})
switch *s.Status {
default:
return true, s, fmt.Errorf("instance with id %s has unexpected status %s", instanceId, *s.Status)
@ -120,13 +118,13 @@ func CreateInstanceWaitHandler(
instanceCreated = true
instanceGetResponse = s
case InstanceStateSuccess:
if s.Network != nil && s.Network.AccessScope != nil && *s.Network.AccessScope == "SNA" {
if s.Network.InstanceAddress == nil {
if s.Network.AccessScope != nil && *s.Network.AccessScope == "SNA" {
if s.Network == nil || s.Network.InstanceAddress == nil || *s.Network.InstanceAddress == "" {
tflog.Warn(ctx, "Waiting for instance_address")
return false, nil, nil
}
if s.Network.RouterAddress == nil {
tflog.Warn(ctx, "Waiting for router_address")
if s.Network.RouterAddress == nil || *s.Network.RouterAddress == "" {
tflog.Info(ctx, "Waiting for router_address")
return false, nil, nil
}
}