Skip to content

Commit 72f1ef6

Browse files
authored
Merge pull request #90 from tstromberg/reliable
increase test coverage
2 parents ca24da4 + a957c1f commit 72f1ef6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+10527
-102
lines changed

pkg/bot/bot_test.go

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,110 @@ func TestShouldPostThread(t *testing.T) {
512512
wantPost: true,
513513
wantReasonPart: "invalid_config",
514514
},
515+
{
516+
name: "passing: posts when in StateReviewedNeedsRefinement",
517+
when: "passing",
518+
checkResult: &turn.CheckResponse{
519+
PullRequest: prx.PullRequest{
520+
State: "open",
521+
},
522+
Analysis: turn.Analysis{
523+
WorkflowState: string(turn.StateReviewedNeedsRefinement),
524+
},
525+
},
526+
wantPost: true,
527+
wantReasonPart: "workflow_state",
528+
},
529+
{
530+
name: "passing: posts when in StateRefinedWaitingForApproval",
531+
when: "passing",
532+
checkResult: &turn.CheckResponse{
533+
PullRequest: prx.PullRequest{
534+
State: "open",
535+
},
536+
Analysis: turn.Analysis{
537+
WorkflowState: string(turn.StateRefinedWaitingForApproval),
538+
},
539+
},
540+
wantPost: true,
541+
wantReasonPart: "workflow_state",
542+
},
543+
{
544+
name: "passing: posts when in StateApprovedWaitingForMerge",
545+
when: "passing",
546+
checkResult: &turn.CheckResponse{
547+
PullRequest: prx.PullRequest{
548+
State: "open",
549+
},
550+
Analysis: turn.Analysis{
551+
WorkflowState: string(turn.StateApprovedWaitingForMerge),
552+
},
553+
},
554+
wantPost: true,
555+
wantReasonPart: "workflow_state",
556+
},
557+
{
558+
name: "passing: does not post when StateNewlyPublished",
559+
when: "passing",
560+
checkResult: &turn.CheckResponse{
561+
PullRequest: prx.PullRequest{
562+
State: "open",
563+
},
564+
Analysis: turn.Analysis{
565+
WorkflowState: string(turn.StateNewlyPublished),
566+
},
567+
},
568+
wantPost: false,
569+
wantReasonPart: "waiting_for",
570+
},
571+
{
572+
name: "passing: does not post when StateInDraft",
573+
when: "passing",
574+
checkResult: &turn.CheckResponse{
575+
PullRequest: prx.PullRequest{
576+
State: "open",
577+
},
578+
Analysis: turn.Analysis{
579+
WorkflowState: string(turn.StateInDraft),
580+
},
581+
},
582+
wantPost: false,
583+
wantReasonPart: "waiting_for",
584+
},
585+
{
586+
name: "passing: does not post when StateTestedWaitingForAssignment",
587+
when: "passing",
588+
checkResult: &turn.CheckResponse{
589+
PullRequest: prx.PullRequest{
590+
State: "open",
591+
},
592+
Analysis: turn.Analysis{
593+
WorkflowState: string(turn.StateTestedWaitingForAssignment),
594+
},
595+
},
596+
wantPost: false,
597+
wantReasonPart: "waiting_for",
598+
},
599+
{
600+
name: "passing: uses fallback when tests have Waiting status",
601+
when: "passing",
602+
checkResult: &turn.CheckResponse{
603+
PullRequest: prx.PullRequest{
604+
State: "open",
605+
},
606+
Analysis: turn.Analysis{
607+
WorkflowState: "unknown_state",
608+
Checks: turn.Checks{
609+
Passing: 0,
610+
Failing: 0,
611+
Pending: 0,
612+
Waiting: 3,
613+
},
614+
},
615+
},
616+
wantPost: false,
617+
wantReasonPart: "tests_pending",
618+
},
515619
}
516620

517621
for _, tt := range tests {

pkg/bot/coordinator_test_helpers.go

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,20 @@ import (
1818
//
1919
//nolint:govet // fieldalignment optimization would reduce test readability
2020
type mockStateStore struct {
21-
markProcessedErr error
22-
saveThreadErr error
23-
saveDMMessageErr error
24-
threads map[string]cache.ThreadInfo
25-
dmTimes map[string]time.Time
26-
dmUsers map[string][]string
27-
dmMessages map[string]state.DMInfo
28-
pendingDMs []*state.PendingDM
29-
processedEvents map[string]bool
30-
lastNotifications map[string]time.Time
31-
mu sync.Mutex
21+
markProcessedErr error
22+
saveThreadErr error
23+
saveDMMessageErr error
24+
queuePendingDMErr error
25+
pendingDMsErr error
26+
removePendingDMErr error
27+
threads map[string]cache.ThreadInfo
28+
dmTimes map[string]time.Time
29+
dmUsers map[string][]string
30+
dmMessages map[string]state.DMInfo
31+
pendingDMs []*state.PendingDM
32+
processedEvents map[string]bool
33+
lastNotifications map[string]time.Time
34+
mu sync.Mutex
3235
}
3336

3437
func (m *mockStateStore) Thread(ctx context.Context, owner, repo string, number int, channelID string) (cache.ThreadInfo, bool) {
@@ -180,13 +183,19 @@ func (m *mockStateStore) RecordNotification(ctx context.Context, prURL string, n
180183
func (m *mockStateStore) QueuePendingDM(ctx context.Context, dm *state.PendingDM) error {
181184
m.mu.Lock()
182185
defer m.mu.Unlock()
186+
if m.queuePendingDMErr != nil {
187+
return m.queuePendingDMErr
188+
}
183189
m.pendingDMs = append(m.pendingDMs, dm)
184190
return nil
185191
}
186192

187193
func (m *mockStateStore) PendingDMs(ctx context.Context, before time.Time) ([]state.PendingDM, error) {
188194
m.mu.Lock()
189195
defer m.mu.Unlock()
196+
if m.pendingDMsErr != nil {
197+
return nil, m.pendingDMsErr
198+
}
190199
var result []state.PendingDM
191200
for _, dm := range m.pendingDMs {
192201
if dm.SendAfter.Before(before) {
@@ -199,6 +208,9 @@ func (m *mockStateStore) PendingDMs(ctx context.Context, before time.Time) ([]st
199208
func (m *mockStateStore) RemovePendingDM(ctx context.Context, id string) error {
200209
m.mu.Lock()
201210
defer m.mu.Unlock()
211+
if m.removePendingDMErr != nil {
212+
return m.removePendingDMErr
213+
}
202214
for i, dm := range m.pendingDMs {
203215
if dm.ID == id {
204216
m.pendingDMs = append(m.pendingDMs[:i], m.pendingDMs[i+1:]...)

0 commit comments

Comments
 (0)