Skip to content

Commit 4b76aba

Browse files
committed
More test provider extraction
1 parent e924715 commit 4b76aba

File tree

2 files changed

+37
-68
lines changed

2 files changed

+37
-68
lines changed

helper/resource/importstate/examplecloud_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,40 @@ import (
44
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
55
"github.com/hashicorp/terraform-plugin-go/tftypes"
66
"github.com/hashicorp/terraform-plugin-testing/internal/testing/testprovider"
7+
"github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/datasource"
78
"github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/resource"
89
)
910

11+
func examplecloudDataSource() testprovider.DataSource {
12+
return testprovider.DataSource{
13+
ReadResponse: &datasource.ReadResponse{
14+
State: tftypes.NewValue(
15+
tftypes.Object{
16+
AttributeTypes: map[string]tftypes.Type{
17+
"id": tftypes.String,
18+
},
19+
},
20+
map[string]tftypes.Value{
21+
"id": tftypes.NewValue(tftypes.String, "datasource-test"),
22+
},
23+
),
24+
},
25+
SchemaResponse: &datasource.SchemaResponse{
26+
Schema: &tfprotov6.Schema{
27+
Block: &tfprotov6.SchemaBlock{
28+
Attributes: []*tfprotov6.SchemaAttribute{
29+
{
30+
Name: "id",
31+
Type: tftypes.String,
32+
Computed: true,
33+
},
34+
},
35+
},
36+
},
37+
},
38+
}
39+
}
40+
1041
func examplecloudResource() testprovider.Resource {
1142
return testprovider.Resource{
1243
CreateResponse: &resource.CreateResponse{

helper/resource/importstate/import_block_with_id_test.go

Lines changed: 6 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"regexp"
99
"testing"
1010

11-
"github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/datasource"
1211
"github.com/hashicorp/terraform-plugin-testing/terraform"
1312

1413
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
@@ -103,82 +102,21 @@ func TestTest_TestStep_ImportBlockId_SkipDataSourceState(t *testing.T) {
103102
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
104103
"examplecloud": providerserver.NewProviderServer(testprovider.Provider{
105104
DataSources: map[string]testprovider.DataSource{
106-
"examplecloud_thing": {
107-
ReadResponse: &datasource.ReadResponse{
108-
State: tftypes.NewValue(
109-
tftypes.Object{
110-
AttributeTypes: map[string]tftypes.Type{
111-
"id": tftypes.String,
112-
},
113-
},
114-
map[string]tftypes.Value{
115-
"id": tftypes.NewValue(tftypes.String, "datasource-test"),
116-
},
117-
),
118-
},
119-
SchemaResponse: &datasource.SchemaResponse{
120-
Schema: &tfprotov6.Schema{
121-
Block: &tfprotov6.SchemaBlock{
122-
Attributes: []*tfprotov6.SchemaAttribute{
123-
{
124-
Name: "id",
125-
Type: tftypes.String,
126-
Computed: true,
127-
},
128-
},
129-
},
130-
},
131-
},
132-
},
105+
"examplecloud_thing": examplecloudDataSource(),
133106
},
134107
Resources: map[string]testprovider.Resource{
135-
"examplecloud_thing": {
136-
CreateResponse: &resource.CreateResponse{
137-
NewState: tftypes.NewValue(
138-
tftypes.Object{
139-
AttributeTypes: map[string]tftypes.Type{
140-
"id": tftypes.String,
141-
},
142-
},
143-
map[string]tftypes.Value{
144-
"id": tftypes.NewValue(tftypes.String, "resource-test"),
145-
},
146-
),
147-
},
148-
ImportStateResponse: &resource.ImportStateResponse{
149-
State: tftypes.NewValue(
150-
tftypes.Object{
151-
AttributeTypes: map[string]tftypes.Type{
152-
"id": tftypes.String,
153-
},
154-
},
155-
map[string]tftypes.Value{
156-
"id": tftypes.NewValue(tftypes.String, "resource-test"),
157-
},
158-
),
159-
},
160-
SchemaResponse: &resource.SchemaResponse{
161-
Schema: &tfprotov6.Schema{
162-
Block: &tfprotov6.SchemaBlock{
163-
Attributes: []*tfprotov6.SchemaAttribute{
164-
{
165-
Name: "id",
166-
Type: tftypes.String,
167-
Computed: true,
168-
},
169-
},
170-
},
171-
},
172-
},
173-
},
108+
"examplecloud_thing": examplecloudResource(),
174109
},
175110
}),
176111
},
177112
Steps: []r.TestStep{
178113
{
179114
Config: `
180115
data "examplecloud_thing" "test" {}
181-
resource "examplecloud_thing" "test" {}
116+
resource "examplecloud_thing" "test" {
117+
name = "somevalue"
118+
location = "westeurope"
119+
}
182120
`,
183121
},
184122
{

0 commit comments

Comments
 (0)