Skip to content

Commit

Permalink
Add simple test for PushRestrictionMerger
Browse files Browse the repository at this point in the history
  • Loading branch information
bluekeyes committed Mar 26, 2019
1 parent 98e24de commit 744ba82
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions bulldozer/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,32 @@ import (
"context"
"testing"

"github.com/google/go-github/github"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/palantir/bulldozer/pull"
"github.com/palantir/bulldozer/pull/pulltest"
)

type MockMerger struct {
MergeCount int
MergeError error

DeleteCount int
DeleteError error
}

func (m *MockMerger) Merge(ctx context.Context, pullCtx pull.Context, message string, options *github.PullRequestOptions) (string, error) {
m.MergeCount++
return "deadbeef", m.MergeError
}

func (m *MockMerger) DeleteHead(ctx context.Context, pullCtx pull.Context) error {
m.DeleteCount++
return m.DeleteError
}

func TestCalculateCommitTitle(t *testing.T) {
defaultPullContext := &pulltest.MockPullContext{
NumberValue: 12,
Expand Down Expand Up @@ -78,3 +97,30 @@ func TestCalculateCommitTitle(t *testing.T) {
})
}
}

func TestPushRestrictionMerger(t *testing.T) {
normal := &MockMerger{}
restricted := &MockMerger{}
merger := NewPushRestrictionMerger(normal, restricted)

ctx := context.Background()
pullCtx := &pulltest.MockPullContext{}

_, _ = merger.Merge(ctx, pullCtx, "", nil)
assert.Equal(t, 1, normal.MergeCount, "normal merge was not called")
assert.Equal(t, 0, restricted.MergeCount, "restricted merge was incorrectly called")

_ = merger.DeleteHead(ctx, pullCtx)
assert.Equal(t, 1, normal.DeleteCount, "normal delete was not called")
assert.Equal(t, 0, restricted.DeleteCount, "restricted delete was incorrectly called")

pullCtx.PushRestrictionsValue = true

_, _ = merger.Merge(ctx, pullCtx, "", nil)
assert.Equal(t, 1, normal.MergeCount, "normal merge was incorrectly called")
assert.Equal(t, 1, restricted.MergeCount, "restricted merge was not called")

_ = merger.DeleteHead(ctx, pullCtx)
assert.Equal(t, 1, normal.DeleteCount, "normal delete was incorrectly called")
assert.Equal(t, 1, restricted.DeleteCount, "restricted delete was not called")
}

0 comments on commit 744ba82

Please sign in to comment.