From 0fa5143172da4e5b8ed2976c17ac23f5b53b13c3 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Wed, 30 Sep 2020 16:07:44 -0400 Subject: [PATCH] cephfs admin: move tests that were previously only built on octopus Signed-off-by: John Mulligan --- cephfs/admin/subvolume_octopus_test.go | 93 -------------------------- cephfs/admin/subvolume_test.go | 83 +++++++++++++++++++++++ 2 files changed, 83 insertions(+), 93 deletions(-) delete mode 100644 cephfs/admin/subvolume_octopus_test.go diff --git a/cephfs/admin/subvolume_octopus_test.go b/cephfs/admin/subvolume_octopus_test.go deleted file mode 100644 index 836473e..0000000 --- a/cephfs/admin/subvolume_octopus_test.go +++ /dev/null @@ -1,93 +0,0 @@ -// +build octopus - -package admin - -import ( - "errors" - "testing" - - "github.com/stretchr/testify/assert" -) - -var sampleSubVolumeSnapshoInfo1 = []byte(` -{ - "created_at": "2020-09-11 17:40:12.035792", - "data_pool": "cephfs_data", - "has_pending_clones": "no", - "protected": "yes", - "size": 0 -} -`) - -func TestParseSubVolumeSnapshotInfo(t *testing.T) { - R := newResponse - t.Run("error", func(t *testing.T) { - _, err := parseSubVolumeSnapshotInfo(R(nil, "", errors.New("flub"))) - assert.Error(t, err) - assert.Equal(t, "flub", err.Error()) - }) - t.Run("statusSet", func(t *testing.T) { - _, err := parseSubVolumeSnapshotInfo(R(nil, "unexpected!", nil)) - assert.Error(t, err) - }) - t.Run("badJSON", func(t *testing.T) { - _, err := parseSubVolumeSnapshotInfo(R([]byte("_XxXxX"), "", nil)) - assert.Error(t, err) - }) - t.Run("ok", func(t *testing.T) { - info, err := parseSubVolumeSnapshotInfo(R(sampleSubVolumeSnapshoInfo1, "", nil)) - assert.NoError(t, err) - if assert.NotNil(t, info) { - assert.Equal(t, "cephfs_data", info.DataPool) - assert.EqualValues(t, 0, info.Size) - assert.Equal(t, 2020, info.CreatedAt.Year()) - assert.Equal(t, "yes", info.Protected) - assert.Equal(t, "no", info.HasPendingClones) - } - }) -} - -func TestSubVolumeSnapshotInfo(t *testing.T) { - fsa := getFSAdmin(t) - volume := "cephfs" - group := "20000leagues" - subname := "poulp" - snapname1 := "t1" - snapname2 := "nope" - - err := fsa.CreateSubVolumeGroup(volume, group, nil) - assert.NoError(t, err) - defer func() { - err := fsa.RemoveSubVolumeGroup(volume, group) - assert.NoError(t, err) - }() - - svopts := &SubVolumeOptions{ - Mode: 0750, - Size: 20 * gibiByte, - } - err = fsa.CreateSubVolume(volume, group, subname, svopts) - assert.NoError(t, err) - defer func() { - err := fsa.RemoveSubVolume(volume, group, subname) - assert.NoError(t, err) - }() - - err = fsa.CreateSubVolumeSnapshot(volume, group, subname, snapname1) - assert.NoError(t, err) - defer func() { - err := fsa.RemoveSubVolumeSnapshot(volume, group, subname, snapname1) - assert.NoError(t, err) - }() - - sinfo, err := fsa.SubVolumeSnapshotInfo(volume, group, subname, snapname1) - assert.NoError(t, err) - assert.NotNil(t, sinfo) - assert.EqualValues(t, 0, sinfo.Size) - assert.Equal(t, "cephfs_data", sinfo.DataPool) - assert.GreaterOrEqual(t, 2020, sinfo.CreatedAt.Year()) - - sinfo, err = fsa.SubVolumeSnapshotInfo(volume, group, subname, snapname2) - assert.Error(t, err) - assert.Nil(t, sinfo) -} diff --git a/cephfs/admin/subvolume_test.go b/cephfs/admin/subvolume_test.go index 84d489e..694d814 100644 --- a/cephfs/admin/subvolume_test.go +++ b/cephfs/admin/subvolume_test.go @@ -433,3 +433,86 @@ func TestSubVolumeSnapshots(t *testing.T) { assert.Contains(t, snaps, snapname2) }) } + +var sampleSubVolumeSnapshoInfo1 = []byte(` +{ + "created_at": "2020-09-11 17:40:12.035792", + "data_pool": "cephfs_data", + "has_pending_clones": "no", + "protected": "yes", + "size": 0 +} +`) + +func TestParseSubVolumeSnapshotInfo(t *testing.T) { + R := newResponse + t.Run("error", func(t *testing.T) { + _, err := parseSubVolumeSnapshotInfo(R(nil, "", errors.New("flub"))) + assert.Error(t, err) + assert.Equal(t, "flub", err.Error()) + }) + t.Run("statusSet", func(t *testing.T) { + _, err := parseSubVolumeSnapshotInfo(R(nil, "unexpected!", nil)) + assert.Error(t, err) + }) + t.Run("badJSON", func(t *testing.T) { + _, err := parseSubVolumeSnapshotInfo(R([]byte("_XxXxX"), "", nil)) + assert.Error(t, err) + }) + t.Run("ok", func(t *testing.T) { + info, err := parseSubVolumeSnapshotInfo(R(sampleSubVolumeSnapshoInfo1, "", nil)) + assert.NoError(t, err) + if assert.NotNil(t, info) { + assert.Equal(t, "cephfs_data", info.DataPool) + assert.EqualValues(t, 0, info.Size) + assert.Equal(t, 2020, info.CreatedAt.Year()) + assert.Equal(t, "yes", info.Protected) + assert.Equal(t, "no", info.HasPendingClones) + } + }) +} + +func TestSubVolumeSnapshotInfo(t *testing.T) { + fsa := getFSAdmin(t) + volume := "cephfs" + group := "20000leagues" + subname := "poulp" + snapname1 := "t1" + snapname2 := "nope" + + err := fsa.CreateSubVolumeGroup(volume, group, nil) + assert.NoError(t, err) + defer func() { + err := fsa.RemoveSubVolumeGroup(volume, group) + assert.NoError(t, err) + }() + + svopts := &SubVolumeOptions{ + Mode: 0750, + Size: 20 * gibiByte, + } + err = fsa.CreateSubVolume(volume, group, subname, svopts) + assert.NoError(t, err) + defer func() { + err := fsa.RemoveSubVolume(volume, group, subname) + assert.NoError(t, err) + }() + + err = fsa.CreateSubVolumeSnapshot(volume, group, subname, snapname1) + assert.NoError(t, err) + defer func() { + err := fsa.RemoveSubVolumeSnapshot(volume, group, subname, snapname1) + assert.NoError(t, err) + }() + + sinfo, err := fsa.SubVolumeSnapshotInfo(volume, group, subname, snapname1) + assert.NoError(t, err) + assert.NotNil(t, sinfo) + assert.EqualValues(t, 0, sinfo.Size) + assert.Equal(t, "cephfs_data", sinfo.DataPool) + assert.GreaterOrEqual(t, 2020, sinfo.CreatedAt.Year()) + + sinfo, err = fsa.SubVolumeSnapshotInfo(volume, group, subname, snapname2) + assert.Error(t, err) + assert.Nil(t, sinfo) +}