From 7accfa6b82789b9b37e800f40d5daf90960efcdd Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Tue, 7 Feb 2023 16:23:24 -0500 Subject: [PATCH] cephfs admin: update tests to handle more than one file system If the ceph cluster we're testing against supports more then one fs our tests shouldn't fail. Update the tests to ensure a cephfs exists as expected but don't assume it's the only one (or that it's the first one returned). Signed-off-by: John Mulligan --- cephfs/admin/volume_test.go | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/cephfs/admin/volume_test.go b/cephfs/admin/volume_test.go index 41e6f93..97e51ca 100644 --- a/cephfs/admin/volume_test.go +++ b/cephfs/admin/volume_test.go @@ -12,8 +12,8 @@ func TestListVolumes(t *testing.T) { vl, err := fsa.ListVolumes() assert.NoError(t, err) - assert.Len(t, vl, 1) - assert.Equal(t, "cephfs", vl[0]) + assert.GreaterOrEqual(t, len(vl), 1) + assert.Contains(t, vl, "cephfs") } func TestEnumerateVolumes(t *testing.T) { @@ -21,10 +21,16 @@ func TestEnumerateVolumes(t *testing.T) { ve, err := fsa.EnumerateVolumes() assert.NoError(t, err) - if assert.Len(t, ve, 1) { - assert.Equal(t, "cephfs", ve[0].Name) - assert.Equal(t, int64(1), ve[0].ID) + + found := false + for i := range ve { + if ve[i].Name == "cephfs" { + assert.Equal(t, int64(1), ve[i].ID) + found = true + break + } } + assert.True(t, found, "never found a cephfs entry in enumerated volumes") } // note: some of these dumps are simplified for testing purposes if we add @@ -384,10 +390,19 @@ func TestListFileSystems(t *testing.T) { l, err := fsa.ListFileSystems() assert.NoError(t, err) - if assert.Len(t, l, 1) { - assert.Equal(t, "cephfs", l[0].Name) - assert.Equal(t, "cephfs_metadata", l[0].MetadataPool) - assert.Len(t, l[0].DataPools, 1) - assert.Contains(t, l[0].DataPools, "cephfs_data") + assert.GreaterOrEqual(t, len(l), 1) + + idx := -1 + for i := range l { + if l[i].Name == "cephfs" { + idx = i + break + } + } + if assert.NotEqual(t, -1, idx) { + assert.Equal(t, "cephfs", l[idx].Name) + assert.Equal(t, "cephfs_metadata", l[idx].MetadataPool) + assert.Len(t, l[idx].DataPools, 1) + assert.Contains(t, l[idx].DataPools, "cephfs_data") } }