Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyaug committed Sep 27, 2023
1 parent e6f1c40 commit 41177d3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
7 changes: 4 additions & 3 deletions pkg/api/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3091,9 +3091,10 @@ func (c *Controller) InternalCreateBranchProtectionRule(w http.ResponseWriter, r
}
}
if rules == nil {
rules = &graveler.BranchProtectionRules{
BranchPatternToBlockedActions: make(map[string]*graveler.BranchProtectionBlockedActions),
}
rules = &graveler.BranchProtectionRules{}
}
if rules.BranchPatternToBlockedActions == nil {
rules.BranchPatternToBlockedActions = make(map[string]*graveler.BranchProtectionBlockedActions)
}
blockedActions := &graveler.BranchProtectionBlockedActions{
Value: []graveler.BranchProtectionBlockedAction{graveler.BranchProtectionBlockedAction_STAGING_WRITE, graveler.BranchProtectionBlockedAction_COMMIT},
Expand Down
10 changes: 6 additions & 4 deletions pkg/graveler/branch/protection_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ func TestSetAndGet(t *testing.T) {
ctx := context.Background()
bpm := prepareTest(t, ctx)
rules, eTag, err := bpm.GetRules(ctx, repository)
if !errors.Is(err, graveler.ErrNotFound) {
t.Fatalf("expected ErrNotFound, got %v", err)
testutil.Must(t, err)
if len(rules.BranchPatternToBlockedActions) != 0 {
t.Fatalf("expected no rules, got %d rules", len(rules.BranchPatternToBlockedActions))
}
testutil.Must(t, bpm.SetRulesIf(ctx, repository, &graveler.BranchProtectionRules{
BranchPatternToBlockedActions: map[string]*graveler.BranchProtectionBlockedActions{
Expand Down Expand Up @@ -90,8 +91,9 @@ func TestDelete(t *testing.T) {
testutil.Must(t, bpm.Delete(ctx, repository, "main*"))

rules, _, err = bpm.GetRules(ctx, repository)
if !errors.Is(err, graveler.ErrNotFound) {
t.Fatalf("expected ErrNotFound after delete, got %v", err)
testutil.Must(t, err)
if len(rules.BranchPatternToBlockedActions) != 0 {
t.Fatalf("expected no rules, got %d rules", len(rules.BranchPatternToBlockedActions))
}
}

Expand Down
20 changes: 17 additions & 3 deletions pkg/graveler/mock/graveler.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 41177d3

Please sign in to comment.