Skip to content

Commit

Permalink
Add tests for manually mounted volumes (and other weird paths)
Browse files Browse the repository at this point in the history
Signed-off-by: Connor Catlett <[email protected]>
  • Loading branch information
ConnorJC3 committed Mar 2, 2023
1 parent c4baaa7 commit ed528b2
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions pkg/cloud/devicemanager/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,60 @@ func TestNewDevice(t *testing.T) {
}
}

func TestNewDeviceWithExistingDevice(t *testing.T) {
testCases := []struct {
name string
existingID string
existingPath string
volumeID string
expectedPath string
}{
{
name: "success: different volumes",
existingID: "vol-1",
existingPath: "/dev/xvdba",
volumeID: "vol-2",
expectedPath: "/dev/xvdbb",
},
{
name: "success: same volumes",
existingID: "vol-1",
existingPath: "/dev/xvdba",
volumeID: "vol-1",
expectedPath: "/dev/xvdba",
},
{
name: "success: same volumes with /dev/sdX path",
existingID: "vol-3",
existingPath: "/dev/sdf",
volumeID: "vol-3",
expectedPath: "/dev/sdf",
},
{
name: "success: same volumes with weird path",
existingID: "vol-42",
existingPath: "/weird/path",
volumeID: "vol-42",
expectedPath: "/weird/path",
},
}
// Use a shared DeviceManager to make sure that there are no race conditions
dm := NewDeviceManager()

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
fakeInstance := newFakeInstance("fake-instance", tc.existingID, tc.existingPath)

dev, err := dm.NewDevice(fakeInstance, tc.volumeID)
assertDevice(t, dev, tc.existingID == tc.volumeID, err)

if dev.Path != tc.expectedPath {
t.Fatalf("Expected path %v got %v", tc.expectedPath, dev.Path)
}
})
}
}

func TestGetDevice(t *testing.T) {
testCases := []struct {
name string
Expand Down

0 comments on commit ed528b2

Please sign in to comment.