Files
gitea-tea/internal/clierr/errors_test.go
T
bircni 2c5e005bcf fix(pr): report checks like gh, exit 8 while they are pending
tea pr checks printed relative links, "Error: pull request checks have
not all succeeded" with exit 1 for checks that were only pending, and
nothing at all without checks. It now heads the table with a colored
verdict and "0 failing, 1 successful, and 2 pending checks", prints a
status icon and absolute links, and exits 8 while checks are pending
and 1 when one failed, without an Error line (D21). clierr.Quiet
carries such an exit code past main without a message. Without checks
it says "no checks reported for pull request alice/x#8".

--watch redraws the summary in place on a terminal, and an expired
--timeout reads "timed out after 3s waiting for 2 pending checks". The
pull request argument is optional, and --web opens the pull request.

Signed-off-by: bircni <bircni@icloud.com>
2026-10-11 23:54:47 +02:00

36 lines
1004 B
Go

// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package clierr
import (
"context"
"errors"
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestExitCodeDistinguishesCancellationAndInterruption(t *testing.T) {
for _, test := range []struct {
err error
code int
}{
{nil, 0},
{errors.New("operation failed"), Failure},
{Wrap(Usage, errors.New("missing input")), Usage},
{Wrap(Authentication, errors.New("login required")), Authentication},
{context.Canceled, Canceled},
{context.DeadlineExceeded, Canceled},
{Wrap(Authentication, context.Canceled), Canceled},
{fmt.Errorf("draft preserved: %w", context.DeadlineExceeded), Canceled},
{Wrap(Interrupted, context.Canceled), Interrupted},
{errors.Join(errors.New("partial failure"), context.Canceled), Canceled},
{Quiet(Pending), Pending},
{fmt.Errorf("checks: %w", Quiet(Failure)), Failure},
} {
assert.Equal(t, test.code, ExitCode(test.err), "%v", test.err)
}
}