Skip to content

Commit 6ff26ee

Browse files
committed
Constuct a tfprotov5.ListResourceResult
1 parent 3a106c1 commit 6ff26ee

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

list/list_resource_test.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/hashicorp/terraform-plugin-framework/hcl2shim"
1313
"github.com/hashicorp/terraform-plugin-framework/list"
1414
"github.com/hashicorp/terraform-plugin-framework/resource"
15+
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
1516
sdk "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1617
tsdk "github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
1718
)
@@ -72,21 +73,20 @@ func TestListResultToResourceData(t *testing.T) {
7273
}
7374

7475
// 2: from the resource type, we can obtain an initialized ResourceData value
75-
d := sdkResource.Data(&tsdk.InstanceState{})
76+
d := sdkResource.Data(&tsdk.InstanceState{ID: "#groot"})
7677

7778
// 3: the initialized ResourceData value is schema-aware
78-
d.SetId("#groot")
79-
80-
if err := d.Set("name", "groot"); err != nil {
79+
if err := d.Set("name", "Groot"); err != nil {
8180
t.Fatalf("Error setting `name`: %v", err)
8281
}
8382

8483
if err := d.Set("nom", "groot"); err == nil {
8584
t.Fatal("False negative outcome: `nom` is not a schema attribute")
8685
}
8786

88-
// 4: mimic SDK GRPCProviderServer.ReadResource ResourceData -> MsgPack
87+
displayName := "I am Groot"
8988

89+
// 4: mimic SDK GRPCProviderServer.ReadResource ResourceData -> MsgPack
9090
state := d.State()
9191
if state == nil {
9292
t.Fatal("Expected state to be non-nil")
@@ -104,13 +104,16 @@ func TestListResultToResourceData(t *testing.T) {
104104
}
105105

106106
// newStateVal = normalizeNullValues(newStateVal, stateVal, false)
107-
// newStateVal = copyTimeoutValues(newStateVal, stateVal)
108-
// newStateVal = setWriteOnlyNullValues(newStateVal, schemaBlock)
109107

110108
pack, err := msgpack.Marshal(newStateVal, schemaBlock.ImpliedType())
111109
if err != nil {
112110
t.Fatalf("Error marshaling new state value to MsgPack: %v", err)
113111
}
114112

115113
fmt.Printf("MsgPack: %s\n", pack)
114+
115+
// 5: construct a tfprotov5.ListResourceResult
116+
listResult := tfprotov5.ListResourceResult{}
117+
listResult.Resource = &tfprotov5.DynamicValue{MsgPack: pack}
118+
listResult.DisplayName = displayName
116119
}

0 commit comments

Comments
 (0)