Fix a bug with hook ALWAYS matching with a process

When a non-nil process was used and a hook was set to match
always, this would not actually match. Fix this.

Fixes: #1308

Signed-off-by: Matthew Heon <matthew.heon@gmail.com>

Closes: #1311
Approved by: rhatdan
This commit is contained in:
Matthew Heon 2018-08-21 09:23:28 -04:00 committed by Atomic Bot
parent 149481a571
commit b4420e22fc
2 changed files with 15 additions and 9 deletions

View File

@ -74,7 +74,7 @@ func (when *When) Match(config *rspec.Spec, annotations map[string]string, hasBi
} }
} }
if config.Process != nil { if config.Process != nil && len(when.Commands) > 0 {
if len(config.Process.Args) == 0 { if len(config.Process.Args) == 0 {
return false, errors.New("process.args must have at least one entry") return false, errors.New("process.args must have at least one entry")
} }

View File

@ -24,9 +24,14 @@ func TestNoMatch(t *testing.T) {
func TestAlways(t *testing.T) { func TestAlways(t *testing.T) {
config := &rspec.Spec{} config := &rspec.Spec{}
processStruct := &rspec.Process{
Args: []string{"/bin/sh", "a", "b"},
}
for _, always := range []bool{true, false} { for _, always := range []bool{true, false} {
for _, or := range []bool{true, false} { for _, or := range []bool{true, false} {
t.Run(fmt.Sprintf("always %t, or %t", always, or), func(t *testing.T) { for _, process := range []*rspec.Process{processStruct, nil} {
t.Run(fmt.Sprintf("always %t, or %t, has process %t", always, or, (process != nil)), func(t *testing.T) {
config.Process = process
when := When{Always: &always, Or: or} when := When{Always: &always, Or: or}
match, err := when.Match(config, map[string]string{}, false) match, err := when.Match(config, map[string]string{}, false)
if err != nil { if err != nil {
@ -36,6 +41,7 @@ func TestAlways(t *testing.T) {
}) })
} }
} }
}
} }
func TestHasBindMountsAnd(t *testing.T) { func TestHasBindMountsAnd(t *testing.T) {