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 <jmulligan@redhat.com>
This commit is contained in:
John Mulligan 2023-02-07 16:23:24 -05:00 committed by John Mulligan
parent b596cb959b
commit 7accfa6b82
1 changed files with 25 additions and 10 deletions

View File

@ -12,8 +12,8 @@ func TestListVolumes(t *testing.T) {
vl, err := fsa.ListVolumes() vl, err := fsa.ListVolumes()
assert.NoError(t, err) assert.NoError(t, err)
assert.Len(t, vl, 1) assert.GreaterOrEqual(t, len(vl), 1)
assert.Equal(t, "cephfs", vl[0]) assert.Contains(t, vl, "cephfs")
} }
func TestEnumerateVolumes(t *testing.T) { func TestEnumerateVolumes(t *testing.T) {
@ -21,10 +21,16 @@ func TestEnumerateVolumes(t *testing.T) {
ve, err := fsa.EnumerateVolumes() ve, err := fsa.EnumerateVolumes()
assert.NoError(t, err) assert.NoError(t, err)
if assert.Len(t, ve, 1) {
assert.Equal(t, "cephfs", ve[0].Name) found := false
assert.Equal(t, int64(1), ve[0].ID) 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 // 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() l, err := fsa.ListFileSystems()
assert.NoError(t, err) assert.NoError(t, err)
if assert.Len(t, l, 1) { assert.GreaterOrEqual(t, len(l), 1)
assert.Equal(t, "cephfs", l[0].Name)
assert.Equal(t, "cephfs_metadata", l[0].MetadataPool) idx := -1
assert.Len(t, l[0].DataPools, 1) for i := range l {
assert.Contains(t, l[0].DataPools, "cephfs_data") 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")
} }
} }