Skip to content

Commit

Permalink
actually still need legacyhandler
Browse files Browse the repository at this point in the history
  • Loading branch information
smonero committed Aug 13, 2024
1 parent 5d92995 commit 62093e2
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions server/neptune/gateway/event/modified_pull_request_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ func TestModifiedPullHandler_Handle_SignalerFailure(t *testing.T) {
expectedT: t,
rootConfigs: []*valid.MergedProjectCfg{root},
},
LegacyHandler: &mockLegacyHandler{
expectedAllRoots: []*valid.MergedProjectCfg{root},
expectedT: t,
},
PRSignaler: &mockPRSignaler{
error: assert.AnError,
expectedRoots: []*valid.MergedProjectCfg{root},
Expand Down Expand Up @@ -106,6 +110,11 @@ func TestModifiedPullHandler_Handle_BranchStrategy(t *testing.T) {
pull := event.PullRequest{
Pull: pullRequest,
}
legacyHandler := &mockLegacyHandler{
expectedEvent: pull,
expectedAllRoots: []*valid.MergedProjectCfg{legacyRoot},
expectedT: t,
}
prRequest := pr.Request{
Revision: "sha",
Repo: testRepo,
Expand Down Expand Up @@ -134,10 +143,12 @@ func TestModifiedPullHandler_Handle_BranchStrategy(t *testing.T) {
expectedT: t,
rootConfigs: []*valid.MergedProjectCfg{legacyRoot},
},
PRSignaler: signaler,
LegacyHandler: legacyHandler,
PRSignaler: signaler,
}
err := pullHandler.Handle(context.Background(), &http.BufferedRequest{}, pull)
assert.NoError(t, err)
assert.True(t, legacyHandler.called)
assert.True(t, signaler.called)
}

Expand Down Expand Up @@ -185,6 +196,11 @@ func TestModifiedPullHandler_Handle_MergeStrategy(t *testing.T) {
pr := event.PullRequest{
Pull: pullRequest,
}
legacyHandler := &mockLegacyHandler{
expectedEvent: pr,
expectedAllRoots: []*valid.MergedProjectCfg{root},
expectedT: t,
}
pullHandler := event.ModifiedPullHandler{
Logger: logger,
Scheduler: &sync.SynchronousScheduler{Logger: logger},
Expand All @@ -195,10 +211,12 @@ func TestModifiedPullHandler_Handle_MergeStrategy(t *testing.T) {
expectedT: t,
rootConfigs: []*valid.MergedProjectCfg{root},
},
PRSignaler: signaler,
LegacyHandler: legacyHandler,
PRSignaler: signaler,
}
err := pullHandler.Handle(context.Background(), &http.BufferedRequest{}, pr)
assert.NoError(t, err)
assert.True(t, legacyHandler.called)
assert.True(t, signaler.called)
}

Expand All @@ -219,6 +237,21 @@ func (r *mockConfigBuilder) Build(_ context.Context, commit *config.RepoCommit,
return r.rootConfigs, r.error
}

type mockLegacyHandler struct {
expectedEvent event.PullRequest
expectedAllRoots []*valid.MergedProjectCfg
expectedT *testing.T
error error
called bool
}

func (l *mockLegacyHandler) Handle(ctx context.Context, _ *http.BufferedRequest, event event.PullRequest, allRoots []*valid.MergedProjectCfg) error {
l.called = true
assert.Equal(l.expectedT, l.expectedEvent, event)
assert.Equal(l.expectedT, l.expectedAllRoots, allRoots)
return l.error
}

type mockPRSignaler struct {
called bool
error error
Expand Down

0 comments on commit 62093e2

Please sign in to comment.