Skip to content

Commit 0896cf7

Browse files
committed
fix grpc_provider_test 2
1 parent fdc63c7 commit 0896cf7

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

internal/plugin/grpc_provider.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,11 +363,12 @@ func (p *GRPCProvider) ValidateListResourceConfig(r providers.ValidateListResour
363363
}
364364

365365
configSchema := listResourceSchema.Body.BlockTypes["config"]
366-
config := cty.NullVal(configSchema.ImpliedType())
366+
ty := configSchema.ImpliedType()
367+
config := cty.NullVal(ty)
367368
if r.Config.Type().HasAttribute("config") {
368369
config = r.Config.GetAttr("config")
369370
}
370-
mp, err := msgpack.Marshal(config, configSchema.ImpliedType())
371+
mp, err := msgpack.Marshal(config, ty)
371372
if err != nil {
372373
resp.Diagnostics = resp.Diagnostics.Append(err)
373374
return resp

internal/plugin/grpc_provider_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ func TestGRPCProvider_ValidateListResourceConfig(t *testing.T) {
483483
gomock.Any(),
484484
).Return(&proto.ValidateListResourceConfig_Response{}, nil)
485485

486-
cfg := hcl2shim.HCL2ValueFromConfigValue(map[string]interface{}{"config": map[string]interface{}{"filter_attr": "value"}})
486+
cfg := hcl2shim.HCL2ValueFromConfigValue(map[string]interface{}{"config": map[string]interface{}{"filter_attr": "value", "nested_filter": map[string]interface{}{"nested_attr": "value"}}})
487487
resp := p.ValidateListResourceConfig(providers.ValidateListResourceConfigRequest{
488488
TypeName: "list",
489489
Config: cfg,
@@ -495,8 +495,12 @@ func TestGRPCProvider_ValidateListResourceConfig_OptionalCfg(t *testing.T) {
495495
ctrl := gomock.NewController(t)
496496
client := mockproto.NewMockProviderClient(ctrl)
497497
sch := providerProtoSchema()
498+
499+
// mock the schema in a way that makes the config attributes optional
498500
sch.ListResourceSchemas["list"].Block.Attributes[0].Optional = true
499501
sch.ListResourceSchemas["list"].Block.Attributes[0].Required = false
502+
sch.ListResourceSchemas["list"].Block.BlockTypes[0].MinItems = 0
503+
sch.ListResourceSchemas["list"].Block.BlockTypes[0].MaxItems = 0
500504
// we always need a GetSchema method
501505
client.EXPECT().GetSchema(
502506
gomock.Any(),
@@ -1689,6 +1693,9 @@ func TestGRPCProvider_ListResource(t *testing.T) {
16891693
configVal := cty.ObjectVal(map[string]cty.Value{
16901694
"config": cty.ObjectVal(map[string]cty.Value{
16911695
"filter_attr": cty.StringVal("filter-value"),
1696+
"nested_filter": cty.ObjectVal(map[string]cty.Value{
1697+
"nested_attr": cty.StringVal("value"),
1698+
}),
16921699
}),
16931700
})
16941701
request := providers.ListResourceRequest{
@@ -2055,6 +2062,9 @@ func TestGRPCProvider_ListResource_Limit(t *testing.T) {
20552062
configVal := cty.ObjectVal(map[string]cty.Value{
20562063
"config": cty.ObjectVal(map[string]cty.Value{
20572064
"filter_attr": cty.StringVal("filter-value"),
2065+
"nested_filter": cty.ObjectVal(map[string]cty.Value{
2066+
"nested_attr": cty.StringVal("value"),
2067+
}),
20582068
}),
20592069
})
20602070
request := providers.ListResourceRequest{

0 commit comments

Comments
 (0)