diff --git a/zfs/datasetpath_visitor_test.go b/zfs/datasetpath_visitor_test.go index b1b3cad..61d8e1b 100644 --- a/zfs/datasetpath_visitor_test.go +++ b/zfs/datasetpath_visitor_test.go @@ -27,9 +27,9 @@ func makeVisitRecorder() (v DatasetPathsVisitor, rec *visitRecorder) { rec = &visitRecorder{ visits: make([]DatasetPathVisit, 0), } - v = func(v DatasetPathVisit) error { + v = func(v DatasetPathVisit) bool { rec.visits = append(rec.visits, v) - return nil + return true } return } diff --git a/zfs/diff_test.go b/zfs/diff_test.go index ad9e3d0..0dce4a1 100644 --- a/zfs/diff_test.go +++ b/zfs/diff_test.go @@ -2,23 +2,42 @@ package zfs import ( "github.com/stretchr/testify/assert" + "strconv" "strings" "testing" + "time" ) func fsvlist(fsv ...string) (r []FilesystemVersion) { r = make([]FilesystemVersion, len(fsv)) for i, f := range fsv { + + // parse the id from fsvlist. it is used to derivce Guid,CreateTXG and Creation attrs + split := strings.Split(f, ",") + if len(split) != 2 { + panic("invalid fsv spec") + } + id, err := strconv.Atoi(split[1]) + if err != nil { + panic(err) + } + if strings.HasPrefix(f, "#") { r[i] = FilesystemVersion{ - Name: strings.TrimPrefix(f, "#"), - Type: Bookmark, + Name: strings.TrimPrefix(f, "#"), + Type: Bookmark, + Guid: uint64(id), + CreateTXG: uint64(id), + Creation: time.Unix(0, 0).Add(time.Duration(id) * time.Second), } } else if strings.HasPrefix(f, "@") { r[i] = FilesystemVersion{ - Name: strings.TrimPrefix(f, "@"), - Type: Snapshot, + Name: strings.TrimPrefix(f, "@"), + Type: Snapshot, + Guid: uint64(id), + CreateTXG: uint64(id), + Creation: time.Unix(0, 0).Add(time.Duration(id) * time.Second), } } else { panic("invalid character") @@ -38,33 +57,33 @@ func TestMakeFilesystemDiff_IncrementalSnapshots(t *testing.T) { l := fsvlist // basic functionality - doTest(l("@a", "@b"), l("@a", "@b", "@c", "@d"), func(d FilesystemDiff) { - assert.Equal(t, l("@b", "@c", "@d"), d.IncrementalPath) + doTest(l("@a,1", "@b,2"), l("@a,1", "@b,2", "@c,3", "@d,4"), func(d FilesystemDiff) { + assert.Equal(t, l("@b,2", "@c,3", "@d,4"), d.IncrementalPath) }) // no common ancestor - doTest(l(), l("@a"), func(d FilesystemDiff) { + doTest(l(), l("@a,1"), func(d FilesystemDiff) { assert.Nil(t, d.IncrementalPath) - assert.False(t, d.Diverged) - assert.Equal(t, l("@a"), d.MRCAPathRight) + assert.EqualValues(t, d.Conflict, ConflictNoCommonAncestor) + assert.Equal(t, l("@a,1"), d.MRCAPathRight) }) - doTest(l("@a", "@b"), l("@c", "@d"), func(d FilesystemDiff) { + doTest(l("@a,1", "@b,2"), l("@c,3", "@d,4"), func(d FilesystemDiff) { assert.Nil(t, d.IncrementalPath) - assert.False(t, d.Diverged) - assert.Equal(t, l("@c", "@d"), d.MRCAPathRight) + assert.EqualValues(t, d.Conflict, ConflictNoCommonAncestor) + assert.Equal(t, l("@c,3", "@d,4"), d.MRCAPathRight) }) // divergence is detected - doTest(l("@a", "@b1"), l("@a", "@b2"), func(d FilesystemDiff) { + doTest(l("@a,1", "@b1,2"), l("@a,1", "@b2,3"), func(d FilesystemDiff) { assert.Nil(t, d.IncrementalPath) - assert.True(t, d.Diverged) - assert.Equal(t, l("@a", "@b1"), d.MRCAPathLeft) - assert.Equal(t, l("@a", "@b2"), d.MRCAPathRight) + assert.EqualValues(t, d.Conflict, ConflictDiverged) + assert.Equal(t, l("@a,1", "@b1,2"), d.MRCAPathLeft) + assert.Equal(t, l("@a,1", "@b2,3"), d.MRCAPathRight) }) // gaps before most recent common ancestor do not matter - doTest(l("@a", "@b", "@c"), l("@a", "@c", "@d"), func(d FilesystemDiff) { - assert.Equal(t, l("@c", "@d"), d.IncrementalPath) + doTest(l("@a,1", "@b,2", "@c,3"), l("@a,1", "@c,3", "@d,4"), func(d FilesystemDiff) { + assert.Equal(t, l("@c,3", "@d,4"), d.IncrementalPath) }) } @@ -73,21 +92,21 @@ func TestMakeFilesystemDiff_BookmarksSupport(t *testing.T) { l := fsvlist // bookmarks are used - doTest(l("@a"), l("#a", "@b"), func(d FilesystemDiff) { - assert.Equal(t, l("#a", "@b"), d.IncrementalPath) + doTest(l("@a,1"), l("#a,1", "@b,2"), func(d FilesystemDiff) { + assert.Equal(t, l("#a,1", "@b,2"), d.IncrementalPath) }) // boomarks are stripped from IncrementalPath (cannot send incrementally) - doTest(l("@a"), l("#a", "#b", "@c"), func(d FilesystemDiff) { - assert.Equal(t, l("#a", "@c"), d.IncrementalPath) + doTest(l("@a,1"), l("#a,1", "#b,2", "@c,3"), func(d FilesystemDiff) { + assert.Equal(t, l("#a,1", "@c,3"), d.IncrementalPath) }) // test that snapshots are preferred over bookmarks in IncrementalPath - doTest(l("@a"), l("#a", "@a", "@b"), func(d FilesystemDiff) { - assert.Equal(t, l("@a", "@b"), d.IncrementalPath) + doTest(l("@a,1"), l("#a,1", "@a,1", "@b,2"), func(d FilesystemDiff) { + assert.Equal(t, l("@a,1", "@b,2"), d.IncrementalPath) }) - doTest(l("@a"), l("@a", "#a", "@b"), func(d FilesystemDiff) { - assert.Equal(t, l("@a", "@b"), d.IncrementalPath) + doTest(l("@a,1"), l("@a,1", "#a,1", "@b,2"), func(d FilesystemDiff) { + assert.Equal(t, l("@a,1", "@b,2"), d.IncrementalPath) }) }