Skip to content

Commit

Permalink
Adding attribute or output path to error message (#266)
Browse files Browse the repository at this point in the history
  • Loading branch information
bendbennett committed Jan 11, 2024
1 parent f1b9656 commit ed9d236
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 63 deletions.
4 changes: 2 additions & 2 deletions plancheck/expect_known_output_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (e expectKnownOutputValue) CheckPlan(ctx context.Context, req CheckPlanRequ
}

if result == nil {
resp.Error = fmt.Errorf("value is null")
resp.Error = fmt.Errorf("value is null for output at path: %s", e.outputAddress)

return
}
Expand All @@ -60,7 +60,7 @@ func (e expectKnownOutputValue) CheckPlan(ctx context.Context, req CheckPlanRequ
reflect.Slice,
reflect.String:
if err := e.knownValue.CheckValue(result); err != nil {
resp.Error = err
resp.Error = fmt.Errorf("error checking value for output at path: %s, err: %s", e.outputAddress, err)

return
}
Expand Down
4 changes: 2 additions & 2 deletions plancheck/expect_known_output_value_at_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (e expectKnownOutputValueAtPath) CheckPlan(ctx context.Context, req CheckPl
}

if result == nil {
resp.Error = fmt.Errorf("value is null")
resp.Error = fmt.Errorf("value is null for output at path: %s.%s", e.outputAddress, e.outputPath.String())

return
}
Expand All @@ -61,7 +61,7 @@ func (e expectKnownOutputValueAtPath) CheckPlan(ctx context.Context, req CheckPl
reflect.Slice,
reflect.String:
if err := e.knownValue.CheckValue(result); err != nil {
resp.Error = err
resp.Error = fmt.Errorf("error checking value for output at path: %s.%s, err: %s", e.outputAddress, e.outputPath.String(), err)

return
}
Expand Down
38 changes: 19 additions & 19 deletions plancheck/expect_known_output_value_at_path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_AttributeValueNull(t *testing.T)
),
},
},
ExpectError: regexp.MustCompile("value is null"),
ExpectError: regexp.MustCompile("value is null for output at path: test_resource_one_output.bool_attribute"),
},
},
})
Expand Down Expand Up @@ -176,7 +176,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_Bool_KnownValueWrongType(t *test
),
},
},
ExpectError: regexp.MustCompile(`expected json\.Number value for Float64ValueExact check, got: bool`),
ExpectError: regexp.MustCompile(`error checking value for output at path: test_resource_one_output.bool_attribute, err: expected json\.Number value for Float64ValueExact check, got: bool`),
},
},
})
Expand Down Expand Up @@ -217,7 +217,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_Bool_KnownValueWrongValue(t *tes
),
},
},
ExpectError: regexp.MustCompile("expected value false for BoolValueExact check, got: true"),
ExpectError: regexp.MustCompile("error checking value for output at path: test_resource_one_output.bool_attribute, err: expected value false for BoolValueExact check, got: true"),
},
},
})
Expand Down Expand Up @@ -299,7 +299,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_Float64_KnownValueWrongType(t *t
),
},
},
ExpectError: regexp.MustCompile(`expected string value for StringValueExact check, got: json\.Number`),
ExpectError: regexp.MustCompile(`error checking value for output at path: test_resource_one_output.float_attribute, err: expected string value for StringValueExact check, got: json\.Number`),
},
},
})
Expand Down Expand Up @@ -340,7 +340,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_Float64_KnownValueWrongValue(t *
),
},
},
ExpectError: regexp.MustCompile("expected value 3.21 for Float64ValueExact check, got: 1.23"),
ExpectError: regexp.MustCompile("error checking value for output at path: test_resource_one_output.float_attribute, err: expected value 3.21 for Float64ValueExact check, got: 1.23"),
},
},
})
Expand Down Expand Up @@ -421,7 +421,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_Int64_KnownValueWrongValue(t *te
),
},
},
ExpectError: regexp.MustCompile("expected value 321 for Int64ValueExact check, got: 123"),
ExpectError: regexp.MustCompile("error checking value for output at path: test_resource_one_output.int_attribute, err: expected value 321 for Int64ValueExact check, got: 123"),
},
},
})
Expand Down Expand Up @@ -511,7 +511,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_List_KnownValueWrongType(t *test
),
},
},
ExpectError: regexp.MustCompile(`expected map\[string\]any value for MapValueExact check, got: \[\]interface {}`),
ExpectError: regexp.MustCompile(`error checking value for output at path: test_resource_one_output.list_attribute, err: expected map\[string\]any value for MapValueExact check, got: \[\]interface {}`),
},
},
})
Expand Down Expand Up @@ -558,7 +558,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_List_KnownValueWrongValue(t *tes
),
},
},
ExpectError: regexp.MustCompile(`list element index 0: expected value value3 for StringValueExact check, got: value1`),
ExpectError: regexp.MustCompile(`error checking value for output at path: test_resource_one_output.list_attribute, err: list element index 0: expected value value3 for StringValueExact check, got: value1`),
},
},
})
Expand Down Expand Up @@ -651,7 +651,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_ListPartial_KnownValueWrongValue
),
},
},
ExpectError: regexp.MustCompile(`list element 0: expected value value3 for StringValueExact check, got: value1`),
ExpectError: regexp.MustCompile(`error checking value for output at path: test_resource_one_output.list_attribute, err: list element 0: expected value value3 for StringValueExact check, got: value1`),
},
},
})
Expand Down Expand Up @@ -738,7 +738,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_ListElements_WrongNum(t *testing
),
},
},
ExpectError: regexp.MustCompile("expected 3 elements for ListElementsExact check, got 2 elements"),
ExpectError: regexp.MustCompile("error checking value for output at path: test_resource_one_output.list_attribute, err: expected 3 elements for ListElementsExact check, got 2 elements"),
},
},
})
Expand Down Expand Up @@ -974,7 +974,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_Map_KnownValueWrongType(t *testi
),
},
},
ExpectError: regexp.MustCompile(`expected \[\]any value for ListValueExact check, got: map\[string\]interface {}`),
ExpectError: regexp.MustCompile(`error checking value for output at path: test_resource_one_output.map_attribute, err: expected \[\]any value for ListValueExact check, got: map\[string\]interface {}`),
},
},
})
Expand Down Expand Up @@ -1021,7 +1021,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_Map_KnownValueWrongValue(t *test
),
},
},
ExpectError: regexp.MustCompile(`missing element key3 for MapValueExact check`),
ExpectError: regexp.MustCompile(`error checking value for output at path: test_resource_one_output.map_attribute, err: missing element key3 for MapValueExact check`),
},
},
})
Expand Down Expand Up @@ -1112,7 +1112,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_MapPartial_KnownValueWrongValue(
),
},
},
ExpectError: regexp.MustCompile(`missing element key3 for MapValuePartial check`),
ExpectError: regexp.MustCompile(`error checking value for output at path: test_resource_one_output.map_attribute, err: missing element key3 for MapValuePartial check`),
},
},
})
Expand Down Expand Up @@ -1199,7 +1199,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_MapElements_WrongNum(t *testing.
),
},
},
ExpectError: regexp.MustCompile("expected 3 elements for MapElementsExact check, got 2 elements"),
ExpectError: regexp.MustCompile("error checking value for output at path: test_resource_one_output.map_attribute, err: expected 3 elements for MapElementsExact check, got 2 elements"),
},
},
})
Expand Down Expand Up @@ -1292,7 +1292,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_Number_KnownValueWrongValue(t *t
),
},
},
ExpectError: regexp.MustCompile("expected value 321 for NumberValueExact check, got: 123"),
ExpectError: regexp.MustCompile("error checking value for output at path: test_resource_one_output.int_attribute, err: expected value 321 for NumberValueExact check, got: 123"),
},
},
})
Expand Down Expand Up @@ -1385,7 +1385,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_Set_KnownValueWrongValue(t *test
),
},
},
ExpectError: regexp.MustCompile(`missing value value3 for SetValueExact check`),
ExpectError: regexp.MustCompile(`error checking value for output at path: test_resource_one_output.set_attribute, err: missing value value3 for SetValueExact check`),
},
},
})
Expand Down Expand Up @@ -1476,7 +1476,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_SetPartial_KnownValueWrongValue(
),
},
},
ExpectError: regexp.MustCompile(`missing value value3 for SetValuePartial check`),
ExpectError: regexp.MustCompile(`error checking value for output at path: test_resource_one_output.set_attribute, err: missing value value3 for SetValuePartial check`),
},
},
})
Expand Down Expand Up @@ -1744,7 +1744,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_String_KnownValueWrongType(t *te
knownvalue.BoolValueExact(true)),
},
},
ExpectError: regexp.MustCompile("expected bool value for BoolValueExact check, got: string"),
ExpectError: regexp.MustCompile("error checking value for output at path: test_resource_one_output.string_attribute, err: expected bool value for BoolValueExact check, got: string"),
},
},
})
Expand Down Expand Up @@ -1784,7 +1784,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_String_KnownValueWrongValue(t *t
knownvalue.StringValueExact("rts")),
},
},
ExpectError: regexp.MustCompile("expected value rts for StringValueExact check, got: str"),
ExpectError: regexp.MustCompile("error checking value for output at path: test_resource_one_output.string_attribute, err: expected value rts for StringValueExact check, got: str"),
},
},
})
Expand Down
38 changes: 19 additions & 19 deletions plancheck/expect_known_output_value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestExpectKnownOutputValue_CheckPlan_AttributeValueNull(t *testing.T) {
),
},
},
ExpectError: regexp.MustCompile("value is null"),
ExpectError: regexp.MustCompile("value is null for output at path: bool_output"),
},
},
})
Expand Down Expand Up @@ -141,7 +141,7 @@ func TestExpectKnownOutputValue_CheckPlan_Bool_KnownValueWrongType(t *testing.T)
),
},
},
ExpectError: regexp.MustCompile(`expected json\.Number value for Float64ValueExact check, got: bool`),
ExpectError: regexp.MustCompile(`error checking value for output at path: bool_output, err: expected json\.Number value for Float64ValueExact check, got: bool`),
},
},
})
Expand Down Expand Up @@ -174,7 +174,7 @@ func TestExpectKnownOutputValue_CheckPlan_Bool_KnownValueWrongValue(t *testing.T
),
},
},
ExpectError: regexp.MustCompile("expected value false for BoolValueExact check, got: true"),
ExpectError: regexp.MustCompile("error checking value for output at path: bool_output, err: expected value false for BoolValueExact check, got: true"),
},
},
})
Expand Down Expand Up @@ -240,7 +240,7 @@ func TestExpectKnownOutputValue_CheckPlan_Float64_KnownValueWrongType(t *testing
),
},
},
ExpectError: regexp.MustCompile(`expected string value for StringValueExact check, got: json\.Number`),
ExpectError: regexp.MustCompile(`error checking value for output at path: float64_output, err: expected string value for StringValueExact check, got: json\.Number`),
},
},
})
Expand Down Expand Up @@ -273,7 +273,7 @@ func TestExpectKnownOutputValue_CheckPlan_Float64_KnownValueWrongValue(t *testin
),
},
},
ExpectError: regexp.MustCompile("expected value 3.21 for Float64ValueExact check, got: 1.23"),
ExpectError: regexp.MustCompile("error checking value for output at path: float64_output, err: expected value 3.21 for Float64ValueExact check, got: 1.23"),
},
},
})
Expand Down Expand Up @@ -338,7 +338,7 @@ func TestExpectKnownOutputValue_CheckPlan_Int64_KnownValueWrongValue(t *testing.
),
},
},
ExpectError: regexp.MustCompile("expected value 321 for Int64ValueExact check, got: 123"),
ExpectError: regexp.MustCompile("error checking value for output at path: int64_output, err: expected value 321 for Int64ValueExact check, got: 123"),
},
},
})
Expand Down Expand Up @@ -412,7 +412,7 @@ func TestExpectKnownOutputValue_CheckPlan_List_KnownValueWrongType(t *testing.T)
),
},
},
ExpectError: regexp.MustCompile(`expected map\[string\]any value for MapValueExact check, got: \[\]interface {}`),
ExpectError: regexp.MustCompile(`error checking value for output at path: list_output, err: expected map\[string\]any value for MapValueExact check, got: \[\]interface {}`),
},
},
})
Expand Down Expand Up @@ -451,7 +451,7 @@ func TestExpectKnownOutputValue_CheckPlan_List_KnownValueWrongValue(t *testing.T
),
},
},
ExpectError: regexp.MustCompile(`list element index 0: expected value value3 for StringValueExact check, got: value1`),
ExpectError: regexp.MustCompile(`error checking value for output at path: list_output, err: list element index 0: expected value value3 for StringValueExact check, got: value1`),
},
},
})
Expand Down Expand Up @@ -528,7 +528,7 @@ func TestExpectKnownOutputValue_CheckPlan_ListPartial_KnownValueWrongValue(t *te
),
},
},
ExpectError: regexp.MustCompile(`list element 0: expected value value3 for StringValueExact check, got: value1`),
ExpectError: regexp.MustCompile(`error checking value for output at path: list_output, err: list element 0: expected value value3 for StringValueExact check, got: value1`),
},
},
})
Expand Down Expand Up @@ -599,7 +599,7 @@ func TestExpectKnownOutputValue_CheckPlan_ListElements_WrongNum(t *testing.T) {
),
},
},
ExpectError: regexp.MustCompile("expected 3 elements for ListElementsExact check, got 2 elements"),
ExpectError: regexp.MustCompile("error checking value for output at path: list_output, err: expected 3 elements for ListElementsExact check, got 2 elements"),
},
},
})
Expand Down Expand Up @@ -795,7 +795,7 @@ func TestExpectKnownOutputValue_CheckPlan_Map_KnownValueWrongType(t *testing.T)
),
},
},
ExpectError: regexp.MustCompile(`expected \[\]any value for ListValueExact check, got: map\[string\]interface {}`),
ExpectError: regexp.MustCompile(`error checking value for output at path: map_output, err: expected \[\]any value for ListValueExact check, got: map\[string\]interface {}`),
},
},
})
Expand Down Expand Up @@ -834,7 +834,7 @@ func TestExpectKnownOutputValue_CheckPlan_Map_KnownValueWrongValue(t *testing.T)
),
},
},
ExpectError: regexp.MustCompile(`missing element key3 for MapValueExact check`),
ExpectError: regexp.MustCompile(`error checking value for output at path: map_output, err: missing element key3 for MapValueExact check`),
},
},
})
Expand Down Expand Up @@ -909,7 +909,7 @@ func TestExpectKnownOutputValue_CheckPlan_MapPartial_KnownValueWrongValue(t *tes
),
},
},
ExpectError: regexp.MustCompile(`missing element key3 for MapValuePartial check`),
ExpectError: regexp.MustCompile(`error checking value for output at path: map_output, err: missing element key3 for MapValuePartial check`),
},
},
})
Expand Down Expand Up @@ -980,7 +980,7 @@ func TestExpectKnownOutputValue_CheckPlan_MapElements_WrongNum(t *testing.T) {
),
},
},
ExpectError: regexp.MustCompile("expected 3 elements for MapElementsExact check, got 2 elements"),
ExpectError: regexp.MustCompile("error checking value for output at path: map_output, err: expected 3 elements for MapElementsExact check, got 2 elements"),
},
},
})
Expand Down Expand Up @@ -1057,7 +1057,7 @@ func TestExpectKnownOutputValue_CheckPlan_Number_KnownValueWrongValue(t *testing
),
},
},
ExpectError: regexp.MustCompile("expected value 321 for NumberValueExact check, got: 123"),
ExpectError: regexp.MustCompile("error checking value for output at path: int64_output, err: expected value 321 for NumberValueExact check, got: 123"),
},
},
})
Expand Down Expand Up @@ -1134,7 +1134,7 @@ func TestExpectKnownOutputValue_CheckPlan_Set_KnownValueWrongValue(t *testing.T)
),
},
},
ExpectError: regexp.MustCompile(`missing value value3 for SetValueExact check`),
ExpectError: regexp.MustCompile(`error checking value for output at path: set_output, err: missing value value3 for SetValueExact check`),
},
},
})
Expand Down Expand Up @@ -1209,7 +1209,7 @@ func TestExpectKnownOutputValue_CheckPlan_SetPartial_KnownValueWrongValue(t *tes
),
},
},
ExpectError: regexp.MustCompile(`missing value value3 for SetValuePartial check`),
ExpectError: regexp.MustCompile(`error checking value for output at path: set_output, err: missing value value3 for SetValuePartial check`),
},
},
})
Expand Down Expand Up @@ -1429,7 +1429,7 @@ func TestExpectKnownOutputValue_CheckPlan_String_KnownValueWrongType(t *testing.
knownvalue.BoolValueExact(true)),
},
},
ExpectError: regexp.MustCompile("expected bool value for BoolValueExact check, got: string"),
ExpectError: regexp.MustCompile("error checking value for output at path: string_output, err: expected bool value for BoolValueExact check, got: string"),
},
},
})
Expand Down Expand Up @@ -1461,7 +1461,7 @@ func TestExpectKnownOutputValue_CheckPlan_String_KnownValueWrongValue(t *testing
knownvalue.StringValueExact("rts")),
},
},
ExpectError: regexp.MustCompile("expected value rts for StringValueExact check, got: str"),
ExpectError: regexp.MustCompile("error checking value for output at path: string_output, err: expected value rts for StringValueExact check, got: str"),
},
},
})
Expand Down
4 changes: 2 additions & 2 deletions plancheck/expect_known_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (e expectKnownValue) CheckPlan(ctx context.Context, req CheckPlanRequest, r
}

if result == nil {
resp.Error = fmt.Errorf("value is null")
resp.Error = fmt.Errorf("value is null for attribute at path: %s.%s", e.resourceAddress, e.attributePath.String())

return
}
Expand All @@ -61,7 +61,7 @@ func (e expectKnownValue) CheckPlan(ctx context.Context, req CheckPlanRequest, r
reflect.Slice,
reflect.String:
if err := e.knownValue.CheckValue(result); err != nil {
resp.Error = err
resp.Error = fmt.Errorf("error checking value for attribute at path: %s.%s, err: %s", e.resourceAddress, e.attributePath.String(), err)

return
}
Expand Down
Loading

0 comments on commit ed9d236

Please sign in to comment.