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
Change-Id: I5c5b8436bcbc39e4e7cd35df2577b2dac53e702a
This commit is contained in:
Paul Duffin
2020-05-06 12:35:38 +01:00
parent 425b0eacaa
commit 4b8b79394f
3 changed files with 83 additions and 11 deletions

View File

@@ -231,6 +231,7 @@ type EmbeddedPropertiesStruct struct {
}
type testPropertiesStruct struct {
name string
private string
Public_Kept string `sdk:"keep"`
S_Common string
@@ -246,10 +247,17 @@ func (p *testPropertiesStruct) optimizableProperties() interface{} {
return p
}
func (p *testPropertiesStruct) String() string {
return p.name
}
var _ propertiesContainer = (*testPropertiesStruct)(nil)
func TestCommonValueOptimization(t *testing.T) {
common := &testPropertiesStruct{}
common := &testPropertiesStruct{name: "common"}
structs := []propertiesContainer{
&testPropertiesStruct{
name: "struct-0",
private: "common",
Public_Kept: "common",
S_Common: "common",
@@ -264,6 +272,7 @@ func TestCommonValueOptimization(t *testing.T) {
},
},
&testPropertiesStruct{
name: "struct-1",
private: "common",
Public_Kept: "common",
S_Common: "common",
@@ -285,6 +294,7 @@ func TestCommonValueOptimization(t *testing.T) {
h := TestHelper{t}
h.AssertDeepEquals("common properties not correct",
&testPropertiesStruct{
name: "common",
private: "",
Public_Kept: "",
S_Common: "common",
@@ -302,6 +312,7 @@ func TestCommonValueOptimization(t *testing.T) {
h.AssertDeepEquals("updated properties[0] not correct",
&testPropertiesStruct{
name: "struct-0",
private: "common",
Public_Kept: "common",
S_Common: "",
@@ -319,6 +330,7 @@ func TestCommonValueOptimization(t *testing.T) {
h.AssertDeepEquals("updated properties[1] not correct",
&testPropertiesStruct{
name: "struct-1",
private: "common",
Public_Kept: "common",
S_Common: "",