Skip to content

Commit

Permalink
Adding further tests for null exact known value type check (#266)
Browse files Browse the repository at this point in the history
  • Loading branch information
bendbennett committed Jan 22, 2024
1 parent 6df33b9 commit 15330e3
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 1 deletion.
2 changes: 1 addition & 1 deletion knownvalue/null.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var _ Check = nullExact{}

type nullExact struct{}

// CheckValue determines whether the passed value is of nil.
// CheckValue determines whether the passed value is nil.
func (v nullExact) CheckValue(other any) error {
if other != nil {
return fmt.Errorf("expected value nil for NullExact check, got: %T", other)
Expand Down
40 changes: 40 additions & 0 deletions plancheck/expect_known_output_value_at_path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,46 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_AttributeValueNull(t *testing.T)
tfjsonpath.New("bool_attribute"),
knownvalue.NullExact(),
),
plancheck.ExpectKnownOutputValueAtPath(
"test_resource_one_output",
tfjsonpath.New("float_attribute"),
knownvalue.NullExact(),
),
plancheck.ExpectKnownOutputValueAtPath(
"test_resource_one_output",
tfjsonpath.New("int_attribute"),
knownvalue.NullExact(),
),
plancheck.ExpectKnownOutputValueAtPath(
"test_resource_one_output",
tfjsonpath.New("list_attribute"),
knownvalue.NullExact(),
),
plancheck.ExpectKnownOutputValueAtPath(
"test_resource_one_output",
tfjsonpath.New("list_nested_block"),
knownvalue.ListExact([]knownvalue.Check{}),
),
plancheck.ExpectKnownOutputValueAtPath(
"test_resource_one_output",
tfjsonpath.New("map_attribute"),
knownvalue.NullExact(),
),
plancheck.ExpectKnownOutputValueAtPath(
"test_resource_one_output",
tfjsonpath.New("set_attribute"),
knownvalue.NullExact(),
),
plancheck.ExpectKnownOutputValueAtPath(
"test_resource_one_output",
tfjsonpath.New("set_nested_block"),
knownvalue.SetExact([]knownvalue.Check{}),
),
plancheck.ExpectKnownOutputValueAtPath(
"test_resource_one_output",
tfjsonpath.New("string_attribute"),
knownvalue.NullExact(),
),
},
},
},
Expand Down
56 changes: 56 additions & 0 deletions plancheck/expect_known_output_value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,69 @@ func TestExpectKnownOutputValue_CheckPlan_AttributeValueNull(t *testing.T) {
output bool_output {
value = test_resource.one.bool_attribute
}
output float_output {
value = test_resource.one.float_attribute
}
output int_output {
value = test_resource.one.int_attribute
}
output list_output {
value = test_resource.one.list_attribute
}
output list_nested_block_output {
value = test_resource.one.list_nested_block
}
output map_output {
value = test_resource.one.map_attribute
}
output set_output {
value = test_resource.one.set_attribute
}
output set_nested_block_output {
value = test_resource.one.set_nested_block
}
output string_output {
value = test_resource.one.string_attribute
}
`,
ConfigPlanChecks: r.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectKnownOutputValue(
"bool_output",
knownvalue.NullExact(),
),
plancheck.ExpectKnownOutputValue(
"float_output",
knownvalue.NullExact(),
),
plancheck.ExpectKnownOutputValue(
"int_output",
knownvalue.NullExact(),
),
plancheck.ExpectKnownOutputValue(
"list_output",
knownvalue.NullExact(),
),
plancheck.ExpectKnownOutputValue(
"list_nested_block_output",
knownvalue.ListExact([]knownvalue.Check{}),
),
plancheck.ExpectKnownOutputValue(
"map_output",
knownvalue.NullExact(),
),
plancheck.ExpectKnownOutputValue(
"set_output",
knownvalue.NullExact(),
),
plancheck.ExpectKnownOutputValue(
"set_nested_block_output",
knownvalue.SetExact([]knownvalue.Check{}),
),
plancheck.ExpectKnownOutputValue(
"string_output",
knownvalue.NullExact(),
),
},
},
},
Expand Down
40 changes: 40 additions & 0 deletions plancheck/expect_known_value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,46 @@ func TestExpectKnownValue_CheckPlan_AttributeValueNull(t *testing.T) {
tfjsonpath.New("bool_attribute"),
knownvalue.NullExact(),
),
plancheck.ExpectKnownValue(
"test_resource.one",
tfjsonpath.New("float_attribute"),
knownvalue.NullExact(),
),
plancheck.ExpectKnownValue(
"test_resource.one",
tfjsonpath.New("int_attribute"),
knownvalue.NullExact(),
),
plancheck.ExpectKnownValue(
"test_resource.one",
tfjsonpath.New("list_attribute"),
knownvalue.NullExact(),
),
plancheck.ExpectKnownValue(
"test_resource.one",
tfjsonpath.New("list_nested_block"),
knownvalue.ListExact([]knownvalue.Check{}),
),
plancheck.ExpectKnownValue(
"test_resource.one",
tfjsonpath.New("map_attribute"),
knownvalue.NullExact(),
),
plancheck.ExpectKnownValue(
"test_resource.one",
tfjsonpath.New("set_attribute"),
knownvalue.NullExact(),
),
plancheck.ExpectKnownValue(
"test_resource.one",
tfjsonpath.New("set_nested_block"),
knownvalue.SetExact([]knownvalue.Check{}),
),
plancheck.ExpectKnownValue(
"test_resource.one",
tfjsonpath.New("string_attribute"),
knownvalue.NullExact(),
),
},
},
},
Expand Down
40 changes: 40 additions & 0 deletions statecheck/expect_known_output_value_at_path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,46 @@ func TestExpectKnownOutputValueAtPath_CheckState_AttributeValueNull(t *testing.T
tfjsonpath.New("bool_attribute"),
knownvalue.NullExact(),
),
statecheck.ExpectKnownOutputValueAtPath(
"test_resource_one_output",
tfjsonpath.New("float_attribute"),
knownvalue.NullExact(),
),
statecheck.ExpectKnownOutputValueAtPath(
"test_resource_one_output",
tfjsonpath.New("int_attribute"),
knownvalue.NullExact(),
),
statecheck.ExpectKnownOutputValueAtPath(
"test_resource_one_output",
tfjsonpath.New("list_attribute"),
knownvalue.NullExact(),
),
statecheck.ExpectKnownOutputValueAtPath(
"test_resource_one_output",
tfjsonpath.New("list_nested_block"),
knownvalue.ListExact([]knownvalue.Check{}),
),
statecheck.ExpectKnownOutputValueAtPath(
"test_resource_one_output",
tfjsonpath.New("map_attribute"),
knownvalue.NullExact(),
),
statecheck.ExpectKnownOutputValueAtPath(
"test_resource_one_output",
tfjsonpath.New("set_attribute"),
knownvalue.NullExact(),
),
statecheck.ExpectKnownOutputValueAtPath(
"test_resource_one_output",
tfjsonpath.New("set_nested_block"),
knownvalue.SetExact([]knownvalue.Check{}),
),
statecheck.ExpectKnownOutputValueAtPath(
"test_resource_one_output",
tfjsonpath.New("string_attribute"),
knownvalue.NullExact(),
),
},
},
},
Expand Down
40 changes: 40 additions & 0 deletions statecheck/expect_known_value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,46 @@ func TestExpectKnownValue_CheckState_AttributeValueNull(t *testing.T) {
tfjsonpath.New("bool_attribute"),
knownvalue.NullExact(),
),
statecheck.ExpectKnownValue(
"test_resource.one",
tfjsonpath.New("float_attribute"),
knownvalue.NullExact(),
),
statecheck.ExpectKnownValue(
"test_resource.one",
tfjsonpath.New("int_attribute"),
knownvalue.NullExact(),
),
statecheck.ExpectKnownValue(
"test_resource.one",
tfjsonpath.New("list_attribute"),
knownvalue.NullExact(),
),
statecheck.ExpectKnownValue(
"test_resource.one",
tfjsonpath.New("list_nested_block"),
knownvalue.ListExact([]knownvalue.Check{}),
),
statecheck.ExpectKnownValue(
"test_resource.one",
tfjsonpath.New("map_attribute"),
knownvalue.NullExact(),
),
statecheck.ExpectKnownValue(
"test_resource.one",
tfjsonpath.New("set_attribute"),
knownvalue.NullExact(),
),
statecheck.ExpectKnownValue(
"test_resource.one",
tfjsonpath.New("set_nested_block"),
knownvalue.ListExact([]knownvalue.Check{}),
),
statecheck.ExpectKnownValue(
"test_resource.one",
tfjsonpath.New("string_attribute"),
knownvalue.NullExact(),
),
},
},
},
Expand Down

0 comments on commit 15330e3

Please sign in to comment.