Update validate test to add case for marked count value

The diff here is largely a refactor to allow the test to run multiple cases
This commit is contained in:
Pam Selle 2021-01-05 11:49:35 -05:00
parent 33c31dce2b
commit dbde1be363

View File

@ -202,6 +202,7 @@ func TestNodeValidatableResource_ValidateResource_managedResource(t *testing.T)
} }
func TestNodeValidatableResource_ValidateResource_managedResourceCount(t *testing.T) { func TestNodeValidatableResource_ValidateResource_managedResourceCount(t *testing.T) {
// Setup
mp := simpleMockProvider() mp := simpleMockProvider()
mp.ValidateResourceTypeConfigFn = func(req providers.ValidateResourceTypeConfigRequest) providers.ValidateResourceTypeConfigResponse { mp.ValidateResourceTypeConfigFn = func(req providers.ValidateResourceTypeConfigRequest) providers.ValidateResourceTypeConfigResponse {
if got, want := req.TypeName, "test_object"; got != want { if got, want := req.TypeName, "test_object"; got != want {
@ -214,11 +215,33 @@ func TestNodeValidatableResource_ValidateResource_managedResourceCount(t *testin
} }
p := providers.Interface(mp) p := providers.Interface(mp)
ctx := &MockEvalContext{}
ctx.installSimpleEval()
ctx.ProviderSchemaSchema = mp.GetSchemaReturn
ctx.ProviderProvider = p
tests := []struct {
name string
count hcl.Expression
}{
{
"simple count",
hcltest.MockExprLiteral(cty.NumberIntVal(2)),
},
{
"marked count value",
hcltest.MockExprLiteral(cty.NumberIntVal(3).Mark("marked")),
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
rc := &configs.Resource{ rc := &configs.Resource{
Mode: addrs.ManagedResourceMode, Mode: addrs.ManagedResourceMode,
Type: "test_object", Type: "test_object",
Name: "foo", Name: "foo",
Count: hcltest.MockExprLiteral(cty.NumberIntVal(2)), Count: test.count,
Config: configs.SynthBody("", map[string]cty.Value{ Config: configs.SynthBody("", map[string]cty.Value{
"test_string": cty.StringVal("bar"), "test_string": cty.StringVal("bar"),
}), }),
@ -231,11 +254,6 @@ func TestNodeValidatableResource_ValidateResource_managedResourceCount(t *testin
}, },
} }
ctx := &MockEvalContext{}
ctx.installSimpleEval()
ctx.ProviderSchemaSchema = mp.GetSchemaReturn
ctx.ProviderProvider = p
diags := node.validateResource(ctx) diags := node.validateResource(ctx)
if diags.HasErrors() { if diags.HasErrors() {
t.Fatalf("err: %s", diags.Err()) t.Fatalf("err: %s", diags.Err())
@ -244,6 +262,8 @@ func TestNodeValidatableResource_ValidateResource_managedResourceCount(t *testin
if !mp.ValidateResourceTypeConfigCalled { if !mp.ValidateResourceTypeConfigCalled {
t.Fatal("Expected ValidateResourceTypeConfig to be called, but it was not!") t.Fatal("Expected ValidateResourceTypeConfig to be called, but it was not!")
} }
})
}
} }
func TestNodeValidatableResource_ValidateResource_dataSource(t *testing.T) { func TestNodeValidatableResource_ValidateResource_dataSource(t *testing.T) {