Skip to content

Commit

Permalink
use GetOkExists
Browse files Browse the repository at this point in the history
  • Loading branch information
linkas45 committed Apr 29, 2024
1 parent 89692fc commit d8ee726
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
8 changes: 4 additions & 4 deletions castai/resource_node_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -1033,8 +1033,8 @@ func toTemplateConstraints(d *schema.ResourceData, obj map[string]any) *sdk.Node
}

out := &sdk.NodetemplatesV1TemplateConstraints{}
// todo: replace with tri-state enum
if v, exists := d.GetOk(FieldNodeTemplateConstraints + "." + FieldNodeTemplateComputeOptimized); exists {
// todo: replace with tri-state enum as GetOkExists is deprecated
if v, exists := d.GetOkExists(FieldNodeTemplateConstraints + ".0." + FieldNodeTemplateComputeOptimized); exists {

Check failure on line 1037 in castai/resource_node_template.go

View workflow job for this annotation

GitHub Actions / lint

SA1019: d.GetOkExists is deprecated: usage is discouraged due to undefined behaviors and may be removed in a future version of the SDK (staticcheck)
out.ComputeOptimized = toPtr(v.(bool))
}
if v, ok := obj[FieldNodeTemplateFallbackRestoreRateSeconds].(int); ok {
Expand Down Expand Up @@ -1074,8 +1074,8 @@ func toTemplateConstraints(d *schema.ResourceData, obj map[string]any) *sdk.Node
out.Spot = toPtr(!v)
}
}
// todo: replace with tri-state enum
if v, exists := d.GetOk(FieldNodeTemplateConstraints + "." + FieldNodeTemplateStorageOptimized); exists {
// todo: replace with tri-state enum as GetOkExists is deprecated
if v, exists := d.GetOkExists(FieldNodeTemplateConstraints + ".0." + FieldNodeTemplateStorageOptimized); exists {

Check failure on line 1078 in castai/resource_node_template.go

View workflow job for this annotation

GitHub Actions / lint

SA1019: d.GetOkExists is deprecated: usage is discouraged due to undefined behaviors and may be removed in a future version of the SDK (staticcheck)
out.StorageOptimized = toPtr(v.(bool))
}
if v, ok := obj[FieldNodeTemplateUseSpotFallbacks].(bool); ok {
Expand Down
20 changes: 19 additions & 1 deletion castai/resource_node_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ func TestToTemplateConstraints_HandleTriStateValuesForStorageAndComputeOptimized
val cty.Value
assertions func(*require.Assertions, *sdk.NodetemplatesV1TemplateConstraints)
}{
"all values empty except one": {
"all values nil": {
val: cty.ObjectVal(map[string]cty.Value{
FieldNodeTemplateConstraints: cty.ListVal([]cty.Value{
cty.ObjectVal(map[string]cty.Value{
Expand All @@ -419,6 +419,24 @@ func TestToTemplateConstraints_HandleTriStateValuesForStorageAndComputeOptimized
r.Nil(constraints.StorageOptimized)
},
},
"values are true/false": {
val: cty.ObjectVal(map[string]cty.Value{
FieldNodeTemplateConstraints: cty.ListVal([]cty.Value{
cty.ObjectVal(map[string]cty.Value{
FieldNodeTemplateMaxCpu: cty.NumberIntVal(100),
FieldNodeTemplateStorageOptimized: cty.True,
FieldNodeTemplateComputeOptimized: cty.False,
}),
}),
}),
assertions: func(r *require.Assertions, constraints *sdk.NodetemplatesV1TemplateConstraints) {
r.NotNil(constraints)
r.NotNil(constraints.ComputeOptimized)
r.NotNil(constraints.StorageOptimized)
r.True(lo.FromPtr(constraints.StorageOptimized))
r.False(lo.FromPtr(constraints.ComputeOptimized))
},
},
}

for name, td := range tests {
Expand Down

0 comments on commit d8ee726

Please sign in to comment.