Skip to content

Commit

Permalink
fix import test
Browse files Browse the repository at this point in the history
  • Loading branch information
austinvalle committed Jan 31, 2024
1 parent 10f3778 commit 95d52c2
Showing 1 changed file with 44 additions and 10 deletions.
54 changes: 44 additions & 10 deletions internal/dynamic6provider/dynamic_import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,40 @@ import (
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
"github.com/hashicorp/terraform-plugin-go/tftypes"
r "github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/knownvalue"
"github.com/hashicorp/terraform-plugin-testing/statecheck"
"github.com/hashicorp/terraform-plugin-testing/tfjsonpath"
"github.com/hashicorp/terraform-provider-corner/internal/testing/testprovider"
"github.com/hashicorp/terraform-provider-corner/internal/testing/testsdk/providerserver"
"github.com/hashicorp/terraform-provider-corner/internal/testing/testsdk/resource"
)

func Test_Dynamic_ImportState(t *testing.T) {
resourceName := "corner_dynamic_thing.foo"
r.UnitTest(t, r.TestCase{
Steps: []r.TestStep{
{
ResourceName: "corner_dynamic_thing.foo",
Config: `resource "corner_dynamic_thing" "foo" {}`,
ImportState: true,
ImportStateId: "id-123456",
Config: `resource "corner_dynamic_thing" "foo" {}`,
ConfigStateChecks: []statecheck.StateCheck{
statecheck.ExpectKnownValue(
"corner_dynamic_thing.foo",
tfjsonpath.New("id"),
knownvalue.StringExact("id-123456"),
),
statecheck.ExpectKnownValue(
"corner_dynamic_thing.foo",
tfjsonpath.New("obj"),
knownvalue.ObjectExact(map[string]knownvalue.Check{
"number": knownvalue.Int64Exact(123456),
}),
),
},
},
{
ResourceName: resourceName,
ImportStateId: "id-123456",
ImportState: true,
ImportStateVerify: true,
},
},
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
Expand All @@ -46,15 +67,28 @@ func Test_Dynamic_ImportState(t *testing.T) {
},
},
},
CreateResponse: &resource.CreateResponse{
NewState: tftypes.NewValue(tftypes.Object{
AttributeTypes: map[string]tftypes.Type{
"id": tftypes.DynamicPseudoType,
"obj": tftypes.DynamicPseudoType,
},
}, map[string]tftypes.Value{
"id": tftypes.NewValue(tftypes.String, "id-123456"),
"obj": tftypes.NewValue(tftypes.Object{
AttributeTypes: map[string]tftypes.Type{
"number": tftypes.Number,
},
}, map[string]tftypes.Value{
"number": tftypes.NewValue(tftypes.Number, 123456),
}),
}),
},
ImportStateResponse: &resource.ImportStateResponse{
State: tftypes.NewValue(tftypes.Object{
AttributeTypes: map[string]tftypes.Type{
"id": tftypes.String,
"obj": tftypes.Object{
AttributeTypes: map[string]tftypes.Type{
"number": tftypes.Number,
},
},
"id": tftypes.DynamicPseudoType,
"obj": tftypes.DynamicPseudoType,
},
}, map[string]tftypes.Value{
"id": tftypes.NewValue(tftypes.String, "id-123456"),
Expand Down

0 comments on commit 95d52c2

Please sign in to comment.