Skip to content

Commit

Permalink
fix(tests): fix buggy tests in probe and sysfs (#593)
Browse files Browse the repository at this point in the history
- fix sysfs tests to cleanup after finishing. tests were failing when
run the second time after passing for the first time.
- skip `TestUdevProbe` in package probe if disk uuid cannot be
generated
- fix `TestFillDiskDetails` in package probe to correctly set
expected dev links

Signed-off-by: Aditya Jain <[email protected]>
  • Loading branch information
z0marlin authored Jun 2, 2021
1 parent a1e6bb0 commit 973d805
Show file tree
Hide file tree
Showing 3 changed files with 188 additions and 106 deletions.
2 changes: 2 additions & 0 deletions changelogs/unreleased/593-z0marlin
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix tests in probe and syspath packages

36 changes: 22 additions & 14 deletions cmd/ndm_daemonset/probe/udevprobe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ package probe

import (
"errors"
"github.com/openebs/node-disk-manager/blockdevice"
"sync"
"testing"

"github.com/openebs/node-disk-manager/blockdevice"
"github.com/openebs/node-disk-manager/cmd/ndm_daemonset/controller"
apis "github.com/openebs/node-disk-manager/pkg/apis/openebs/v1alpha1"
libudevwrapper "github.com/openebs/node-disk-manager/pkg/udev"
Expand Down Expand Up @@ -113,14 +113,18 @@ func TestFillDiskDetails(t *testing.T) {
expectedDiskInfo.DeviceAttributes.WWN = mockOsDiskDetails.Wwn
expectedDiskInfo.PartitionInfo.PartitionTableType = mockOsDiskDetails.PartTableType
expectedDiskInfo.DeviceAttributes.IDType = mockOsDiskDetails.IdType
expectedDiskInfo.DevLinks = append(expectedDiskInfo.DevLinks, blockdevice.DevLink{
Kind: libudevwrapper.BY_ID_LINK,
Links: mockOsDiskDetails.ByIdDevLinks,
})
expectedDiskInfo.DevLinks = append(expectedDiskInfo.DevLinks, blockdevice.DevLink{
Kind: libudevwrapper.BY_PATH_LINK,
Links: mockOsDiskDetails.ByPathDevLinks,
})
if len(mockOsDiskDetails.ByIdDevLinks) > 0 {
expectedDiskInfo.DevLinks = append(expectedDiskInfo.DevLinks, blockdevice.DevLink{
Kind: libudevwrapper.BY_ID_LINK,
Links: mockOsDiskDetails.ByIdDevLinks,
})
}
if len(mockOsDiskDetails.ByPathDevLinks) > 0 {
expectedDiskInfo.DevLinks = append(expectedDiskInfo.DevLinks, blockdevice.DevLink{
Kind: libudevwrapper.BY_PATH_LINK,
Links: mockOsDiskDetails.ByPathDevLinks,
})
}

// The devlinks are compared separately as the ordering of devlinks can be different in some systems
// eg: ubuntu 20.04 in github actions
Expand Down Expand Up @@ -186,7 +190,7 @@ func TestUdevProbe(t *testing.T) {
}
probeEvent.addBlockDeviceEvent(eventDetails)
// Retrieve disk resource
uuid, _ := generateUUID(*deviceDetails)
uuid, ok := generateUUID(*deviceDetails)
cdr1, err1 := fakeController.GetBlockDevice(uuid)
fakeDr, err := mockOsDiskToAPI()
if err != nil {
Expand All @@ -197,17 +201,21 @@ func TestUdevProbe(t *testing.T) {
fakeDr.ObjectMeta.Labels[controller.NDMDeviceTypeKey] = "blockdevice"
fakeDr.ObjectMeta.Labels[controller.NDMManagedKey] = controller.TrueString
tests := map[string]struct {
actualDisk apis.BlockDevice
actualDisk *apis.BlockDevice
expectedDisk apis.BlockDevice
actualError error
expectedError error
}{
"add event for resource with 'fake-disk-uid' uuid": {actualDisk: *cdr1, expectedDisk: fakeDr, actualError: err1, expectedError: nil},
"add event for resource with 'fake-disk-uid' uuid": {actualDisk: cdr1, expectedDisk: fakeDr, actualError: err1, expectedError: nil},
}
for name, test := range tests {
t.Run(name, func(t *testing.T) {
compareBlockDevice(t, test.expectedDisk, test.actualDisk)
assert.Equal(t, test.expectedError, test.actualError)
if !ok {
assert.Nil(t, cdr1)
} else {
compareBlockDevice(t, test.expectedDisk, *test.actualDisk)
assert.Equal(t, test.expectedError, test.actualError)
}
})
}
}
Expand Down
Loading

0 comments on commit 973d805

Please sign in to comment.