Skip to content

Commit 0ba6749

Browse files
make tests use two providers
this validates that the provider must stay open long enough for the resource to plan the actions
1 parent a8c46f5 commit 0ba6749

File tree

1 file changed

+41
-36
lines changed

1 file changed

+41
-36
lines changed

internal/terraform/context_apply_action_test.go

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestContext2Apply_actions(t *testing.T) {
3434
"unreferenced": {
3535
module: map[string]string{
3636
"main.tf": `
37-
action "test_unlinked" "hello" {}
37+
action "act_unlinked" "hello" {}
3838
`,
3939
},
4040
expectInvokeActionCalled: false,
@@ -43,12 +43,12 @@ action "test_unlinked" "hello" {}
4343
"before_create triggered": {
4444
module: map[string]string{
4545
"main.tf": `
46-
action "test_unlinked" "hello" {}
46+
action "act_unlinked" "hello" {}
4747
resource "test_object" "a" {
4848
lifecycle {
4949
action_trigger {
5050
events = [before_create]
51-
actions = [action.test_unlinked.hello]
51+
actions = [action.act_unlinked.hello]
5252
}
5353
}
5454
}
@@ -60,12 +60,12 @@ resource "test_object" "a" {
6060
"after_create triggered": {
6161
module: map[string]string{
6262
"main.tf": `
63-
action "test_unlinked" "hello" {}
63+
action "act_unlinked" "hello" {}
6464
resource "test_object" "a" {
6565
lifecycle {
6666
action_trigger {
6767
events = [after_create]
68-
actions = [action.test_unlinked.hello]
68+
actions = [action.act_unlinked.hello]
6969
}
7070
}
7171
}
@@ -77,13 +77,13 @@ resource "test_object" "a" {
7777
"before_update triggered": {
7878
module: map[string]string{
7979
"main.tf": `
80-
action "test_unlinked" "hello" {}
80+
action "act_unlinked" "hello" {}
8181
resource "test_object" "a" {
8282
name = "new name"
8383
lifecycle {
8484
action_trigger {
8585
events = [before_update]
86-
actions = [action.test_unlinked.hello]
86+
actions = [action.act_unlinked.hello]
8787
}
8888
}
8989
}
@@ -112,13 +112,13 @@ resource "test_object" "a" {
112112
"after_update triggered": {
113113
module: map[string]string{
114114
"main.tf": `
115-
action "test_unlinked" "hello" {}
115+
action "act_unlinked" "hello" {}
116116
resource "test_object" "a" {
117117
name = "new name"
118118
lifecycle {
119119
action_trigger {
120120
events = [after_update]
121-
actions = [action.test_unlinked.hello]
121+
actions = [action.act_unlinked.hello]
122122
}
123123
}
124124
}
@@ -147,12 +147,12 @@ resource "test_object" "a" {
147147
"before_create failing": {
148148
module: map[string]string{
149149
"main.tf": `
150-
action "test_unlinked" "hello" {}
150+
action "act_unlinked" "hello" {}
151151
resource "test_object" "a" {
152152
lifecycle {
153153
action_trigger {
154154
events = [before_create]
155-
actions = [action.test_unlinked.hello]
155+
actions = [action.act_unlinked.hello]
156156
}
157157
}
158158
}
@@ -183,12 +183,12 @@ resource "test_object" "a" {
183183
"before_create failing to call invoke": {
184184
module: map[string]string{
185185
"main.tf": `
186-
action "test_unlinked" "hello" {}
186+
action "act_unlinked" "hello" {}
187187
resource "test_object" "a" {
188188
lifecycle {
189189
action_trigger {
190190
events = [before_create]
191-
actions = [action.test_unlinked.hello]
191+
actions = [action.act_unlinked.hello]
192192
}
193193
}
194194
}
@@ -217,7 +217,7 @@ resource "test_object" "a" {
217217
resource "test_object" "a" {
218218
name = "foo"
219219
}
220-
action "test_unlinked" "hello" {
220+
action "act_unlinked" "hello" {
221221
config {
222222
attr = resource.test_object.a.name
223223
}
@@ -226,15 +226,15 @@ resource "test_object" "b" {
226226
lifecycle {
227227
action_trigger {
228228
events = [before_create]
229-
actions = [action.test_unlinked.hello]
229+
actions = [action.act_unlinked.hello]
230230
}
231231
}
232232
}
233233
`,
234234
},
235235
expectInvokeActionCalled: true,
236236
expectInvokeActionCalls: []providers.InvokeActionRequest{{
237-
ActionType: "test_unlinked",
237+
ActionType: "act_unlinked",
238238
PlannedActionData: cty.ObjectVal(map[string]cty.Value{
239239
"attr": cty.StringVal("foo"),
240240
}),
@@ -248,7 +248,7 @@ resource "test_object" "b" {
248248
variable "unknown_value" {
249249
type = string
250250
}
251-
action "test_unlinked" "hello" {
251+
action "act_unlinked" "hello" {
252252
config {
253253
attr = var.unknown_value
254254
}
@@ -257,7 +257,7 @@ resource "test_object" "b" {
257257
lifecycle {
258258
action_trigger {
259259
events = [before_create]
260-
actions = [action.test_unlinked.hello]
260+
actions = [action.act_unlinked.hello]
261261
}
262262
}
263263
}
@@ -271,7 +271,7 @@ resource "test_object" "b" {
271271

272272
expectInvokeActionCalled: true,
273273
expectInvokeActionCalls: []providers.InvokeActionRequest{{
274-
ActionType: "test_unlinked",
274+
ActionType: "act_unlinked",
275275
PlannedActionData: cty.ObjectVal(map[string]cty.Value{
276276
"attr": cty.UnknownVal(cty.String),
277277
}),
@@ -285,7 +285,7 @@ variable "secret_value" {
285285
type = string
286286
sensitive = true
287287
}
288-
action "test_unlinked" "hello" {
288+
action "act_unlinked" "hello" {
289289
config {
290290
attr = var.secret_value
291291
}
@@ -294,7 +294,7 @@ resource "test_object" "b" {
294294
lifecycle {
295295
action_trigger {
296296
events = [before_create]
297-
actions = [action.test_unlinked.hello]
297+
actions = [action.act_unlinked.hello]
298298
}
299299
}
300300
}
@@ -308,7 +308,7 @@ resource "test_object" "b" {
308308

309309
expectInvokeActionCalled: true,
310310
expectInvokeActionCalls: []providers.InvokeActionRequest{{
311-
ActionType: "test_unlinked",
311+
ActionType: "act_unlinked",
312312
PlannedActionData: cty.ObjectVal(map[string]cty.Value{
313313
"attr": cty.StringVal("psst, I'm secret"),
314314
}),
@@ -320,34 +320,40 @@ resource "test_object" "b" {
320320

321321
invokeActionCalls := []providers.InvokeActionRequest{}
322322

323-
p := &testing_provider.MockProvider{
323+
testProvider := &testing_provider.MockProvider{
324324
GetProviderSchemaResponse: &providers.GetProviderSchemaResponse{
325-
Actions: map[string]providers.ActionSchema{
326-
"test_unlinked": {
327-
ConfigSchema: &configschema.Block{
325+
ResourceTypes: map[string]providers.Schema{
326+
"test_object": {
327+
Body: &configschema.Block{
328328
Attributes: map[string]*configschema.Attribute{
329-
"attr": {
329+
"name": {
330330
Type: cty.String,
331331
Optional: true,
332332
},
333333
},
334334
},
335-
336-
Unlinked: &providers.UnlinkedAction{},
337335
},
338336
},
339-
ResourceTypes: map[string]providers.Schema{
340-
"test_object": {
341-
Body: &configschema.Block{
337+
},
338+
}
339+
340+
actionProvider := &testing_provider.MockProvider{
341+
GetProviderSchemaResponse: &providers.GetProviderSchemaResponse{
342+
Actions: map[string]providers.ActionSchema{
343+
"act_unlinked": {
344+
ConfigSchema: &configschema.Block{
342345
Attributes: map[string]*configschema.Attribute{
343-
"name": {
346+
"attr": {
344347
Type: cty.String,
345348
Optional: true,
346349
},
347350
},
348351
},
352+
353+
Unlinked: &providers.UnlinkedAction{},
349354
},
350355
},
356+
ResourceTypes: map[string]providers.Schema{},
351357
},
352358
InvokeActionFn: func(req providers.InvokeActionRequest) providers.InvokeActionResponse {
353359
invokeActionCalls = append(invokeActionCalls, req)
@@ -383,9 +389,8 @@ resource "test_object" "b" {
383389

384390
ctx := testContext2(t, &ContextOpts{
385391
Providers: map[addrs.Provider]providers.Factory{
386-
// The providers never actually going to get called here, we should
387-
// catch the error long before anything happens.
388-
addrs.NewDefaultProvider("test"): testProviderFuncFixed(p),
392+
addrs.NewDefaultProvider("test"): testProviderFuncFixed(testProvider),
393+
addrs.NewDefaultProvider("act"): testProviderFuncFixed(actionProvider),
389394
},
390395
})
391396

0 commit comments

Comments
 (0)