Allow pruning of unsupported fields in structs in maps
Adds support for traversing into a field that is of type:
map[...]*struct{...}
This is needed to allow java_sdk_library to mark scope specific
properties, e.g. public.annotations as being target build release
specific.
It was necessary to change the Scope field from:
Scope map[*apiScope]scopeProperties
to:
Scope map[*apiScope]*scopeProperties
That is because there is no way in go to change the field of a struct
value of a map. i.e. you cannot do the following, not even using
reflection:
Scope[apiScopePublic].AnnotationsZip = nil
Bug: 204763318
Test: m nothing
Merged-In: Id103f70f55d4202971321ef4925cbec4b55f8136
Change-Id: Id103f70f55d4202971321ef4925cbec4b55f8136
(cherry picked from commit 106a3a4bec
)
This commit is contained in:
@@ -126,11 +126,17 @@ func TestPropertyPrunerByBuildRelease(t *testing.T) {
|
||||
F1_only string `supported_build_releases:"F1"`
|
||||
}
|
||||
|
||||
type mapped struct {
|
||||
Default string
|
||||
T_only string `supported_build_releases:"T"`
|
||||
}
|
||||
|
||||
type testBuildReleasePruner struct {
|
||||
Default string
|
||||
S_and_T_only string `supported_build_releases:"S-T"`
|
||||
T_later string `supported_build_releases:"T+"`
|
||||
Nested nested
|
||||
Mapped map[string]*mapped
|
||||
}
|
||||
|
||||
inputFactory := func() testBuildReleasePruner {
|
||||
@@ -141,6 +147,16 @@ func TestPropertyPrunerByBuildRelease(t *testing.T) {
|
||||
Nested: nested{
|
||||
F1_only: "F1_only",
|
||||
},
|
||||
Mapped: map[string]*mapped{
|
||||
"one": {
|
||||
Default: "one-default",
|
||||
T_only: "one-t-only",
|
||||
},
|
||||
"two": {
|
||||
Default: "two-default",
|
||||
T_only: "two-t-only",
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,6 +185,8 @@ func TestPropertyPrunerByBuildRelease(t *testing.T) {
|
||||
expected := inputFactory()
|
||||
expected.T_later = ""
|
||||
expected.Nested.F1_only = ""
|
||||
expected.Mapped["one"].T_only = ""
|
||||
expected.Mapped["two"].T_only = ""
|
||||
assertJsonEquals(t, expected, testStruct)
|
||||
})
|
||||
|
||||
@@ -189,6 +207,8 @@ func TestPropertyPrunerByBuildRelease(t *testing.T) {
|
||||
|
||||
expected := inputFactory()
|
||||
expected.S_and_T_only = ""
|
||||
expected.Mapped["one"].T_only = ""
|
||||
expected.Mapped["two"].T_only = ""
|
||||
assertJsonEquals(t, expected, testStruct)
|
||||
})
|
||||
|
||||
@@ -200,6 +220,8 @@ func TestPropertyPrunerByBuildRelease(t *testing.T) {
|
||||
expected := inputFactory()
|
||||
expected.S_and_T_only = ""
|
||||
expected.Nested.F1_only = ""
|
||||
expected.Mapped["one"].T_only = ""
|
||||
expected.Mapped["two"].T_only = ""
|
||||
assertJsonEquals(t, expected, testStruct)
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user