mount-utils: fix linter warnings in tests

Mostly "return value is not checked".

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin 2023-06-07 14:18:08 -07:00
parent 8ced101db5
commit cfbc5dc54f
2 changed files with 18 additions and 11 deletions

View File

@ -41,8 +41,7 @@ func TestDoCleanupMountPoint(t *testing.T) {
// and error if the prepare function encountered a fatal error. // and error if the prepare function encountered a fatal error.
prepareMnt func(base string) (MountPoint, error, error) prepareMnt func(base string) (MountPoint, error, error)
// Function that prepares the FakeMounter for the test. // Function that prepares the FakeMounter for the test.
// Returns error if prepareMntr function encountered a fatal error. prepareMntr func(mntr *FakeMounter)
prepareMntr func(mntr *FakeMounter) error
expectErr bool expectErr bool
}{ }{
"mount-ok": { "mount-ok": {
@ -94,9 +93,8 @@ func TestDoCleanupMountPoint(t *testing.T) {
} }
return MountPoint{Device: "/dev/sdb", Path: path}, nil, nil return MountPoint{Device: "/dev/sdb", Path: path}, nil, nil
}, },
prepareMntr: func(mntr *FakeMounter) error { prepareMntr: func(mntr *FakeMounter) {
mntr.WithSkipMountPointCheck() mntr.WithSkipMountPointCheck()
return nil
}, },
expectErr: false, expectErr: false,
}, },

View File

@ -30,6 +30,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/stretchr/testify/assert"
utilexec "k8s.io/utils/exec" utilexec "k8s.io/utils/exec"
testexec "k8s.io/utils/exec/testing" testexec "k8s.io/utils/exec/testing"
) )
@ -436,15 +437,17 @@ func TestSearchMountPoints(t *testing.T) {
defer os.Remove(tmpFile.Name()) defer os.Remove(tmpFile.Name())
defer tmpFile.Close() defer tmpFile.Close()
for _, v := range testcases { for _, v := range testcases {
tmpFile.Truncate(0) assert.NoError(t, tmpFile.Truncate(0))
tmpFile.Seek(0, 0) _, err := tmpFile.Seek(0, 0)
tmpFile.WriteString(v.mountInfos) assert.NoError(t, err)
tmpFile.Sync() _, err = tmpFile.WriteString(v.mountInfos)
assert.NoError(t, err)
assert.NoError(t, tmpFile.Sync())
refs, err := SearchMountPoints(v.source, tmpFile.Name()) refs, err := SearchMountPoints(v.source, tmpFile.Name())
if !reflect.DeepEqual(refs, v.expectedRefs) { if !reflect.DeepEqual(refs, v.expectedRefs) {
t.Errorf("test %q: expected Refs: %#v, got %#v", v.name, v.expectedRefs, refs) t.Errorf("test %q: expected Refs: %#v, got %#v", v.name, v.expectedRefs, refs)
} }
if !reflect.DeepEqual(err, v.expectedErr) { if err != v.expectedErr {
t.Errorf("test %q: expected err: %v, got %v", v.name, v.expectedErr, err) t.Errorf("test %q: expected err: %v, got %v", v.name, v.expectedErr, err)
} }
} }
@ -703,7 +706,10 @@ func TestFormatConcurrency(t *testing.T) {
// for one to be released // for one to be released
for i := 0; i < tc.max+1; i++ { for i := 0; i < tc.max+1; i++ {
go func() { go func() {
mounter.format(fstype, nil) _, err := mounter.format(fstype, nil)
if err != nil {
t.Errorf("format(%q): %v", fstype, err)
}
}() }()
} }
@ -778,7 +784,10 @@ func TestFormatTimeout(t *testing.T) {
for i := 0; i < maxConcurrency+1; i++ { for i := 0; i < maxConcurrency+1; i++ {
go func() { go func() {
mounter.format(fstype, nil) _, err := mounter.format(fstype, nil)
if err != nil {
t.Errorf("format(%q): %v", fstype, err)
}
}() }()
} }