prpfiles can be exluded with ~ prefix

Used the ~ as prefix as ! will mess up with yaml syntax

Signed-off-by: Christian Goll <cgoll@suse.com>
This commit is contained in:
Christian Goll
2023-10-09 16:46:24 +02:00
committed by Jonathon Anderson
parent 85eaa20708
commit d6ef1a86ce
3 changed files with 65 additions and 16 deletions

View File

@@ -171,6 +171,13 @@ nodes:
profiles:
- profile1
- profile2
node5:
runtime overlay:
- n1o1
- ~p1o2
profiles:
- profile1
- profile2
`
assert := assert.New(t)
var ymlSrc NodeYaml
@@ -194,4 +201,21 @@ nodes:
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.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}")
}
func Test_negated_list(t *testing.T) {
assert := assert.New(t)
list := []string{"tok1", "tok2"}
list2 := []string{"tok1", "tok2", "~tok3"}
list3 := []string{"tok1", "tok2", "~tok3", "~tok3"}
list4 := []string{"tok1", "tok2", "~tok3", "~tok4"}
list5 := []string{"tok1", "tok3", "~tok3", "tok2"}
assert.Equal([]string{"tok3"}, negList(list2))
assert.Equal(list, cleanList(list2))
assert.Equal(list, cleanList(list3))
assert.Equal(list, cleanList(list4))
assert.Equal(list, cleanList(list5))
}

View File

@@ -238,24 +238,46 @@ func (ent *Entry) GetB() bool {
}
}
// returns all negated elemets which are marked with ! as prefix
// from a list
func negList(list []string) (ret []string) {
for _, tok := range list {
if strings.HasPrefix(tok, "~") {
ret = append(ret, tok[1:])
}
}
return
}
// clean a list from negated tokens
func cleanList(list []string) (ret []string) {
neg := negList(list)
for _, listTok := range list {
notNegate := true
for _, negTok := range neg {
if listTok == negTok || listTok == "~"+negTok {
notNegate = false
}
}
if notNegate {
ret = append(ret, listTok)
}
}
return ret
}
/*
Returns a string slice created from a comma seperated list of the value.
Returns a string slice created from a comma separated list of the value.
*/
func (ent *Entry) GetSlice() []string {
var retval []string
if len(ent.value) != 0 {
retval = ent.value
}
if len(ent.altvalue) != 0 {
retval = append(retval, ent.altvalue...)
}
retval := append(ent.value, ent.altvalue...)
if len(retval) != 0 {
return retval
return cleanList(retval)
}
if len(ent.def) != 0 {
return ent.def
}
return retval
return []string{}
}
/*
@@ -328,11 +350,13 @@ alternative is presend. Default value is in '()'. If
nothing is defined '--' is returned.
*/
func (ent *Entry) Print() (ret string) {
if len(ent.value) != 0 {
ret = strings.Join(ent.value, ",")
}
if len(ent.altvalue) != 0 {
ret = strings.Join(append(ent.value, ent.altvalue...), ",")
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