@@ -20,78 +20,81 @@ func TestTest_TestStep_ImportBlockVerify(t *testing.T) {
2020
2121 UnitTest (t , TestCase {
2222 TerraformVersionChecks : []tfversion.TerraformVersionCheck {
23- tfversion .SkipBelow (tfversion .Version1_5_0 ), // import blocks are only available in v1.5.0 and later
23+ // import blocks are only available in v1.5.0 and later
24+ tfversion .SkipBelow (tfversion .Version1_5_0 ),
2425 },
2526 ProtoV6ProviderFactories : map [string ]func () (tfprotov6.ProviderServer , error ){
2627 "examplecloud" : providerserver .NewProviderServer (testprovider.Provider {
2728 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- },
29+ "examplecloud_bucket" : exampleCloudBucketResource (t ),
7630 },
7731 }),
7832 },
7933 Steps : []TestStep {
8034 {
81- Config : `resource "examplecloud_thing" "test" {}` ,
35+ Config : `
36+ resource "examplecloud_bucket" "storage" {
37+ bucket = "test-bucket"
38+ description = "A bucket for testing."
39+ }` ,
8240 },
8341 {
84- ImportState : true ,
85- ImportStateVerify : true ,
86- ImportStateBlockConfig : `
87- import {
88- to = examplecloud_thing.test
89- identity = {
90- hat = "derby"
91- cat = "garfield"
92- }
93- }` ,
42+ ImportState : true ,
43+ ImportStateKind : ImportBlockWithResourceIdentity ,
44+ ResourceName : "examplecloud_bucket.storage" ,
9445 },
9546 },
9647 })
9748}
49+
50+ func exampleCloudBucketResource (t * testing.T ) testprovider.Resource {
51+ t .Helper ()
52+
53+ return testprovider.Resource {
54+ CreateResponse : & resource.CreateResponse {
55+ NewResourceIdentityData : tftypes .NewValue (
56+ tftypes.Object {
57+ AttributeTypes : map [string ]tftypes.Type {
58+ "region" : tftypes .String ,
59+ "bucket" : tftypes .String ,
60+ },
61+ },
62+ map [string ]tftypes.Value {
63+ "region" : tftypes .NewValue (tftypes .String , "test-region" ),
64+ "bucket" : tftypes .NewValue (tftypes .String , "test-bucket" ),
65+ },
66+ ),
67+ NewState : tftypes .NewValue (
68+ tftypes.Object {
69+ AttributeTypes : map [string ]tftypes.Type {
70+ "bucket" : tftypes .String ,
71+ "description" : tftypes .String ,
72+ },
73+ },
74+ map [string ]tftypes.Value {
75+ "bucket" : tftypes .NewValue (tftypes .String , "test-bucket" ),
76+ "description" : tftypes .NewValue (tftypes .String , "A bucket for testing." ),
77+ },
78+ ),
79+ },
80+ ImportStateResponse : & resource.ImportStateResponse {},
81+ SchemaResponse : & resource.SchemaResponse {
82+ Schema : & tfprotov6.Schema {
83+ Block : & tfprotov6.SchemaBlock {
84+ Attributes : []* tfprotov6.SchemaAttribute {
85+ {
86+ Name : "bucket" ,
87+ Type : tftypes .String ,
88+ Required : true ,
89+ },
90+ {
91+ Name : "description" ,
92+ Type : tftypes .String ,
93+ Optional : true ,
94+ },
95+ },
96+ },
97+ },
98+ },
99+ }
100+ }
0 commit comments