forked from treeverse/lakeFS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcataloger_create_entries_test.go
146 lines (142 loc) · 3.32 KB
/
cataloger_create_entries_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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package catalog
import (
"context"
"testing"
"github.com/treeverse/lakefs/testutil"
)
func TestCataloger_CreateEntries(t *testing.T) {
ctx := context.Background()
c := testCataloger(t)
// test data
repo := testCatalogerRepo(t, ctx, c, "repo", "master")
testutil.MustDo(t, "create entry on master for testing",
c.CreateEntry(ctx, repo, "master",
Entry{Path: "/aaa/bbb/ddd", Checksum: "cc", PhysicalAddress: "xx", Size: 1},
CreateEntryParams{}))
_, err := c.CreateBranch(ctx, repo, "b1", "master")
testutil.MustDo(t, "create branch b1 based on master", err)
type args struct {
repository string
branch string
entries []Entry
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "basic",
args: args{
repository: repo,
branch: "master",
entries: []Entry{
{
Path: "/aaa/bbb/ccc1",
Checksum: "1231",
PhysicalAddress: "5671",
Size: 100,
Metadata: Metadata{"k1": "v1"},
},
{
Path: "/aaa/bbb/ccc2",
Checksum: "1232",
PhysicalAddress: "5672",
Size: 200,
Metadata: Metadata{"k2": "v2"},
},
},
},
wantErr: false,
},
{
name: "unknown repo",
args: args{
repository: "norepo",
branch: "master",
entries: []Entry{
{
Path: "/aaa/bbb/cccX",
Checksum: "1239",
PhysicalAddress: "5679",
Size: 999,
},
},
},
wantErr: true,
},
{
name: "unknown branch",
args: args{
repository: repo,
branch: "masterX",
entries: []Entry{
{
Path: "/aaa/bbb/cccX",
Checksum: "1239",
PhysicalAddress: "5679",
Size: 999,
},
},
},
wantErr: true,
},
{
name: "missing repo",
args: args{
repository: "",
branch: "master",
entries: []Entry{
{
Path: "/aaa/bbb/cccX",
Checksum: "1239",
PhysicalAddress: "5679",
Size: 999,
},
},
},
wantErr: true,
},
{
name: "missing branch",
args: args{
repository: repo,
branch: "",
entries: []Entry{
{
Path: "/aaa/bbb/cccX",
Checksum: "1239",
PhysicalAddress: "5679",
Size: 999,
},
},
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := c.CreateEntries(ctx, tt.args.repository, tt.args.branch, tt.args.entries)
if (err != nil) != tt.wantErr {
t.Fatalf("CreateEntries() error = %v, wantErr %v", err, tt.wantErr)
}
if err != nil {
return
}
// check if case there was no error
for i, entry := range tt.args.entries {
ent, err := c.GetEntry(ctx, repo, tt.args.branch, entry.Path, GetEntryParams{})
testutil.MustDo(t, "get entry for new created entry", err)
if ent.Path != entry.Path {
t.Errorf("Entry at pos %d: path '%s', expected '%s'", i, ent.Path, entry.Path)
}
if ent.PhysicalAddress != entry.PhysicalAddress {
t.Errorf("Entry at pos %d: address '%s', expected '%s'", i, ent.PhysicalAddress, entry.PhysicalAddress)
}
if ent.Size != entry.Size {
t.Errorf("Entry at pos %d: size '%d', expected '%d'", i, ent.Size, entry.Size)
}
}
})
}
}