forked from treeverse/lakeFS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcataloger_delete_branch_test.go
118 lines (110 loc) · 2.99 KB
/
cataloger_delete_branch_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
package catalog
import (
"context"
"errors"
"fmt"
"testing"
"github.com/treeverse/lakefs/db"
)
func TestCataloger_DeleteBranch(t *testing.T) {
ctx := context.Background()
c := testCataloger(t, WithCacheEnabled(false))
if err := c.CreateRepository(ctx, "repo1", "s3://bucket1", "master"); err != nil {
t.Fatal("create repository for testing", err)
}
for i := 0; i < 3; i++ {
branchName := fmt.Sprintf("branch%d", i)
var sourceBranch string
if i == 0 {
sourceBranch = "master"
} else {
sourceBranch = fmt.Sprintf("branch%d", i-1)
}
testCatalogerBranch(t, ctx, c, "repo1", branchName, sourceBranch)
}
testCatalogerBranch(t, ctx, c, "repo1", "b1", "master")
if err := c.CreateEntry(ctx, "repo1", "b1", Entry{
Path: "/file1",
Checksum: "7c9d66ac57c9fa91bb375256fe1541e33f9548904c3f41fcd1e1208f2f3559f1",
PhysicalAddress: "/file1abc",
Size: 42,
Metadata: nil,
}, CreateEntryParams{}); err != nil {
t.Fatal("create entry for testing", err)
}
type args struct {
repository string
branch string
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "delete default branch",
args: args{repository: "repo1", branch: "master"},
wantErr: true,
},
{
name: "delete branch",
args: args{repository: "repo1", branch: "b1"},
wantErr: false,
},
{
name: "delete unknown branch",
args: args{repository: "repo1", branch: "nob"},
wantErr: true,
},
{
name: "delete without repository",
args: args{repository: "repoX", branch: "nob"},
wantErr: true,
},
{
name: "delete branch used by branch",
args: args{repository: "repo1", branch: "branch1"},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := c.DeleteBranch(ctx, tt.args.repository, tt.args.branch)
if (err != nil) != tt.wantErr {
t.Fatalf("DeleteBranch() error = %v, wantErr %v", err, tt.wantErr)
}
if err != nil {
return
}
_, err = c.GetBranchReference(ctx, tt.args.repository, tt.args.branch)
if !errors.As(err, &db.ErrNotFound) {
t.Errorf("Branch should not be found after delete, got err=%s", err)
return
}
})
}
}
func TestCataloger_DeleteBranchTwice(t *testing.T) {
ctx := context.Background()
c := testCataloger(t)
repo := testCatalogerRepo(t, ctx, c, "repo", "branch0")
const numBranches = 3
// create branches
for i := 0; i < numBranches; i++ {
sourceBranchName := fmt.Sprintf("branch%d", i)
branchName := fmt.Sprintf("branch%d", i+1)
testCatalogerBranch(t, ctx, c, repo, branchName, sourceBranchName)
}
// delete twice (checking double delete) in reverse order
for i := numBranches; i > 0; i-- {
branchName := fmt.Sprintf("branch%d", i)
err := c.DeleteBranch(ctx, repo, branchName)
if err != nil {
t.Fatal("Expected delete to succeed on", branchName, err)
}
err = c.DeleteBranch(ctx, repo, branchName)
if err == nil {
t.Fatal("Expected delete to fail on", branchName, err)
}
}
}