build: improve attachments resolution.
This commit is contained in:
parent
38d310c62a
commit
7a70252e26
2 changed files with 30 additions and 7 deletions
|
|
@ -67,13 +67,8 @@ func (p *AppArmorProfile) resolve(str string) []string {
|
||||||
if len(match) > 1 {
|
if len(match) > 1 {
|
||||||
variable := match[0]
|
variable := match[0]
|
||||||
varname := match[1]
|
varname := match[1]
|
||||||
if len(p.Variables[varname]) > 1 {
|
for _, value := range p.Variables[varname] {
|
||||||
for _, value := range p.Variables[varname] {
|
newVar := strings.ReplaceAll(str, variable, value)
|
||||||
newVar := strings.ReplaceAll(str, variable, value)
|
|
||||||
vars = append(vars, p.resolve(newVar)...)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
newVar := strings.ReplaceAll(str, variable, p.Variables[varname][0])
|
|
||||||
vars = append(vars, p.resolve(newVar)...)
|
vars = append(vars, p.resolve(newVar)...)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -93,6 +93,34 @@ func TestAppArmorProfile_ParseVariables(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAppArmorProfile_resolve(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
variables map[string][]string
|
||||||
|
input string
|
||||||
|
want []string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "empty",
|
||||||
|
variables: Tunables,
|
||||||
|
input: "@{}",
|
||||||
|
want: []string{"@{}"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
p := &AppArmorProfile{
|
||||||
|
Content: "",
|
||||||
|
Variables: tt.variables,
|
||||||
|
Attachments: []string{},
|
||||||
|
}
|
||||||
|
if got := p.resolve(tt.input); !reflect.DeepEqual(got, tt.want) {
|
||||||
|
t.Errorf("AppArmorProfile.resolve() = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestAppArmorProfile_ResolveAttachments(t *testing.T) {
|
func TestAppArmorProfile_ResolveAttachments(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue