forked from treeverse/lakeFS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcataloger_get_entry_test.go
152 lines (148 loc) · 4.41 KB
/
cataloger_get_entry_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
147
148
149
150
151
152
package catalog
import (
"context"
"testing"
)
func TestCataloger_GetEntry(t *testing.T) {
ctx := context.Background()
c := testCataloger(t)
repository := setupReadEntryData(t, ctx, c)
type args struct {
repository string
reference string
path string
}
tests := []struct {
name string
args args
want *Entry
wantErr bool
}{
{
name: "uncommitted - uncommitted file",
args: args{repository: repository, reference: "master", path: "/file3"},
want: &Entry{Path: "/file3", PhysicalAddress: "/addr3", Size: 42, Checksum: "ffff"},
wantErr: false,
},
{
name: "uncommitted - committed file",
args: args{repository: repository, reference: "master", path: "/file1"},
want: &Entry{Path: "/file1", PhysicalAddress: "/addr1", Size: 42, Checksum: "ff"},
wantErr: false,
},
{
name: "committed - committed file",
args: args{repository: repository, reference: "master:HEAD", path: "/file2"},
want: &Entry{Path: "/file2", PhysicalAddress: "/addr2", Size: 24, Checksum: "ee"},
wantErr: false,
},
{
name: "uncommitted - unknown file",
args: args{repository: repository, reference: "master", path: "/fileX"},
want: nil,
wantErr: true,
},
{
name: "committed - unknown file",
args: args{repository: repository, reference: "master:HEAD", path: "/fileX"},
want: nil,
wantErr: true,
},
{
name: "unknown repository",
args: args{repository: "repoX", reference: "master", path: "/file1"},
want: nil,
wantErr: true,
},
{
name: "missing repository",
args: args{repository: "", reference: "master", path: "/file1"},
want: nil,
wantErr: true,
},
{
name: "empty reference",
args: args{repository: repository, reference: "", path: "/file1"},
want: nil,
wantErr: true,
},
{
name: "missing path",
args: args{repository: repository, reference: "master:HEAD", path: ""},
want: nil,
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := c.GetEntry(ctx, tt.args.repository, tt.args.reference, tt.args.path, GetEntryParams{})
if (err != nil) != tt.wantErr {
t.Errorf("GetEntry() error = %v, wantErr %v", err, tt.wantErr)
return
}
if (got == nil && tt.want != nil) || (got != nil && tt.want == nil) {
t.Errorf("GetEntry() got = %+v, want = %+v", got, tt.want)
return
}
if tt.want == nil || got == nil {
return
}
// compare just specific fields
if tt.want.Path != got.Path {
t.Errorf("GetEntry() got Path = %v, want = %v", got.Path, tt.want.Path)
}
if tt.want.PhysicalAddress != got.PhysicalAddress {
t.Errorf("GetEntry() got PhysicalAddress = %v, want = %v", got.PhysicalAddress, tt.want.PhysicalAddress)
}
if tt.want.Size != got.Size {
t.Errorf("GetEntry() got Size = %v, want = %v", got.Size, tt.want.Size)
}
if tt.want.Checksum != got.Checksum {
t.Errorf("GetEntry() got Checksum = %v, want = %v", got.Checksum, tt.want.Checksum)
}
})
}
}
func setupReadEntryData(t *testing.T, ctx context.Context, c Cataloger) string {
repository := testCatalogerRepo(t, ctx, c, "repository", "master")
if err := c.CreateEntry(ctx, repository, "master", Entry{
Path: "/file1",
Checksum: "ff",
PhysicalAddress: "/addr1",
Size: 42,
Metadata: nil,
}, CreateEntryParams{}); err != nil {
t.Fatal("failed to create entry", err)
}
if err := c.CreateEntry(ctx, repository, "master", Entry{
Path: "/file2",
Checksum: "ee",
PhysicalAddress: "/addr2",
Size: 24,
Metadata: nil,
}, CreateEntryParams{}); err != nil {
t.Fatal("failed to create entry", err)
}
if _, err := c.Commit(ctx, repository, "master", "commit file1 and 2", "tester", nil); err != nil {
t.Fatal("failed to commit for get entry:", err)
}
if err := c.CreateEntry(ctx, repository, "master", Entry{
Path: "/file3",
Checksum: "ffff",
PhysicalAddress: "/addr3",
Size: 42,
Metadata: nil,
}, CreateEntryParams{}); err != nil {
t.Fatal("failed to create entry", err)
}
if err := c.CreateEntry(ctx, repository, "master", Entry{
Path: "/file4",
Checksum: "eeee",
PhysicalAddress: "/addr4",
Size: 24,
Metadata: nil,
}, CreateEntryParams{}); err != nil {
t.Fatal("failed to create entry", err)
}
return repository
}