Skip to content

Commit 2d5ce8a

Browse files
stephybunrainkwan
andauthored
querychecks: add tests (#553)
* update examplecloud resource/list resource and add test files for querychecks * forgot one, oops * Saving my place * Revert "Saving my place" This reverts commit ccc4965. * Updating with correct packages * Almost passing all tests * Added missing copywrite * remove early returns and retrieve resource schema in the providerserver * Addressing PR comments --------- Co-authored-by: Rain <[email protected]> Co-authored-by: Rain Kwan <[email protected]>
1 parent ee23b9f commit 2d5ce8a

13 files changed

+1334
-301
lines changed

helper/resource/query/examplecloud_list_test.go

Lines changed: 162 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ func examplecloudListResource() testprovider.ListResource {
1919
Block: &tfprotov6.SchemaBlock{
2020
Attributes: []*tfprotov6.SchemaAttribute{
2121
{
22-
Name: "id",
22+
Name: "resource_group_name",
2323
Type: tftypes.String,
24-
Computed: true,
24+
Required: true,
2525
},
2626
},
2727
},
@@ -33,57 +33,199 @@ func examplecloudListResource() testprovider.ListResource {
3333
Resource: teststep.Pointer(tftypes.NewValue(
3434
tftypes.Object{
3535
AttributeTypes: map[string]tftypes.Type{
36-
"id": tftypes.String,
37-
"location": tftypes.String,
38-
"name": tftypes.String,
36+
"id": tftypes.String,
37+
"location": tftypes.String,
38+
"name": tftypes.String,
39+
"resource_group_name": tftypes.String,
40+
"instances": tftypes.Number,
3941
},
4042
},
4143
map[string]tftypes.Value{
42-
"id": tftypes.NewValue(tftypes.String, "westeurope/somevalue"),
43-
"location": tftypes.NewValue(tftypes.String, "westeurope"),
44-
"name": tftypes.NewValue(tftypes.String, "somevalue"),
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),
4549
},
4650
)),
4751
Identity: teststep.Pointer(tftypes.NewValue(
4852
tftypes.Object{
4953
AttributeTypes: map[string]tftypes.Type{
50-
"id": tftypes.String,
51-
"location": tftypes.String,
54+
"resource_group_name": tftypes.String,
55+
"name": tftypes.String,
5256
},
5357
},
5458
map[string]tftypes.Value{
55-
"id": tftypes.NewValue(tftypes.String, "westeurope/somevalue1"),
56-
"location": tftypes.NewValue(tftypes.String, "westeurope"),
59+
"resource_group_name": tftypes.NewValue(tftypes.String, "foo"),
60+
"name": tftypes.NewValue(tftypes.String, "banane"),
5761
},
5862
)),
63+
DisplayName: "banane",
5964
})
6065
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+
)),
61150
Identity: teststep.Pointer(tftypes.NewValue(
62151
tftypes.Object{
63152
AttributeTypes: map[string]tftypes.Type{
64-
"id": tftypes.String,
65-
"location": tftypes.String,
153+
"resource_group_name": tftypes.String,
154+
"name": tftypes.String,
66155
},
67156
},
68157
map[string]tftypes.Value{
69-
"id": tftypes.NewValue(tftypes.String, "westeurope/somevalue2"),
70-
"location": tftypes.NewValue(tftypes.String, "westeurope2"),
158+
"resource_group_name": tftypes.NewValue(tftypes.String, "bar"),
159+
"name": tftypes.NewValue(tftypes.String, "papaya"),
71160
},
72161
)),
162+
DisplayName: "papaya",
73163
})
74164
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+
)),
75216
Identity: teststep.Pointer(tftypes.NewValue(
76217
tftypes.Object{
77218
AttributeTypes: map[string]tftypes.Type{
78-
"id": tftypes.String,
79-
"location": tftypes.String,
219+
"resource_group_name": tftypes.String,
220+
"name": tftypes.String,
80221
},
81222
},
82223
map[string]tftypes.Value{
83-
"id": tftypes.NewValue(tftypes.String, "westeurope/somevalue3"),
84-
"location": tftypes.NewValue(tftypes.String, "westeurope3"),
224+
"resource_group_name": tftypes.NewValue(tftypes.String, "bar"),
225+
"name": tftypes.NewValue(tftypes.String, "kirsche"),
85226
},
86227
)),
228+
DisplayName: "kirsche",
87229
})
88230
},
89231
},

helper/resource/query/examplecloud_test.go

Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,83 +17,95 @@ func examplecloudResource() testprovider.Resource {
1717
NewState: tftypes.NewValue(
1818
tftypes.Object{
1919
AttributeTypes: map[string]tftypes.Type{
20-
"id": tftypes.String,
21-
"location": tftypes.String,
22-
"name": tftypes.String,
20+
"id": tftypes.String,
21+
"location": tftypes.String,
22+
"name": tftypes.String,
23+
"resource_group_name": tftypes.String,
24+
"instances": tftypes.Number,
2325
},
2426
},
2527
map[string]tftypes.Value{
26-
"id": tftypes.NewValue(tftypes.String, "westeurope/somevalue"),
27-
"location": tftypes.NewValue(tftypes.String, "westeurope"),
28-
"name": tftypes.NewValue(tftypes.String, "somevalue"),
28+
"id": tftypes.NewValue(tftypes.String, "foo/banana"),
29+
"location": tftypes.NewValue(tftypes.String, "westeurope"),
30+
"name": tftypes.NewValue(tftypes.String, "banana"),
31+
"resource_group_name": tftypes.NewValue(tftypes.String, "foo"),
32+
"instances": tftypes.NewValue(tftypes.Number, int64(5)),
2933
},
3034
),
3135
NewIdentity: teststep.Pointer(tftypes.NewValue(
3236
tftypes.Object{
3337
AttributeTypes: map[string]tftypes.Type{
34-
"id": tftypes.String,
35-
"location": tftypes.String,
38+
"resource_group_name": tftypes.String,
39+
"name": tftypes.String,
3640
},
3741
},
3842
map[string]tftypes.Value{
39-
"id": tftypes.NewValue(tftypes.String, "westeurope/somevalue"),
40-
"location": tftypes.NewValue(tftypes.String, "somelocation"),
43+
"resource_group_name": tftypes.NewValue(tftypes.String, "foo"),
44+
"name": tftypes.NewValue(tftypes.String, "banana"),
4145
},
4246
)),
4347
},
4448
ReadResponse: &resource.ReadResponse{
4549
NewState: tftypes.NewValue(
4650
tftypes.Object{
4751
AttributeTypes: map[string]tftypes.Type{
48-
"id": tftypes.String,
49-
"location": tftypes.String,
50-
"name": tftypes.String,
52+
"id": tftypes.String,
53+
"location": tftypes.String,
54+
"name": tftypes.String,
55+
"resource_group_name": tftypes.String,
56+
"instances": tftypes.Number,
5157
},
5258
},
5359
map[string]tftypes.Value{
54-
"id": tftypes.NewValue(tftypes.String, "westeurope/somevalue"),
55-
"location": tftypes.NewValue(tftypes.String, "westeurope"),
56-
"name": tftypes.NewValue(tftypes.String, "somevalue"),
60+
"id": tftypes.NewValue(tftypes.String, "foo/banana"),
61+
"location": tftypes.NewValue(tftypes.String, "westeurope"),
62+
"name": tftypes.NewValue(tftypes.String, "banana"),
63+
"resource_group_name": tftypes.NewValue(tftypes.String, "foo"),
64+
"instances": tftypes.NewValue(tftypes.Number, int64(5)),
5765
},
5866
),
5967
NewIdentity: teststep.Pointer(tftypes.NewValue(
6068
tftypes.Object{
6169
AttributeTypes: map[string]tftypes.Type{
62-
"id": tftypes.String,
63-
"location": tftypes.String,
70+
"resource_group_name": tftypes.String,
71+
"name": tftypes.String,
6472
},
6573
},
6674
map[string]tftypes.Value{
67-
"id": tftypes.NewValue(tftypes.String, "westeurope/somevalue"),
68-
"location": tftypes.NewValue(tftypes.String, "westeurope"),
75+
"resource_group_name": tftypes.NewValue(tftypes.String, "foo"),
76+
"name": tftypes.NewValue(tftypes.String, "banana"),
6977
},
7078
)),
7179
},
7280
ImportStateResponse: &resource.ImportStateResponse{
7381
State: tftypes.NewValue(
7482
tftypes.Object{
7583
AttributeTypes: map[string]tftypes.Type{
76-
"id": tftypes.String,
77-
"location": tftypes.String,
78-
"name": tftypes.String,
84+
"id": tftypes.String,
85+
"location": tftypes.String,
86+
"name": tftypes.String,
87+
"resource_group_name": tftypes.String,
88+
"instances": tftypes.Number,
7989
},
8090
},
8191
map[string]tftypes.Value{
82-
"id": tftypes.NewValue(tftypes.String, "westeurope/somevalue"),
83-
"location": tftypes.NewValue(tftypes.String, "westeurope"),
84-
"name": tftypes.NewValue(tftypes.String, "somevalue"),
92+
"id": tftypes.NewValue(tftypes.String, "foo/banana"),
93+
"location": tftypes.NewValue(tftypes.String, "westeurope"),
94+
"name": tftypes.NewValue(tftypes.String, "banana"),
95+
"resource_group_name": tftypes.NewValue(tftypes.String, "foo"),
96+
"instances": tftypes.NewValue(tftypes.Number, int64(5)),
8597
},
8698
),
8799
Identity: teststep.Pointer(tftypes.NewValue(
88100
tftypes.Object{
89101
AttributeTypes: map[string]tftypes.Type{
90-
"id": tftypes.String,
91-
"location": tftypes.String,
102+
"resource_group_name": tftypes.String,
103+
"name": tftypes.String,
92104
},
93105
},
94106
map[string]tftypes.Value{
95-
"id": tftypes.NewValue(tftypes.String, "westeurope/somevalue"),
96-
"location": tftypes.NewValue(tftypes.String, "westeurope/somevalue"),
107+
"resource_group_name": tftypes.NewValue(tftypes.String, "foo"),
108+
"name": tftypes.NewValue(tftypes.String, "banana"),
97109
},
98110
)),
99111
},
@@ -104,6 +116,8 @@ func examplecloudResource() testprovider.Resource {
104116
ComputedStringAttribute("id"),
105117
RequiredStringAttribute("location"),
106118
RequiredStringAttribute("name"),
119+
RequiredStringAttribute("resource_group_name"),
120+
OptionalNumberAttribute("instances"),
107121
},
108122
},
109123
},
@@ -113,12 +127,12 @@ func examplecloudResource() testprovider.Resource {
113127
Version: 1,
114128
IdentityAttributes: []*tfprotov6.ResourceIdentitySchemaAttribute{
115129
{
116-
Name: "id",
130+
Name: "resource_group_name",
117131
Type: tftypes.String,
118132
RequiredForImport: true,
119133
},
120134
{
121-
Name: "location",
135+
Name: "name",
122136
Type: tftypes.String,
123137
RequiredForImport: true,
124138
},

0 commit comments

Comments
 (0)