fix: fix mapping tests #44
1 changed files with 36 additions and 2 deletions
|
|
@ -55,6 +55,22 @@ 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("")
|
m.ConnectionInfo.Host = types.StringValue("")
|
||||||
if host, ok := resp.ConnectionInfo.GetHostOk(); ok {
|
if host, ok := resp.ConnectionInfo.GetHostOk(); ok {
|
||||||
m.ConnectionInfo.Host = types.StringValue(host)
|
m.ConnectionInfo.Host = types.StringValue(host)
|
||||||
|
|
@ -138,8 +154,8 @@ func mapGetDataInstanceResponseToModel(
|
||||||
) error {
|
) error {
|
||||||
m.BackupSchedule = types.StringValue(resp.GetBackupSchedule())
|
m.BackupSchedule = types.StringValue(resp.GetBackupSchedule())
|
||||||
handleEncryption(m, resp)
|
handleEncryption(m, resp)
|
||||||
m.ConnectionInfo.Host = types.StringValue(resp.ConnectionInfo.GetHost())
|
handleConnectionInfo(ctx, m, resp)
|
||||||
m.ConnectionInfo.Port = types.Int64Value(resp.ConnectionInfo.GetPort())
|
|
||||||
m.FlavorId = types.StringValue(resp.GetFlavorId())
|
m.FlavorId = types.StringValue(resp.GetFlavorId())
|
||||||
m.Id = utils.BuildInternalTerraformId(m.ProjectId.ValueString(), m.Region.ValueString(), m.InstanceId.ValueString())
|
m.Id = utils.BuildInternalTerraformId(m.ProjectId.ValueString(), m.Region.ValueString(), m.InstanceId.ValueString())
|
||||||
m.InstanceId = types.StringPointerValue(resp.Id)
|
m.InstanceId = types.StringPointerValue(resp.Id)
|
||||||
|
|
@ -169,6 +185,24 @@ func mapGetDataInstanceResponseToModel(
|
||||||
return nil
|
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 {
|
func handleNetwork(ctx context.Context, m *dataSourceModel, resp *postgresflex.GetInstanceResponse) error {
|
||||||
netAcl, diags := types.ListValueFrom(ctx, types.StringType, resp.Network.GetAcl())
|
netAcl, diags := types.ListValueFrom(ctx, types.StringType, resp.Network.GetAcl())
|
||||||
if diags.HasError() {
|
if diags.HasError() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue