test(actions): drop duplicate cases and share the checks server

Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
bircni committed 2026-10-12 20:48:00 +02:00
1 parent 71d84b070b
commit 4a85bb3d40
5 files changed
+13 -29

No files matched your search

-4
View File
@@ -122,10 +122,6 @@ func (p *dispatchingPrompter) Ask(_ context.Context, title string, validate func
return answer, validate(answer) return answer, validate(answer)
} }
func (p *dispatchingPrompter) AskText(context.Context, string, string) (string, error) {
return "", nil
}
func (p *dispatchingPrompter) ConfirmDefault(_ context.Context, title string, defaultYes bool) (bool, error) { func (p *dispatchingPrompter) ConfirmDefault(_ context.Context, title string, defaultYes bool) (bool, error) {
p.asked = append(p.asked, title) p.asked = append(p.asked, title)
return !defaultYes, nil return !defaultYes, nil
+2 -6
View File
@@ -11,6 +11,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
"strings"
"testing" "testing"
"gitea.dev/tea/internal/clierr" "gitea.dev/tea/internal/clierr"
@@ -97,7 +98,7 @@ func TestRunDownloadExtractsArtifactsByName(t *testing.T) {
return return
} }
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, filepathReplace(tc.out, dir), diagnostics.String()) require.Equal(t, strings.ReplaceAll(tc.out, "{dir}", dir), diagnostics.String())
for name, content := range tc.files { for name, content := range tc.files {
data, err := os.ReadFile(filepath.Join(dir, name)) data, err := os.ReadFile(filepath.Join(dir, name))
require.NoError(t, err, name) require.NoError(t, err, name)
@@ -153,11 +154,6 @@ func TestExtractZipKeepsPermissionBits(t *testing.T) {
} }
} }
// filepathReplace puts dir in place of {dir} in text.
func filepathReplace(text, dir string) string {
return string(bytes.ReplaceAll([]byte(text), []byte("{dir}"), []byte(dir)))
}
func TestArtifactListShowsSizesAndExpiry(t *testing.T) { func TestArtifactListShowsSizesAndExpiry(t *testing.T) {
server, _ := actionsAPI(t, map[string]string{ server, _ := actionsAPI(t, map[string]string{
"GET actions/runs/29/artifacts": `{"total_count":2,"artifacts":[{"id":1,"name":"build","size_in_bytes":3145728,"expires_at":"2028-03-01T12:00:00Z"},{"id":3,"name":"old","size_in_bytes":13,"expired":true,"expires_at":"2027-12-01T12:00:00Z"}]}`, "GET actions/runs/29/artifacts": `{"total_count":2,"artifacts":[{"id":1,"name":"build","size_in_bytes":3145728,"expires_at":"2028-03-01T12:00:00Z"},{"id":3,"name":"old","size_in_bytes":13,"expired":true,"expires_at":"2027-12-01T12:00:00Z"}]}`,
+11 -14
View File
@@ -6,6 +6,7 @@ package app
import ( import (
"context" "context"
"net/http" "net/http"
"net/http/httptest"
"strings" "strings"
"testing" "testing"
@@ -109,17 +110,7 @@ func TestChecksSummaryAndExitCodes(t *testing.T) {
{name: "none", statuses: `[]`}, {name: "none", statuses: `[]`},
} { } {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
server := newAuthenticatedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { server := checksServer(t, tc.statuses)
switch {
case r.URL.Path == "/api/v1/repos/alice/x/pulls/8":
_, _ = w.Write([]byte(`{"number":8,"head":{"sha":"abc"}}`))
case r.URL.Query().Get("page") == "1":
_, _ = w.Write([]byte(tc.statuses))
default:
_, _ = w.Write([]byte(`[]`))
}
}))
defer server.Close()
deps, out, diagnostics := serverDeps(t, server.URL) deps, out, diagnostics := serverDeps(t, server.URL)
plainTTY(t, &deps, server.URL) plainTTY(t, &deps, server.URL)
err := Execute(context.Background(), deps, []string{"pr", "checks", "8", "-R", "alice/x"}) err := Execute(context.Background(), deps, []string{"pr", "checks", "8", "-R", "alice/x"})
@@ -135,18 +126,24 @@ func TestChecksSummaryAndExitCodes(t *testing.T) {
} }
} }
func TestChecksWatchTimeoutCountsPendingChecks(t *testing.T) { // checksServer serves pull request alice/x#8 whose head commit has statuses.
func checksServer(t *testing.T, statuses string) *httptest.Server {
server := newAuthenticatedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { server := newAuthenticatedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch { switch {
case r.URL.Path == "/api/v1/repos/alice/x/pulls/8": case r.URL.Path == "/api/v1/repos/alice/x/pulls/8":
_, _ = w.Write([]byte(`{"number":8,"head":{"sha":"abc"}}`)) _, _ = w.Write([]byte(`{"number":8,"head":{"sha":"abc"}}`))
case r.URL.Query().Get("page") == "1": case r.URL.Query().Get("page") == "1":
_, _ = w.Write([]byte(`[{"id":1,"context":"a","status":"pending"},{"id":2,"context":"b","status":"pending"}]`)) _, _ = w.Write([]byte(statuses))
default: default:
_, _ = w.Write([]byte(`[]`)) _, _ = w.Write([]byte(`[]`))
} }
})) }))
defer server.Close() t.Cleanup(server.Close)
return server
}
func TestChecksWatchTimeoutCountsPendingChecks(t *testing.T) {
server := checksServer(t, `[{"id":1,"context":"a","status":"pending"},{"id":2,"context":"b","status":"pending"}]`)
deps, _, _ := serverDeps(t, server.URL) deps, _, _ := serverDeps(t, server.URL)
err := Execute(context.Background(), deps, []string{"pr", "checks", "8", "-R", "alice/x", "--watch", "--interval=1ms", "--timeout=30ms"}) err := Execute(context.Background(), deps, []string{"pr", "checks", "8", "-R", "alice/x", "--watch", "--interval=1ms", "--timeout=30ms"})
require.EqualError(t, err, "timed out after 30ms waiting for 2 pending checks") require.EqualError(t, err, "timed out after 30ms waiting for 2 pending checks")
-3
View File
@@ -96,9 +96,7 @@ func TestDownloadDestinations(t *testing.T) {
{name: "existing in --dir", flags: downloadFlags{dir: "dl"}, file: "existing.txt", err: filepath.Join("dl", "existing.txt") + " already exists"}, {name: "existing in --dir", flags: downloadFlags{dir: "dl"}, file: "existing.txt", err: filepath.Join("dl", "existing.txt") + " already exists"},
{name: "--clobber", flags: downloadFlags{clobber: true}, file: "existing.txt", want: "existing.txt"}, {name: "--clobber", flags: downloadFlags{clobber: true}, file: "existing.txt", want: "existing.txt"},
{name: "--skip-existing", flags: downloadFlags{skipExisting: true}, file: "existing.txt", want: "existing.txt", skip: true}, {name: "--skip-existing", flags: downloadFlags{skipExisting: true}, file: "existing.txt", want: "existing.txt", skip: true},
{name: "--skip-existing new file", flags: downloadFlags{skipExisting: true}, file: "notes.txt", want: "notes.txt"},
{name: "parent directory name", file: "../escape.txt", err: `cannot use "../escape.txt" as a file name; pass --output`}, {name: "parent directory name", file: "../escape.txt", err: `cannot use "../escape.txt" as a file name; pass --output`},
{name: "nested name", file: "a/b.txt", err: "cannot use"},
{name: "dot dot", file: "..", err: "cannot use"}, {name: "dot dot", file: "..", err: "cannot use"},
{name: "--output and --dir", flags: downloadFlags{output: "x", dir: "dl"}, file: "notes.txt", err: "--output and --dir cannot be combined"}, {name: "--output and --dir", flags: downloadFlags{output: "x", dir: "dl"}, file: "notes.txt", err: "--output and --dir cannot be combined"},
{name: "--clobber and --skip-existing", flags: downloadFlags{clobber: true, skipExisting: true}, file: "notes.txt", err: "--clobber and --skip-existing cannot be combined"}, {name: "--clobber and --skip-existing", flags: downloadFlags{clobber: true, skipExisting: true}, file: "notes.txt", err: "--clobber and --skip-existing cannot be combined"},
@@ -146,7 +144,6 @@ func TestDownloadsToATerminalRefuseBinaryData(t *testing.T) {
err string err string
}{ }{
{name: "piped binary stays byte exact", body: "PK\x03\x04\x00\x01", want: "PK\x03\x04\x00\x01"}, {name: "piped binary stays byte exact", body: "PK\x03\x04\x00\x01", want: "PK\x03\x04\x00\x01"},
{name: "terminal text", body: "hello\nworld\n", want: "hello\nworld\n", tty: true},
{name: "terminal text loses escapes", body: "title\x1b]0;PWNED\x07\n", want: "title]0;PWNED\n", tty: true}, {name: "terminal text loses escapes", body: "title\x1b]0;PWNED\x07\n", want: "title]0;PWNED\n", tty: true},
{name: "terminal binary", body: "PK\x03\x04\x00\x01", tty: true, err: "refusing to write binary data to the terminal"}, {name: "terminal binary", body: "PK\x03\x04\x00\x01", tty: true, err: "refusing to write binary data to the terminal"},
{name: "terminal invalid UTF-8", body: "abc\xff\xfedef", tty: true, err: "refusing to write binary data"}, {name: "terminal invalid UTF-8", body: "abc\xff\xfedef", tty: true, err: "refusing to write binary data"},
-2
View File
@@ -19,7 +19,6 @@ func TestWebhookCreateValidatesEventsAndTypes(t *testing.T) {
want string want string
}{ }{
{[]string{"--events", "pushh"}, "--events must be create, delete, fork, push, issues"}, {[]string{"--events", "pushh"}, "--events must be create, delete, fork, push, issues"},
{[]string{"--events", "push,pull_request_review_approved"}, "--events must be"},
{[]string{"--type", "slackk"}, "--type must be gitea, gogs, slack"}, {[]string{"--type", "slackk"}, "--type must be gitea, gogs, slack"},
{[]string{"--type", "slack"}, "--type slack needs a channel: --config channel=#name"}, {[]string{"--type", "slack"}, "--type slack needs a channel: --config channel=#name"},
} { } {
@@ -50,7 +49,6 @@ func TestWebhookEventsCollapseCompleteGroups(t *testing.T) {
events []string events []string
want string want string
}{ }{
{[]string{"push"}, "push"},
{[]string{"issue_assign", "issue_comment", "issue_label", "issue_milestone", "issues", "push"}, "issues (5), push"}, {[]string{"issue_assign", "issue_comment", "issue_label", "issue_milestone", "issues", "push"}, "issues (5), push"},
{[]string{"issue_label", "issues"}, "issue_label, issues"}, {[]string{"issue_label", "issues"}, "issue_label, issues"},
{append([]string{"create"}, pulls...), "create, pull_request (8)"}, {append([]string{"create"}, pulls...), "create, pull_request (8)"},