forked from treeverse/lakeFS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcataloger_get_branch_reference_test.go
82 lines (77 loc) · 1.86 KB
/
cataloger_get_branch_reference_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
package catalog
import (
"context"
"reflect"
"testing"
"github.com/treeverse/lakefs/testutil"
)
func TestCataloger_GetBranch(t *testing.T) {
ctx := context.Background()
c := testCataloger(t)
// setup test data
repo := testCatalogerRepo(t, ctx, c, "repo", "master")
_, err := c.CreateBranch(ctx, repo, "branch1", "master")
testutil.MustDo(t, "create branch1", err)
testCatalogerCreateEntry(t, ctx, c, repo, "master", "a/file", nil, "")
_, err = c.Commit(ctx, repo, "master", "commit a file", "tester", nil)
testutil.MustDo(t, "commit a file", err)
type args struct {
repository string
branch string
}
tests := []struct {
name string
args args
want string
wantErr bool
}{
{
name: "branch with commits",
args: args{repository: repo, branch: "master"},
want: "~KJ8Wd1Rs96a",
wantErr: false,
},
{
name: "branch without commits",
args: args{repository: repo, branch: "branch1"},
want: "~2FgRfNLHmSmvR",
wantErr: false,
},
{
name: "unknown repository",
args: args{repository: "repoX", branch: "master"},
want: "",
wantErr: true,
},
{
name: "missing repository",
args: args{repository: "", branch: "master"},
want: "",
wantErr: true,
},
{
name: "unknown branch",
args: args{repository: repo, branch: "nobranch"},
want: "",
wantErr: true,
},
{
name: "missing branch",
args: args{repository: repo, branch: ""},
want: "",
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := c.GetBranchReference(ctx, tt.args.repository, tt.args.branch)
if (err != nil) != tt.wantErr {
t.Errorf("GetBranch() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetBranch() got = %v, want %v", got, tt.want)
}
})
}
}