forked from treeverse/lakeFS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcataloger_diff_uncommitted_test.go
119 lines (104 loc) · 3.76 KB
/
cataloger_diff_uncommitted_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package catalog
import (
"context"
"strconv"
"testing"
"github.com/go-test/deep"
"github.com/treeverse/lakefs/testutil"
)
func TestCataloger_DiffUncommitted_Pagination(t *testing.T) {
ctx := context.Background()
c := testCataloger(t)
repository := testCatalogerRepo(t, ctx, c, "repo", "master")
const numOfFiles = 10
var expectedDifferences Differences
for i := 0; i < numOfFiles; i++ {
p := "/file" + strconv.Itoa(i)
testCatalogerCreateEntry(t, ctx, c, repository, "master", p, nil, "")
expectedDifferences = append(expectedDifferences, Difference{Type: DifferenceTypeAdded, Path: p})
}
const changesPerPage = 3
var differences Differences
var after string
for {
res, hasMore, err := c.DiffUncommitted(ctx, repository, "master", changesPerPage, after)
testutil.MustDo(t, "diff uncommitted changes", err)
if err != nil {
t.Fatalf("DiffUncommitted err=%s, expected none", err)
}
if len(res) > changesPerPage {
t.Fatalf("DiffUncommitted() result length %d, expected equal or less than %d", len(res), changesPerPage)
}
differences = append(differences, res...)
if !hasMore {
break
}
after = res[len(res)-1].Path
}
if diff := deep.Equal(differences, expectedDifferences); diff != nil {
t.Fatal("DiffUncommitted", diff)
}
// check the case where we ask for 0 amount
res, hasMore, err := c.DiffUncommitted(ctx, repository, "master", 0, "")
testutil.MustDo(t, "diff uncommitted with 0 limit", err)
if !hasMore {
t.Error("DiffUncommitted() has more should be true")
}
if len(res) != 0 {
t.Errorf("DiffUncommitted() has %d items in result when expected none", len(res))
}
}
func TestCataloger_DiffUncommitted_Changes(t *testing.T) {
ctx := context.Background()
c := testCataloger(t)
repository := testCatalogerRepo(t, ctx, c, "repo", "master")
// commit files
for i := 0; i < 3; i++ {
testCatalogerCreateEntry(t, ctx, c, repository, "master", "/file"+strconv.Itoa(i), nil, "")
}
_, err := c.Commit(ctx, repository, "master", "commit to master", "tester", nil)
testutil.MustDo(t, "commit to master", err)
// delete, create and change
const newFilename = "/file5"
testCatalogerCreateEntry(t, ctx, c, repository, "master", newFilename, nil, "seed1")
const delFilename = "/file1"
testutil.MustDo(t, "delete committed file on master",
c.DeleteEntry(ctx, repository, "master", delFilename))
const overFilename = "/file2"
testCatalogerCreateEntry(t, ctx, c, repository, "master", overFilename, nil, "seed1")
// verify that diff uncommitted show the above change
differences, _, err := c.DiffUncommitted(ctx, repository, "master", -1, "")
if err != nil {
t.Fatalf("DiffUncommitted err = %s, expected none", err)
}
changes := Differences{
Difference{Type: DifferenceTypeRemoved, Path: "/file1"},
Difference{Type: DifferenceTypeChanged, Path: "/file2"},
Difference{Type: DifferenceTypeAdded, Path: "/file5"},
}
if diff := deep.Equal(differences, changes); diff != nil {
t.Fatal("DiffUncommitted", diff)
}
}
func TestCataloger_DiffUncommitted_NoChance(t *testing.T) {
ctx := context.Background()
c := testCataloger(t)
repository := testCatalogerRepo(t, ctx, c, "repo", "master")
// commit files
for i := 0; i < 3; i++ {
testCatalogerCreateEntry(t, ctx, c, repository, "master", "/file"+strconv.Itoa(i), nil, "")
}
_, err := c.Commit(ctx, repository, "master", "commit to master", "tester", nil)
testutil.MustDo(t, "commit to master", err)
// verify that diff uncommitted show the above change
differences, hasMore, err := c.DiffUncommitted(ctx, repository, "master", -1, "")
if err != nil {
t.Fatalf("DiffUncommitted err = %s, expected none", err)
}
if len(differences) != 0 {
t.Fatalf("DiffUncommitted differences len=%d, expected 0", len(differences))
}
if hasMore {
t.Fatal("DiffUncommitted hadMore is true, expected false")
}
}