Simplified slice ordering fix and extended for runtime overlay

- Extends #1357
- Fixes #1259

Signed-off-by: Jonathon Anderson <janderson@ciq.com>
This commit is contained in:
Jonathon Anderson
2024-09-04 19:57:52 -06:00
parent bfa6ad6be8
commit 4a5c1cad12
6 changed files with 72 additions and 123 deletions

View File

@@ -191,19 +191,19 @@ nodes:
}
assert.Contains(nodemap, "node1")
assert.ElementsMatch(nodemap["node1"].RuntimeOverlay.GetSlice(), []string{"p1o1", "p1o2"})
assert.Equal(nodemap["node1"].RuntimeOverlay.Print(), "p1o1,p1o2")
assert.Equal("p1o1,p1o2", nodemap["node1"].RuntimeOverlay.Print())
assert.Contains(nodemap, "node2")
assert.ElementsMatch(nodemap["node2"].RuntimeOverlay.GetSlice(), []string{"p1o1", "p1o2", "p2o1", "p2o2"})
assert.Equal(nodemap["node2"].RuntimeOverlay.Print(), "p1o1,p1o2,p2o1,p2o2")
assert.Equal("p1o1,p1o2,p2o1,p2o2", nodemap["node2"].RuntimeOverlay.Print())
assert.Contains(nodemap, "node3")
assert.ElementsMatch(nodemap["node3"].RuntimeOverlay.GetSlice(), []string{"p1o1", "p1o2", "n1o1", "n1o2"})
assert.Equal(nodemap["node3"].RuntimeOverlay.Print(), "n1o1,n1o2,p1o1,p1o2")
assert.Equal("p1o1,p1o2,n1o1,n1o2", nodemap["node3"].RuntimeOverlay.Print())
assert.Contains(nodemap, "node4")
assert.ElementsMatch(nodemap["node4"].RuntimeOverlay.GetSlice(), []string{"p1o1", "p1o2", "p2o1", "p2o2", "n1o1", "n1o2"})
assert.Equal(nodemap["node4"].RuntimeOverlay.Print(), "n1o1,n1o2,p1o1,p1o2,p2o1,p2o2")
assert.Equal("p1o1,p1o2,p2o1,p2o2,n1o1,n1o2", nodemap["node4"].RuntimeOverlay.Print())
assert.Contains(nodemap, "node5")
assert.ElementsMatch(nodemap["node5"].RuntimeOverlay.GetSlice(), []string{"p1o1", "p2o1", "p2o2", "n1o1"})
assert.Equal(nodemap["node5"].RuntimeOverlay.Print(), "n1o1,p1o1,p2o1,p2o2 ~{p1o2}")
assert.Equal("p1o1,p2o1,p2o2,n1o1 ~{p1o2}", nodemap["node5"].RuntimeOverlay.Print())
}
func Test_negated_list(t *testing.T) {

View File

@@ -32,19 +32,11 @@ func recursiveFields(obj interface{}, emptyFields bool, prefix string) (output [
if typeObj.Elem().Field(i).Type == reflect.TypeOf(Entry{}) {
myField := valObj.Elem().Field(i).Interface().(Entry)
if emptyFields || myField.Get() != "" {
if typeObj.Elem().Field(i).Name == "SystemOverlay" {
output = append(output, NodeFields{
Field: prefix + typeObj.Elem().Field(i).Name,
Source: myField.Source(),
Value: myField.PrintPreferAlt(),
})
} else {
output = append(output, NodeFields{
Field: prefix + typeObj.Elem().Field(i).Name,
Source: myField.Source(),
Value: myField.Print(),
})
}
output = append(output, NodeFields{
Field: prefix + typeObj.Elem().Field(i).Name,
Source: myField.Source(),
Value: myField.Print(),
})
}
} else if typeObj.Elem().Field(i).Type == reflect.TypeOf(map[string]*Entry{}) {
for key, val := range valObj.Elem().Field(i).Interface().(map[string]*Entry) {

View File

@@ -277,17 +277,6 @@ func cleanList(list []string) (ret []string) {
Returns a string slice created from a comma separated list of the value.
*/
func (ent *Entry) GetSlice() []string {
retval := append(ent.value, ent.altvalue...)
if len(retval) != 0 {
return cleanList(retval)
}
if len(ent.def) != 0 {
return ent.def
}
return []string{}
}
func (ent *Entry) GetSlicePreferAlt() []string {
retval := append(ent.altvalue, ent.value...)
if len(retval) != 0 {
return cleanList(retval)
@@ -378,43 +367,6 @@ func (ent *Entry) Print() string {
if len(ent.def) != 0 {
return "(" + ent.def[0] + ")"
}
} else {
var ret string
if len(ent.value) != 0 || len(ent.altvalue) != 0 {
combList := append(ent.value, ent.altvalue...)
ret = strings.Join(cleanList(combList), ",")
if len(negList(combList)) > 0 {
ret += " ~{" + strings.Join(negList(combList), ",") + "}"
}
}
if ret != "" {
return ret
}
if len(ent.def) != 0 {
return "(" + strings.Join(ent.def, ",") + ")"
}
}
return "--"
}
/* Gets the the entry of the value in following order
* profile value if set
* node value if set
* default value if set
*/
func (ent *Entry) PrintPreferAlt() string {
if !ent.isSlice {
if len(ent.altvalue) != 0 {
return ent.altvalue[0]
}
if len(ent.value) != 0 {
return ent.value[0]
}
if len(ent.def) != 0 {
return "(" + ent.def[0] + ")"
}
} else {
var ret string
if len(ent.value) != 0 || len(ent.altvalue) != 0 {