From ed528b2c27bd6250d783aab792f5ed47d1ab6291 Mon Sep 17 00:00:00 2001 From: Connor Catlett Date: Thu, 2 Mar 2023 08:05:34 +0000 Subject: [PATCH] Add tests for manually mounted volumes (and other weird paths) Signed-off-by: Connor Catlett --- pkg/cloud/devicemanager/manager_test.go | 54 +++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/pkg/cloud/devicemanager/manager_test.go b/pkg/cloud/devicemanager/manager_test.go index 25e095f3ea..0f277be024 100644 --- a/pkg/cloud/devicemanager/manager_test.go +++ b/pkg/cloud/devicemanager/manager_test.go @@ -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