fix: fix mapping tests #44
7 changed files with 56 additions and 12 deletions
|
|
@ -34,7 +34,12 @@ func TestMapFields(t *testing.T) {
|
||||||
Name: utils.Ptr("my-db"),
|
Name: utils.Ptr("my-db"),
|
||||||
Owner: utils.Ptr("\"my-owner\""),
|
Owner: utils.Ptr("\"my-owner\""),
|
||||||
},
|
},
|
||||||
model: &dataSourceModel{},
|
model: &dataSourceModel{
|
||||||
|
DatabaseModel: datasource.DatabaseModel{
|
||||||
|
ProjectId: types.StringValue("my-project"),
|
||||||
|
InstanceId: types.StringValue("my-instance"),
|
||||||
|
},
|
||||||
|
},
|
||||||
region: "eu01",
|
region: "eu01",
|
||||||
},
|
},
|
||||||
expected: expected{
|
expected: expected{
|
||||||
|
|
|
||||||
|
|
@ -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() {
|
||||||
|
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
package postgresflexalpha
|
|
||||||
|
|
@ -164,6 +164,7 @@ func TestMapFieldsCreate(t *testing.T) {
|
||||||
},
|
},
|
||||||
testRegion,
|
testRegion,
|
||||||
resourceModel{
|
resourceModel{
|
||||||
|
Id: types.Int64Value(1),
|
||||||
UserId: types.Int64Value(1),
|
UserId: types.Int64Value(1),
|
||||||
InstanceId: types.StringValue("iid"),
|
InstanceId: types.StringValue("iid"),
|
||||||
ProjectId: types.StringValue("pid"),
|
ProjectId: types.StringValue("pid"),
|
||||||
|
|
@ -185,6 +186,7 @@ func TestMapFieldsCreate(t *testing.T) {
|
||||||
},
|
},
|
||||||
testRegion,
|
testRegion,
|
||||||
resourceModel{
|
resourceModel{
|
||||||
|
Id: types.Int64Value(1),
|
||||||
UserId: types.Int64Value(1),
|
UserId: types.Int64Value(1),
|
||||||
InstanceId: types.StringValue("iid"),
|
InstanceId: types.StringValue("iid"),
|
||||||
ProjectId: types.StringValue("pid"),
|
ProjectId: types.StringValue("pid"),
|
||||||
|
|
@ -193,7 +195,7 @@ func TestMapFieldsCreate(t *testing.T) {
|
||||||
Password: types.StringNull(),
|
Password: types.StringNull(),
|
||||||
Region: types.StringValue(testRegion),
|
Region: types.StringValue(testRegion),
|
||||||
Status: types.StringValue("status"),
|
Status: types.StringValue("status"),
|
||||||
ConnectionString: types.StringValue("connection_string"),
|
ConnectionString: types.StringNull(),
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
|
|
@ -206,6 +208,7 @@ func TestMapFieldsCreate(t *testing.T) {
|
||||||
},
|
},
|
||||||
testRegion,
|
testRegion,
|
||||||
resourceModel{
|
resourceModel{
|
||||||
|
Id: types.Int64Value(1),
|
||||||
UserId: types.Int64Value(1),
|
UserId: types.Int64Value(1),
|
||||||
InstanceId: types.StringValue("iid"),
|
InstanceId: types.StringValue("iid"),
|
||||||
ProjectId: types.StringValue("pid"),
|
ProjectId: types.StringValue("pid"),
|
||||||
|
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
package sqlserverflexalpha
|
|
||||||
|
|
@ -416,6 +416,7 @@ func mapFieldsCreate(userResp *sqlserverflexalpha.CreateUserResponse, model *res
|
||||||
return fmt.Errorf("user id not present")
|
return fmt.Errorf("user id not present")
|
||||||
}
|
}
|
||||||
userId := *user.Id
|
userId := *user.Id
|
||||||
|
model.Id = types.Int64Value(userId)
|
||||||
model.UserId = types.Int64Value(userId)
|
model.UserId = types.Int64Value(userId)
|
||||||
model.Username = types.StringPointerValue(user.Username)
|
model.Username = types.StringPointerValue(user.Username)
|
||||||
|
|
||||||
|
|
@ -467,6 +468,7 @@ func mapFields(userResp *sqlserverflexalpha.GetUserResponse, model *resourceMode
|
||||||
return fmt.Errorf("user id not present")
|
return fmt.Errorf("user id not present")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
model.Id = types.Int64Value(userId)
|
||||||
model.UserId = types.Int64Value(userId)
|
model.UserId = types.Int64Value(userId)
|
||||||
model.Username = types.StringPointerValue(user.Username)
|
model.Username = types.StringPointerValue(user.Username)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -67,9 +67,11 @@ func CreateInstanceWaitHandler(
|
||||||
if s == nil || s.Id == nil || *s.Id != instanceId || s.Status == nil {
|
if s == nil || s.Id == nil || *s.Id != instanceId || s.Status == nil {
|
||||||
return false, nil, nil
|
return false, nil, nil
|
||||||
}
|
}
|
||||||
tflog.Debug(ctx, "waiting for instance ready", map[string]interface{}{
|
tflog.Debug(
|
||||||
|
ctx, "waiting for instance ready", map[string]interface{}{
|
||||||
"status": *s.Status,
|
"status": *s.Status,
|
||||||
})
|
},
|
||||||
|
)
|
||||||
switch *s.Status {
|
switch *s.Status {
|
||||||
default:
|
default:
|
||||||
return true, s, fmt.Errorf("instance with id %s has unexpected status %s", instanceId, *s.Status)
|
return true, s, fmt.Errorf("instance with id %s has unexpected status %s", instanceId, *s.Status)
|
||||||
|
|
@ -118,13 +120,13 @@ func CreateInstanceWaitHandler(
|
||||||
instanceCreated = true
|
instanceCreated = true
|
||||||
instanceGetResponse = s
|
instanceGetResponse = s
|
||||||
case InstanceStateSuccess:
|
case InstanceStateSuccess:
|
||||||
if *s.Network.AccessScope == "SNA" {
|
if s.Network != nil && s.Network.AccessScope != nil && *s.Network.AccessScope == "SNA" {
|
||||||
if s.Network == nil || s.Network.InstanceAddress == nil {
|
if s.Network.InstanceAddress == nil {
|
||||||
tflog.Warn(ctx, "Waiting for instance_address")
|
tflog.Warn(ctx, "Waiting for instance_address")
|
||||||
return false, nil, nil
|
return false, nil, nil
|
||||||
}
|
}
|
||||||
if s.Network.RouterAddress == nil {
|
if s.Network.RouterAddress == nil {
|
||||||
tflog.Info(ctx, "Waiting for router_address")
|
tflog.Warn(ctx, "Waiting for router_address")
|
||||||
return false, nil, nil
|
return false, nil, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue