Skip to content

Commit 84b0e71

Browse files
committed
Updating with correct packages
1 parent 1b91d14 commit 84b0e71

8 files changed

+789
-67
lines changed

querycheck/contains_name_test.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package querycheck_test
22

33
import (
4+
"regexp"
5+
"testing"
6+
47
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
58
r "github.com/hashicorp/terraform-plugin-testing/helper/resource"
69
"github.com/hashicorp/terraform-plugin-testing/internal/testing/testprovider"
710
"github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/providerserver"
811
"github.com/hashicorp/terraform-plugin-testing/querycheck"
912
"github.com/hashicorp/terraform-plugin-testing/tfversion"
10-
"regexp"
11-
"testing"
1213
)
1314

1415
func TestContainsResourceWithName(t *testing.T) {
@@ -21,13 +22,11 @@ func TestContainsResourceWithName(t *testing.T) {
2122
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
2223
"examplecloud": providerserver.NewProviderServer(testprovider.Provider{
2324
ListResources: map[string]testprovider.ListResource{
24-
2525
// TODO: define a simpler resource and list resource here or copy the `examplecloud_test.go` and `examplecloud_list_resource.go` files here for use
26-
27-
//"examplecloud_containerette": examplecloudListResource(),
26+
"examplecloud_containerette": examplecloudListResource(),
2827
},
2928
Resources: map[string]testprovider.Resource{
30-
//"examplecloud_containerette": examplecloudResource(),
29+
"examplecloud_containerette": examplecloudResource(),
3130
},
3231
}),
3332
},
@@ -78,13 +77,10 @@ func TestContainsResourceWithName_NotFound(t *testing.T) {
7877
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
7978
"examplecloud": providerserver.NewProviderServer(testprovider.Provider{
8079
ListResources: map[string]testprovider.ListResource{
81-
82-
// TODO: define a resource and list resource here or copy the `examplecloud_test.go` and `examplecloud_list_resource.go` files here for use
83-
84-
//"examplecloud_containerette": examplecloudListResource(),
80+
"examplecloud_containerette": examplecloudListResource(),
8581
},
8682
Resources: map[string]testprovider.Resource{
87-
//"examplecloud_containerette": examplecloudResource(),
83+
"examplecloud_containerette": examplecloudResource(),
8884
},
8985
}),
9086
},
Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package querycheck_test
5+
6+
import (
7+
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
8+
"github.com/hashicorp/terraform-plugin-go/tftypes"
9+
"github.com/hashicorp/terraform-plugin-testing/internal/testing/testprovider"
10+
"github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/list"
11+
"github.com/hashicorp/terraform-plugin-testing/internal/teststep"
12+
)
13+
14+
func examplecloudListResource() testprovider.ListResource {
15+
return testprovider.ListResource{
16+
IncludeResource: true,
17+
SchemaResponse: &list.SchemaResponse{
18+
Schema: &tfprotov6.Schema{
19+
Block: &tfprotov6.SchemaBlock{
20+
Attributes: []*tfprotov6.SchemaAttribute{
21+
{
22+
Name: "resource_group_name",
23+
Type: tftypes.String,
24+
Required: true,
25+
},
26+
},
27+
},
28+
},
29+
},
30+
ListResultsStream: &list.ListResultsStream{
31+
Results: func(push func(list.ListResult) bool) {
32+
push(list.ListResult{
33+
Resource: teststep.Pointer(tftypes.NewValue(
34+
tftypes.Object{
35+
AttributeTypes: map[string]tftypes.Type{
36+
"id": tftypes.String,
37+
"location": tftypes.String,
38+
"name": tftypes.String,
39+
"resource_group_name": tftypes.String,
40+
"instances": tftypes.Number,
41+
},
42+
},
43+
map[string]tftypes.Value{
44+
"id": tftypes.NewValue(tftypes.String, "foo/banane"),
45+
"location": tftypes.NewValue(tftypes.String, "westeurope"),
46+
"name": tftypes.NewValue(tftypes.String, "banane"),
47+
"resource_group_name": tftypes.NewValue(tftypes.String, "foo"),
48+
"instances": tftypes.NewValue(tftypes.Number, 5),
49+
},
50+
)),
51+
Identity: teststep.Pointer(tftypes.NewValue(
52+
tftypes.Object{
53+
AttributeTypes: map[string]tftypes.Type{
54+
"resource_group_name": tftypes.String,
55+
"name": tftypes.String,
56+
},
57+
},
58+
map[string]tftypes.Value{
59+
"resource_group_name": tftypes.NewValue(tftypes.String, "foo"),
60+
"name": tftypes.NewValue(tftypes.String, "banane"),
61+
},
62+
)),
63+
DisplayName: "banane",
64+
})
65+
push(list.ListResult{
66+
Resource: teststep.Pointer(tftypes.NewValue(
67+
tftypes.Object{
68+
AttributeTypes: map[string]tftypes.Type{
69+
"id": tftypes.String,
70+
"location": tftypes.String,
71+
"name": tftypes.String,
72+
"resource_group_name": tftypes.String,
73+
"instances": tftypes.Number,
74+
},
75+
},
76+
map[string]tftypes.Value{
77+
"id": tftypes.NewValue(tftypes.String, "foo/ananas"),
78+
"location": tftypes.NewValue(tftypes.String, "westeurope"),
79+
"name": tftypes.NewValue(tftypes.String, "ananas"),
80+
"resource_group_name": tftypes.NewValue(tftypes.String, "foo"),
81+
"instances": tftypes.NewValue(tftypes.Number, 9000),
82+
},
83+
)),
84+
Identity: teststep.Pointer(tftypes.NewValue(
85+
tftypes.Object{
86+
AttributeTypes: map[string]tftypes.Type{
87+
"resource_group_name": tftypes.String,
88+
"name": tftypes.String,
89+
},
90+
},
91+
map[string]tftypes.Value{
92+
"resource_group_name": tftypes.NewValue(tftypes.String, "foo"),
93+
"name": tftypes.NewValue(tftypes.String, "ananas"),
94+
},
95+
)),
96+
DisplayName: "ananas",
97+
})
98+
push(list.ListResult{
99+
Resource: teststep.Pointer(tftypes.NewValue(
100+
tftypes.Object{
101+
AttributeTypes: map[string]tftypes.Type{
102+
"id": tftypes.String,
103+
"location": tftypes.String,
104+
"name": tftypes.String,
105+
"resource_group_name": tftypes.String,
106+
"instances": tftypes.Number,
107+
},
108+
},
109+
map[string]tftypes.Value{
110+
"id": tftypes.NewValue(tftypes.String, "foo/kiwi"),
111+
"location": tftypes.NewValue(tftypes.String, "westeurope"),
112+
"name": tftypes.NewValue(tftypes.String, "kiwi"),
113+
"resource_group_name": tftypes.NewValue(tftypes.String, "foo"),
114+
"instances": tftypes.NewValue(tftypes.Number, 88),
115+
},
116+
)),
117+
Identity: teststep.Pointer(tftypes.NewValue(
118+
tftypes.Object{
119+
AttributeTypes: map[string]tftypes.Type{
120+
"resource_group_name": tftypes.String,
121+
"name": tftypes.String,
122+
},
123+
},
124+
map[string]tftypes.Value{
125+
"resource_group_name": tftypes.NewValue(tftypes.String, "foo"),
126+
"name": tftypes.NewValue(tftypes.String, "kiwi"),
127+
},
128+
)),
129+
DisplayName: "kiwi",
130+
})
131+
push(list.ListResult{
132+
Resource: teststep.Pointer(tftypes.NewValue(
133+
tftypes.Object{
134+
AttributeTypes: map[string]tftypes.Type{
135+
"id": tftypes.String,
136+
"location": tftypes.String,
137+
"name": tftypes.String,
138+
"resource_group_name": tftypes.String,
139+
"instances": tftypes.Number,
140+
},
141+
},
142+
map[string]tftypes.Value{
143+
"id": tftypes.NewValue(tftypes.String, "bar/papaya"),
144+
"location": tftypes.NewValue(tftypes.String, "westeurope"),
145+
"name": tftypes.NewValue(tftypes.String, "banane"),
146+
"resource_group_name": tftypes.NewValue(tftypes.String, "foo"),
147+
"instances": tftypes.NewValue(tftypes.Number, 3),
148+
},
149+
)),
150+
Identity: teststep.Pointer(tftypes.NewValue(
151+
tftypes.Object{
152+
AttributeTypes: map[string]tftypes.Type{
153+
"resource_group_name": tftypes.String,
154+
"name": tftypes.String,
155+
},
156+
},
157+
map[string]tftypes.Value{
158+
"resource_group_name": tftypes.NewValue(tftypes.String, "bar"),
159+
"name": tftypes.NewValue(tftypes.String, "papaya"),
160+
},
161+
)),
162+
DisplayName: "papaya",
163+
})
164+
push(list.ListResult{
165+
Resource: teststep.Pointer(tftypes.NewValue(
166+
tftypes.Object{
167+
AttributeTypes: map[string]tftypes.Type{
168+
"id": tftypes.String,
169+
"location": tftypes.String,
170+
"name": tftypes.String,
171+
"resource_group_name": tftypes.String,
172+
"instances": tftypes.Number,
173+
},
174+
},
175+
map[string]tftypes.Value{
176+
"id": tftypes.NewValue(tftypes.String, "bar/birne"),
177+
"location": tftypes.NewValue(tftypes.String, "westeurope"),
178+
"name": tftypes.NewValue(tftypes.String, "birne"),
179+
"resource_group_name": tftypes.NewValue(tftypes.String, "foo"),
180+
"instances": tftypes.NewValue(tftypes.Number, 8564),
181+
},
182+
)),
183+
Identity: teststep.Pointer(tftypes.NewValue(
184+
tftypes.Object{
185+
AttributeTypes: map[string]tftypes.Type{
186+
"resource_group_name": tftypes.String,
187+
"name": tftypes.String,
188+
},
189+
},
190+
map[string]tftypes.Value{
191+
"resource_group_name": tftypes.NewValue(tftypes.String, "bar"),
192+
"name": tftypes.NewValue(tftypes.String, "birne"),
193+
},
194+
)),
195+
DisplayName: "birne",
196+
})
197+
push(list.ListResult{
198+
Resource: teststep.Pointer(tftypes.NewValue(
199+
tftypes.Object{
200+
AttributeTypes: map[string]tftypes.Type{
201+
"id": tftypes.String,
202+
"location": tftypes.String,
203+
"name": tftypes.String,
204+
"resource_group_name": tftypes.String,
205+
"instances": tftypes.Number,
206+
},
207+
},
208+
map[string]tftypes.Value{
209+
"id": tftypes.NewValue(tftypes.String, "bar/kirsche"),
210+
"location": tftypes.NewValue(tftypes.String, "westeurope"),
211+
"name": tftypes.NewValue(tftypes.String, "kirsche"),
212+
"resource_group_name": tftypes.NewValue(tftypes.String, "foo"),
213+
"instances": tftypes.NewValue(tftypes.Number, 500),
214+
},
215+
)),
216+
Identity: teststep.Pointer(tftypes.NewValue(
217+
tftypes.Object{
218+
AttributeTypes: map[string]tftypes.Type{
219+
"resource_group_name": tftypes.String,
220+
"name": tftypes.String,
221+
},
222+
},
223+
map[string]tftypes.Value{
224+
"resource_group_name": tftypes.NewValue(tftypes.String, "bar"),
225+
"name": tftypes.NewValue(tftypes.String, "kirsche"),
226+
},
227+
)),
228+
DisplayName: "kirsche",
229+
})
230+
},
231+
},
232+
}
233+
}

0 commit comments

Comments
 (0)