Skip to content

Commit 074cd13

Browse files
committed
add tests for invalid paths
1 parent 207fb01 commit 074cd13

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

plancheck/expect_unknown_output_value_at_path_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,46 @@ func Test_ExpectUnknownOutputValueAtPath_SetNestedBlock_Object(t *testing.T) {
361361
})
362362
}
363363

364+
func Test_ExpectUnknownOutputValueAtPath_ExpectError_KnownValue_PathNotFound(t *testing.T) {
365+
t.Parallel()
366+
367+
r.UnitTest(t, r.TestCase{
368+
ProviderFactories: map[string]func() (*schema.Provider, error){
369+
"test": func() (*schema.Provider, error) { //nolint:unparam // required signature
370+
return testProvider(), nil
371+
},
372+
},
373+
// Prior to Terraform v1.3.0 a planned output is marked as fully unknown
374+
// if any attribute is unknown. The id attribute within the test provider
375+
// is unknown.
376+
// Reference: https://github.com/hashicorp/terraform/blob/v1.3/CHANGELOG.md#130-september-21-2022
377+
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
378+
tfversion.SkipBelow(tfversion.Version1_3_0),
379+
},
380+
Steps: []r.TestStep{
381+
{
382+
Config: `
383+
resource "test_resource" "one" {
384+
list_nested_block {
385+
list_nested_block_attribute = "value 1"
386+
}
387+
}
388+
389+
output "resource" {
390+
value = test_resource.one
391+
}
392+
`,
393+
ConfigPlanChecks: r.ConfigPlanChecks{
394+
PreApply: []plancheck.PlanCheck{
395+
plancheck.ExpectUnknownOutputValueAtPath("resource", tfjsonpath.New("list_nested_block").AtSliceIndex(0).AtMapKey("not_correct_attr")),
396+
},
397+
},
398+
ExpectError: regexp.MustCompile(`path not found: specified key not_correct_attr not found in map at list_nested_block.0.not_correct_attr`),
399+
},
400+
},
401+
})
402+
}
403+
364404
func Test_ExpectUnknownOutputValueAtPath_ExpectError_KnownValue_ListAttribute(t *testing.T) {
365405
t.Parallel()
366406

plancheck/expect_unknown_value_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,36 @@ func Test_ExpectUnknownValue_SetNestedBlock(t *testing.T) {
217217
})
218218
}
219219

220+
func Test_ExpectUnknownValue_ExpectError_KnownValue_PathNotFound(t *testing.T) {
221+
t.Parallel()
222+
223+
r.UnitTest(t, r.TestCase{
224+
ProviderFactories: map[string]func() (*schema.Provider, error){
225+
"test": func() (*schema.Provider, error) { //nolint:unparam // required signature
226+
return testProvider(), nil
227+
},
228+
},
229+
Steps: []r.TestStep{
230+
{
231+
Config: `
232+
resource "test_resource" "two" {
233+
list_nested_block {
234+
list_nested_block_attribute = "value 1"
235+
}
236+
}
237+
`,
238+
ConfigPlanChecks: r.ConfigPlanChecks{
239+
PreApply: []plancheck.PlanCheck{
240+
plancheck.ExpectUnknownValue("test_resource.two",
241+
tfjsonpath.New("list_nested_block").AtSliceIndex(0).AtMapKey("not_correct_attr")),
242+
},
243+
},
244+
ExpectError: regexp.MustCompile(`path not found: specified key not_correct_attr not found in map at list_nested_block.0.not_correct_attr`),
245+
},
246+
},
247+
})
248+
}
249+
220250
func Test_ExpectUnknownValue_ExpectError_KnownValue_ListAttribute(t *testing.T) {
221251
t.Parallel()
222252

0 commit comments

Comments
 (0)