Allow extractCommonProperties to return an error

Refactoring in preparation for follow up changes.

Also:
* Adds a new AssertErrorMessageEquals() helper method.
* Improved error reporting in the accessor and added name to
  extractorProperty to ensure meaningful errors are reported.
* Added String() string method to propertiesContainer.
* Reports errors using the field name as the errors are not really
  fixable by developers and it is more meaningful to the build team.

Bug: 155628860
Test: m nothing
Merged-In: I5c5b8436bcbc39e4e7cd35df2577b2dac53e702a
Change-Id: I5c5b8436bcbc39e4e7cd35df2577b2dac53e702a
(cherry picked from commit 4b8b79394f)
This commit is contained in:
Paul Duffin
2020-05-06 12:35:38 +01:00
parent d7acc7b73e
commit 1c58f5795a
3 changed files with 83 additions and 11 deletions

View File

@@ -173,6 +173,15 @@ func (h *TestHelper) AssertStringEquals(message string, expected string, actual
}
}
func (h *TestHelper) AssertErrorMessageEquals(message string, expected string, actual error) {
h.t.Helper()
if actual == nil {
h.t.Errorf("Expected error but was nil")
} else if actual.Error() != expected {
h.t.Errorf("%s: expected %s, actual %s", message, expected, actual.Error())
}
}
func (h *TestHelper) AssertTrimmedStringEquals(message string, expected string, actual string) {
h.t.Helper()
h.AssertStringEquals(message, strings.TrimSpace(expected), strings.TrimSpace(actual))