|
| 1 | +// Copyright (c) HashiCorp, Inc. |
| 2 | +// SPDX-License-Identifier: MPL-2.0 |
| 3 | + |
| 4 | +package resource |
| 5 | + |
| 6 | +import ( |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/hashicorp/terraform-plugin-go/tfprotov6" |
| 10 | + "github.com/hashicorp/terraform-plugin-go/tftypes" |
| 11 | + |
| 12 | + "github.com/hashicorp/terraform-plugin-testing/internal/testing/testprovider" |
| 13 | + "github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/providerserver" |
| 14 | + "github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/resource" |
| 15 | + "github.com/hashicorp/terraform-plugin-testing/tfversion" |
| 16 | +) |
| 17 | + |
| 18 | +func TestTest_TestStep_ImportBlockVerify(t *testing.T) { |
| 19 | + t.Parallel() |
| 20 | + |
| 21 | + UnitTest(t, TestCase{ |
| 22 | + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ |
| 23 | + tfversion.SkipBelow(tfversion.Version1_5_0), // import blocks are only available in v1.5.0 and later |
| 24 | + }, |
| 25 | + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ |
| 26 | + "examplecloud": providerserver.NewProviderServer(testprovider.Provider{ |
| 27 | + Resources: map[string]testprovider.Resource{ |
| 28 | + "examplecloud_thing": { |
| 29 | + CreateResponse: &resource.CreateResponse{ |
| 30 | + NewState: tftypes.NewValue( |
| 31 | + tftypes.Object{ |
| 32 | + AttributeTypes: map[string]tftypes.Type{ |
| 33 | + "id": tftypes.String, |
| 34 | + "other": tftypes.String, |
| 35 | + }, |
| 36 | + }, |
| 37 | + map[string]tftypes.Value{ |
| 38 | + "id": tftypes.NewValue(tftypes.String, "resource-test"), |
| 39 | + "other": tftypes.NewValue(tftypes.String, "testvalue"), |
| 40 | + }, |
| 41 | + ), |
| 42 | + }, |
| 43 | + ImportStateResponse: &resource.ImportStateResponse{ |
| 44 | + State: tftypes.NewValue( |
| 45 | + tftypes.Object{ |
| 46 | + AttributeTypes: map[string]tftypes.Type{ |
| 47 | + "id": tftypes.String, |
| 48 | + "other": tftypes.String, |
| 49 | + }, |
| 50 | + }, |
| 51 | + map[string]tftypes.Value{ |
| 52 | + "id": tftypes.NewValue(tftypes.String, "resource-test"), |
| 53 | + "other": tftypes.NewValue(tftypes.String, "testvalue"), |
| 54 | + }, |
| 55 | + ), |
| 56 | + }, |
| 57 | + SchemaResponse: &resource.SchemaResponse{ |
| 58 | + Schema: &tfprotov6.Schema{ |
| 59 | + Block: &tfprotov6.SchemaBlock{ |
| 60 | + Attributes: []*tfprotov6.SchemaAttribute{ |
| 61 | + { |
| 62 | + Name: "id", |
| 63 | + Type: tftypes.String, |
| 64 | + Computed: true, |
| 65 | + }, |
| 66 | + { |
| 67 | + Name: "other", |
| 68 | + Type: tftypes.String, |
| 69 | + Computed: true, |
| 70 | + }, |
| 71 | + }, |
| 72 | + }, |
| 73 | + }, |
| 74 | + }, |
| 75 | + }, |
| 76 | + }, |
| 77 | + }), |
| 78 | + }, |
| 79 | + Steps: []TestStep{ |
| 80 | + { |
| 81 | + Config: `resource "examplecloud_thing" "test" {}`, |
| 82 | + }, |
| 83 | + { |
| 84 | + ImportState: true, |
| 85 | + ImportStateVerify: true, |
| 86 | + ImportStateBlockConfig: `import { |
| 87 | + to = examplecloud_thing.test |
| 88 | + identity = { |
| 89 | + hat = "derby" |
| 90 | + cat = "garfield" |
| 91 | + } |
| 92 | + }`, |
| 93 | + }, |
| 94 | + }, |
| 95 | + }) |
| 96 | +} |
0 commit comments