diff --git a/pkg/cmd/pr/checks/output.go b/pkg/cmd/pr/checks/output.go index 24105c3e226..581a8a88418 100644 --- a/pkg/cmd/pr/checks/output.go +++ b/pkg/cmd/pr/checks/output.go @@ -68,7 +68,7 @@ func addRow(tp *tableprinter.TablePrinter, io *iostreams.IOStreams, o check) { func printSummary(io *iostreams.IOStreams, counts checkCounts) { summary := "" - if counts.Failed+counts.Passed+counts.Skipping+counts.Pending > 0 { + if counts.Failed+counts.Passed+counts.Skipping+counts.Pending+counts.Canceled > 0 { if counts.Failed > 0 { summary = "Some checks were not successful" } else if counts.Pending > 0 { diff --git a/pkg/cmd/pr/checks/output_test.go b/pkg/cmd/pr/checks/output_test.go new file mode 100644 index 00000000000..aa3eed04725 --- /dev/null +++ b/pkg/cmd/pr/checks/output_test.go @@ -0,0 +1,55 @@ +package checks + +import ( + "testing" + + "github.com/cli/cli/v2/pkg/iostreams" + "github.com/stretchr/testify/require" +) + +func TestPrintSummary(t *testing.T) { + tests := []struct { + name string + counts checkCounts + want string + }{ + { + name: "no checks", + counts: checkCounts{}, + want: "\n\n", + }, + { + name: "all successful", + counts: checkCounts{Passed: 3}, + want: "All checks were successful\n0 cancelled, 0 failing, 3 successful, 0 skipped, and 0 pending checks\n\n", + }, + { + name: "some failed", + counts: checkCounts{Failed: 1, Passed: 2}, + want: "Some checks were not successful\n0 cancelled, 1 failing, 2 successful, 0 skipped, and 0 pending checks\n\n", + }, + { + name: "some pending", + counts: checkCounts{Pending: 1, Passed: 2}, + want: "Some checks are still pending\n0 cancelled, 0 failing, 2 successful, 0 skipped, and 1 pending checks\n\n", + }, + { + // Regression: before the fix, the guard omitted counts.Canceled, so a + // cancelled-only result printed an empty summary. + name: "only cancelled", + counts: checkCounts{Canceled: 2}, + want: "Some checks were cancelled\n2 cancelled, 0 failing, 0 successful, 0 skipped, and 0 pending checks\n\n", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + ios, _, stdout, _ := iostreams.Test() + ios.SetStdoutTTY(true) + + printSummary(ios, tt.counts) + + require.Equal(t, tt.want, stdout.String()) + }) + } +}