config: return correct error

_conmonVersionFormatErr is a format string and it needs an error
argument.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano 2022-08-16 16:12:39 +02:00
parent 815258862e
commit e4edaae628
2 changed files with 4 additions and 2 deletions

View File

@ -459,7 +459,7 @@ func probeConmon(conmonBinary string) error {
matches := r.FindStringSubmatch(out.String())
if len(matches) != 5 {
return errors.New(_conmonVersionFormatErr)
return fmt.Errorf(_conmonVersionFormatErr, errors.New("invalid version format"))
}
major, err := strconv.Atoi(matches[2])

View File

@ -1,6 +1,7 @@
package config
import (
"errors"
"fmt"
"io/ioutil"
"os"
@ -57,7 +58,8 @@ func TestProbeConmon(t *testing.T) {
msg: "failure invalid format",
output: "invalid",
assert: func(err error, msg string) {
assert.EqualError(t, err, _conmonVersionFormatErr, msg)
expectedErr := fmt.Errorf(_conmonVersionFormatErr, errors.New("invalid version format"))
assert.Equal(t, err, expectedErr, msg)
},
},
} {