mirror of
https://github.com/zrepl/zrepl.git
synced 2025-01-03 21:08:52 +01:00
[#321] platformtest: add test for zfs.ZFSHolds
This commit is contained in:
parent
b056e7b2b9
commit
94a0fbf953
@ -5,6 +5,7 @@ package tests
|
||||
var Cases = []Case{BatchDestroy,
|
||||
CreateReplicationCursor,
|
||||
GetNonexistent,
|
||||
HoldsWork,
|
||||
IdempotentBookmark,
|
||||
IdempotentDestroy,
|
||||
IdempotentHold,
|
||||
@ -14,6 +15,7 @@ var Cases = []Case{BatchDestroy,
|
||||
ListFilesystemVersionsZeroExistIsNotAnError,
|
||||
ListFilesystemsNoFilter,
|
||||
ReceiveForceIntoEncryptedErr,
|
||||
ReceiveForceRollbackWorksUnencrypted,
|
||||
ReplicationIncrementalCleansUpStaleAbstractionsWithCacheOnSecondReplication,
|
||||
ReplicationIncrementalCleansUpStaleAbstractionsWithoutCacheOnSecondReplication,
|
||||
ReplicationIncrementalIsPossibleIfCommonSnapshotIsDestroyed,
|
||||
|
32
platformtest/tests/holds.go
Normal file
32
platformtest/tests/holds.go
Normal file
@ -0,0 +1,32 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"path"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/zrepl/zrepl/platformtest"
|
||||
"github.com/zrepl/zrepl/zfs"
|
||||
)
|
||||
|
||||
func HoldsWork(ctx *platformtest.Context) {
|
||||
platformtest.Run(ctx, platformtest.PanicErr, ctx.RootDataset, `
|
||||
DESTROYROOT
|
||||
CREATEROOT
|
||||
+ "foo bar"
|
||||
+ "foo bar@snap name"
|
||||
`)
|
||||
|
||||
fs := path.Join(ctx.RootDataset, "foo bar")
|
||||
|
||||
err := zfs.ZFSHold(ctx, fs, fsversion(ctx, fs, "@snap name"), "tag 1")
|
||||
require.NoError(ctx, err)
|
||||
|
||||
err = zfs.ZFSHold(ctx, fs, fsversion(ctx, fs, "@snap name"), "tag 2")
|
||||
require.NoError(ctx, err)
|
||||
|
||||
holds, err := zfs.ZFSHolds(ctx, fs, "snap name")
|
||||
require.NoError(ctx, err)
|
||||
require.Len(ctx, holds, 2)
|
||||
require.Contains(ctx, holds, "tag 1")
|
||||
require.Contains(ctx, holds, "tag 2")
|
||||
}
|
54
platformtest/tests/recvRollback.go
Normal file
54
platformtest/tests/recvRollback.go
Normal file
@ -0,0 +1,54 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/zrepl/zrepl/platformtest"
|
||||
"github.com/zrepl/zrepl/zfs"
|
||||
)
|
||||
|
||||
func ReceiveForceRollbackWorksUnencrypted(ctx *platformtest.Context) {
|
||||
platformtest.Run(ctx, platformtest.PanicErr, ctx.RootDataset, `
|
||||
DESTROYROOT
|
||||
CREATEROOT
|
||||
+ "foo bar"
|
||||
+ "foo bar@a snap"
|
||||
+ "foo bar@another snap"
|
||||
+ "foo bar@snap3"
|
||||
+ "sender"
|
||||
+ "sender@1"
|
||||
`)
|
||||
|
||||
rfs := fmt.Sprintf("%s/foo bar", ctx.RootDataset)
|
||||
sfs := fmt.Sprintf("%s/sender", ctx.RootDataset)
|
||||
sfsSnap1 := sendArgVersion(ctx, sfs, "@1")
|
||||
|
||||
sendArgs, err := zfs.ZFSSendArgsUnvalidated{
|
||||
FS: sfs,
|
||||
Encrypted: &zfs.NilBool{B: false},
|
||||
From: nil,
|
||||
To: &sfsSnap1,
|
||||
ResumeToken: "",
|
||||
}.Validate(ctx)
|
||||
require.NoError(ctx, err)
|
||||
|
||||
sendStream, err := zfs.ZFSSend(ctx, sendArgs)
|
||||
require.NoError(ctx, err)
|
||||
|
||||
recvOpts := zfs.RecvOptions{
|
||||
RollbackAndForceRecv: true,
|
||||
SavePartialRecvState: false,
|
||||
}
|
||||
err = zfs.ZFSRecv(ctx, rfs, &zfs.ZFSSendArgVersion{RelName: "@1", GUID: sfsSnap1.GUID}, sendStream, recvOpts)
|
||||
require.NoError(ctx, err)
|
||||
|
||||
// assert exists on receiver
|
||||
rfsSnap1 := fsversion(ctx, rfs, "@1")
|
||||
// assert it's the only one (rollback and force-recv should be blowing away the other filesystems)
|
||||
rfsVersions, err := zfs.ZFSListFilesystemVersions(ctx, mustDatasetPath(rfs), zfs.ListFilesystemVersionsOptions{})
|
||||
require.NoError(ctx, err)
|
||||
assert.Len(ctx, rfsVersions, 1)
|
||||
assert.Equal(ctx, rfsVersions[0], rfsSnap1)
|
||||
}
|
Loading…
Reference in New Issue
Block a user