Skip to content

Commit

Permalink
mount-utils: fix linter warnings in tests
Browse files Browse the repository at this point in the history
Mostly "return value is not checked".

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed Jun 14, 2023
1 parent 8ced101 commit cfbc5dc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
6 changes: 2 additions & 4 deletions staging/src/k8s.io/mount-utils/mount_helper_test.go
Expand Up @@ -41,8 +41,7 @@ func TestDoCleanupMountPoint(t *testing.T) {
// and error if the prepare function encountered a fatal error.
prepareMnt func(base string) (MountPoint, error, error)
// Function that prepares the FakeMounter for the test.
// Returns error if prepareMntr function encountered a fatal error.
prepareMntr func(mntr *FakeMounter) error
prepareMntr func(mntr *FakeMounter)
expectErr bool
}{
"mount-ok": {
Expand Down Expand Up @@ -94,9 +93,8 @@ func TestDoCleanupMountPoint(t *testing.T) {
}
return MountPoint{Device: "/dev/sdb", Path: path}, nil, nil
},
prepareMntr: func(mntr *FakeMounter) error {
prepareMntr: func(mntr *FakeMounter) {
mntr.WithSkipMountPointCheck()
return nil
},
expectErr: false,
},
Expand Down
23 changes: 16 additions & 7 deletions staging/src/k8s.io/mount-utils/mount_linux_test.go
Expand Up @@ -30,6 +30,7 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
utilexec "k8s.io/utils/exec"
testexec "k8s.io/utils/exec/testing"
)
Expand Down Expand Up @@ -436,15 +437,17 @@ func TestSearchMountPoints(t *testing.T) {
defer os.Remove(tmpFile.Name())
defer tmpFile.Close()
for _, v := range testcases {
tmpFile.Truncate(0)
tmpFile.Seek(0, 0)
tmpFile.WriteString(v.mountInfos)
tmpFile.Sync()
assert.NoError(t, tmpFile.Truncate(0))
_, err := tmpFile.Seek(0, 0)
assert.NoError(t, err)
_, err = tmpFile.WriteString(v.mountInfos)
assert.NoError(t, err)
assert.NoError(t, tmpFile.Sync())
refs, err := SearchMountPoints(v.source, tmpFile.Name())
if !reflect.DeepEqual(refs, v.expectedRefs) {
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)
}
}
Expand Down Expand Up @@ -703,7 +706,10 @@ func TestFormatConcurrency(t *testing.T) {
// for one to be released
for i := 0; i < tc.max+1; i++ {
go func() {
mounter.format(fstype, nil)
_, err := mounter.format(fstype, nil)
if err != nil {
t.Errorf("format(%q): %v", fstype, err)
}
}()
}

Expand Down Expand Up @@ -778,7 +784,10 @@ func TestFormatTimeout(t *testing.T) {

for i := 0; i < maxConcurrency+1; i++ {
go func() {
mounter.format(fstype, nil)
_, err := mounter.format(fstype, nil)
if err != nil {
t.Errorf("format(%q): %v", fstype, err)
}
}()
}

Expand Down

0 comments on commit cfbc5dc

Please sign in to comment.