fix: enable empty and len rules from testifylint on pkg package
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com> Co-authored-by: Patrick Ohly <patrick.ohly@intel.com>
This commit is contained in:
@@ -51,7 +51,7 @@ func TestProberExistingDriverBeforeInit(t *testing.T) {
|
||||
// Assert
|
||||
// Probe occurs, 1 plugin should be returned, and 2 watches (pluginDir and all its
|
||||
// current subdirectories) registered.
|
||||
assert.Equal(t, 1, len(events))
|
||||
assert.Len(t, events, 1)
|
||||
assert.Equal(t, volume.ProbeAddOrUpdate, events[0].Op)
|
||||
plugDir := pluginDir
|
||||
if goruntime.GOOS == "windows" {
|
||||
@@ -66,7 +66,7 @@ func TestProberExistingDriverBeforeInit(t *testing.T) {
|
||||
// Act
|
||||
events, err = prober.Probe()
|
||||
// Assert
|
||||
assert.Equal(t, 0, len(events))
|
||||
assert.Empty(t, events)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ func TestProberAddRemoveDriver(t *testing.T) {
|
||||
prober.Probe()
|
||||
events, err := prober.Probe()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, 0, len(events))
|
||||
assert.Empty(t, events)
|
||||
|
||||
// Call probe after a file is added. Should return 1 event.
|
||||
|
||||
@@ -93,7 +93,7 @@ func TestProberAddRemoveDriver(t *testing.T) {
|
||||
events, err = prober.Probe()
|
||||
|
||||
// Assert
|
||||
assert.Equal(t, 1, len(events))
|
||||
assert.Len(t, events, 1)
|
||||
assert.Equal(t, volume.ProbeAddOrUpdate, events[0].Op) // 1 newly added
|
||||
assertPathSuffix(t, driverPath, watcher.watches[len(watcher.watches)-1]) // Checks most recent watch
|
||||
assert.NoError(t, err)
|
||||
@@ -103,7 +103,7 @@ func TestProberAddRemoveDriver(t *testing.T) {
|
||||
// Act
|
||||
events, err = prober.Probe()
|
||||
// Assert
|
||||
assert.Equal(t, 0, len(events))
|
||||
assert.Empty(t, events)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Call probe after a non-driver file is added in a subdirectory. should return 1 event.
|
||||
@@ -115,7 +115,7 @@ func TestProberAddRemoveDriver(t *testing.T) {
|
||||
events, err = prober.Probe()
|
||||
|
||||
// Assert
|
||||
assert.Equal(t, 1, len(events))
|
||||
assert.Len(t, events, 1)
|
||||
assert.Equal(t, volume.ProbeAddOrUpdate, events[0].Op)
|
||||
assert.NoError(t, err)
|
||||
|
||||
@@ -123,7 +123,7 @@ func TestProberAddRemoveDriver(t *testing.T) {
|
||||
// Act
|
||||
events, err = prober.Probe()
|
||||
// Assert
|
||||
assert.Equal(t, 0, len(events))
|
||||
assert.Empty(t, events)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Call probe after a subdirectory is added in a driver directory. should return 1 event.
|
||||
@@ -135,7 +135,7 @@ func TestProberAddRemoveDriver(t *testing.T) {
|
||||
events, err = prober.Probe()
|
||||
|
||||
// Assert
|
||||
assert.Equal(t, 1, len(events))
|
||||
assert.Len(t, events, 1)
|
||||
assert.Equal(t, volume.ProbeAddOrUpdate, events[0].Op)
|
||||
assert.NoError(t, err)
|
||||
|
||||
@@ -143,7 +143,7 @@ func TestProberAddRemoveDriver(t *testing.T) {
|
||||
// Act
|
||||
events, err = prober.Probe()
|
||||
// Assert
|
||||
assert.Equal(t, 0, len(events))
|
||||
assert.Empty(t, events)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Call probe after a subdirectory is removed in a driver directory. should return 1 event.
|
||||
@@ -154,7 +154,7 @@ func TestProberAddRemoveDriver(t *testing.T) {
|
||||
events, err = prober.Probe()
|
||||
|
||||
// Assert
|
||||
assert.Equal(t, 1, len(events))
|
||||
assert.Len(t, events, 1)
|
||||
assert.Equal(t, volume.ProbeAddOrUpdate, events[0].Op)
|
||||
assert.NoError(t, err)
|
||||
|
||||
@@ -162,7 +162,7 @@ func TestProberAddRemoveDriver(t *testing.T) {
|
||||
// Act
|
||||
events, err = prober.Probe()
|
||||
// Assert
|
||||
assert.Equal(t, 0, len(events))
|
||||
assert.Empty(t, events)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Call probe after a driver executable and driver directory is remove. should return 1 event.
|
||||
@@ -172,13 +172,13 @@ func TestProberAddRemoveDriver(t *testing.T) {
|
||||
watcher.TriggerEvent(fsnotify.Remove, driverPath)
|
||||
// Act and Assert: 1 ProbeRemove event
|
||||
events, err = prober.Probe()
|
||||
assert.Equal(t, 1, len(events))
|
||||
assert.Len(t, events, 1)
|
||||
assert.Equal(t, volume.ProbeRemove, events[0].Op)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Act and Assert: 0 event
|
||||
events, err = prober.Probe()
|
||||
assert.Equal(t, 0, len(events))
|
||||
assert.Empty(t, events)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ func TestEmptyPluginDir(t *testing.T) {
|
||||
events, err := prober.Probe()
|
||||
|
||||
// Assert
|
||||
assert.Equal(t, 0, len(events))
|
||||
assert.Empty(t, events)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ func TestRemovePluginDir(t *testing.T) {
|
||||
// Act: The handler triggered by the above events should have already handled the event appropriately.
|
||||
|
||||
// Assert
|
||||
assert.Equal(t, 3, len(watcher.watches)) // 2 from initial setup, 1 from new watch.
|
||||
assert.Len(t, watcher.watches, 3) // 2 from initial setup, 1 from new watch.
|
||||
plugDir := pluginDir
|
||||
if goruntime.GOOS == "windows" {
|
||||
plugDir = "\\flexvolume"
|
||||
@@ -229,7 +229,7 @@ func TestNestedDriverDir(t *testing.T) {
|
||||
// Arrange
|
||||
_, fs, watcher, _ := initTestEnvironment(t)
|
||||
// Assert
|
||||
assert.Equal(t, 2, len(watcher.watches)) // 2 from initial setup
|
||||
assert.Len(t, watcher.watches, 2) // 2 from initial setup
|
||||
|
||||
// test add testDriverName
|
||||
testDriverName := "testDriverName"
|
||||
@@ -237,7 +237,7 @@ func TestNestedDriverDir(t *testing.T) {
|
||||
fs.MkdirAll(testDriverPath, 0777)
|
||||
watcher.TriggerEvent(fsnotify.Create, testDriverPath)
|
||||
// Assert
|
||||
assert.Equal(t, 3, len(watcher.watches)) // 2 from initial setup, 1 from new watch.
|
||||
assert.Len(t, watcher.watches, 3) // 2 from initial setup, 1 from new watch.
|
||||
assertPathSuffix(t, testDriverPath, watcher.watches[len(watcher.watches)-1])
|
||||
|
||||
// test add nested subdir inside testDriverName
|
||||
@@ -248,7 +248,7 @@ func TestNestedDriverDir(t *testing.T) {
|
||||
fs.MkdirAll(subdirPath, 0777)
|
||||
watcher.TriggerEvent(fsnotify.Create, subdirPath)
|
||||
// Assert
|
||||
assert.Equal(t, 4+i, len(watcher.watches)) // 3 + newly added
|
||||
assert.Len(t, watcher.watches, 4+i) // 3 + newly added
|
||||
assertPathSuffix(t, subdirPath, watcher.watches[len(watcher.watches)-1])
|
||||
basePath = subdirPath
|
||||
}
|
||||
@@ -272,13 +272,13 @@ func TestProberMultipleEvents(t *testing.T) {
|
||||
events, err := prober.Probe()
|
||||
|
||||
// Assert
|
||||
assert.Equal(t, 2, len(events))
|
||||
assert.Len(t, events, 2)
|
||||
assert.Equal(t, volume.ProbeAddOrUpdate, events[0].Op)
|
||||
assert.Equal(t, volume.ProbeAddOrUpdate, events[1].Op)
|
||||
assert.NoError(t, err)
|
||||
for i := 0; i < iterations-1; i++ {
|
||||
events, err = prober.Probe()
|
||||
assert.Equal(t, 0, len(events))
|
||||
assert.Empty(t, events)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
}
|
||||
@@ -321,7 +321,7 @@ func TestProberSuccessAndError(t *testing.T) {
|
||||
events, err := prober.Probe()
|
||||
|
||||
// Assert
|
||||
assert.Equal(t, 1, len(events))
|
||||
assert.Len(t, events, 1)
|
||||
assert.Equal(t, volume.ProbeAddOrUpdate, events[0].Op)
|
||||
assert.Equal(t, driverName, events[0].PluginName)
|
||||
assert.Error(t, err)
|
||||
|
||||
Reference in New Issue
Block a user