|
| 1 | +package data |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + "zfs-file-history/internal/data/diff_state" |
| 6 | + "zfs-file-history/internal/zfs" |
| 7 | + |
| 8 | + "github.com/stretchr/testify/assert" |
| 9 | +) |
| 10 | + |
| 11 | +func TestFileBrowserEntry_HasReal(t *testing.T) { |
| 12 | + entry := &FileBrowserEntry{ |
| 13 | + RealFile: &RealFile{Path: "/foo"}, |
| 14 | + } |
| 15 | + assert.True(t, entry.HasReal()) |
| 16 | + |
| 17 | + entry = &FileBrowserEntry{ |
| 18 | + RealFile: nil, |
| 19 | + } |
| 20 | + assert.False(t, entry.HasReal()) |
| 21 | +} |
| 22 | + |
| 23 | +func TestFileBrowserEntry_HasSnapshot(t *testing.T) { |
| 24 | + entry := &FileBrowserEntry{ |
| 25 | + SnapshotFiles: []*SnapshotFile{{Path: "/foo"}}, |
| 26 | + } |
| 27 | + assert.True(t, entry.HasSnapshot()) |
| 28 | + |
| 29 | + entry = &FileBrowserEntry{ |
| 30 | + SnapshotFiles: []*SnapshotFile{}, |
| 31 | + } |
| 32 | + assert.False(t, entry.HasSnapshot()) |
| 33 | +} |
| 34 | + |
| 35 | +func TestFileBrowserEntry_GetRealPath(t *testing.T) { |
| 36 | + realFile := &RealFile{Path: "/real/path"} |
| 37 | + snapshotFile := &SnapshotFile{OriginalPath: "/original/path"} |
| 38 | + |
| 39 | + entry := &FileBrowserEntry{ |
| 40 | + RealFile: realFile, |
| 41 | + } |
| 42 | + assert.Equal(t, "/real/path", entry.GetRealPath()) |
| 43 | + |
| 44 | + entry = &FileBrowserEntry{ |
| 45 | + RealFile: nil, |
| 46 | + SnapshotFiles: []*SnapshotFile{snapshotFile}, |
| 47 | + } |
| 48 | + assert.Equal(t, "/original/path", entry.GetRealPath()) |
| 49 | +} |
| 50 | + |
| 51 | +func TestFileBrowserEntry_Equal(t *testing.T) { |
| 52 | + e1 := FileBrowserEntry{RealFile: &RealFile{Path: "/foo"}} |
| 53 | + e2 := FileBrowserEntry{RealFile: &RealFile{Path: "/foo"}} |
| 54 | + e3 := FileBrowserEntry{RealFile: &RealFile{Path: "/bar"}} |
| 55 | + |
| 56 | + assert.True(t, e1.Equal(e2)) |
| 57 | + assert.False(t, e1.Equal(e3)) |
| 58 | +} |
| 59 | + |
| 60 | +func TestFileBrowserEntry_HasDiff(t *testing.T) { |
| 61 | + entry := &FileBrowserEntry{ |
| 62 | + DiffState: diff_state.Modified, |
| 63 | + SnapshotFiles: []*SnapshotFile{{Path: "/foo"}}, |
| 64 | + } |
| 65 | + assert.True(t, entry.HasDiff()) |
| 66 | + |
| 67 | + entry.DiffState = diff_state.Equal |
| 68 | + assert.False(t, entry.HasDiff()) |
| 69 | + |
| 70 | + entry.DiffState = diff_state.Modified |
| 71 | + entry.SnapshotFiles = nil |
| 72 | + assert.False(t, entry.HasDiff()) |
| 73 | +} |
| 74 | + |
| 75 | +func TestFileBrowserEntry_TableRowId(t *testing.T) { |
| 76 | + entry := FileBrowserEntry{RealFile: &RealFile{Path: "/foo"}} |
| 77 | + assert.Equal(t, "/foo", entry.TableRowId()) |
| 78 | +} |
| 79 | + |
| 80 | +func TestRealFile_Equal(t *testing.T) { |
| 81 | + f1 := RealFile{Name: "a", Path: "p"} |
| 82 | + f2 := RealFile{Name: "a", Path: "p"} |
| 83 | + f3 := RealFile{Name: "b", Path: "p"} |
| 84 | + |
| 85 | + assert.True(t, f1.Equal(f2)) |
| 86 | + assert.False(t, f1.Equal(f3)) |
| 87 | +} |
| 88 | + |
| 89 | +func TestSnapshotFile_Equal(t *testing.T) { |
| 90 | + snap := &zfs.Snapshot{} |
| 91 | + f1 := SnapshotFile{Path: "p", OriginalPath: "o", Snapshot: snap} |
| 92 | + f2 := SnapshotFile{Path: "p", OriginalPath: "o", Snapshot: snap} |
| 93 | + f3 := SnapshotFile{Path: "p2", OriginalPath: "o", Snapshot: snap} |
| 94 | + |
| 95 | + assert.True(t, f1.Equal(f2)) |
| 96 | + assert.False(t, f1.Equal(f3)) |
| 97 | +} |
0 commit comments