Files
gitea-tea/internal/services/artifacts_test.go
T
bircni 9f69a89537 feat(run): show runs like gh, watch them live, and download artifacts
run list prints a table with a status icon, the workflow name, title,
branch, event, elapsed time and age, and the total from the server; runs
carry workflow, workflow_path and run_number in JSON. run view shows the
run's state and trigger, its jobs with their steps and durations, the
next steps and the run's URL; --json includes the jobs, --log prints
their logs and --web opens the run.

Run commands accept #N and run URLs, and ask for a recent run in a
terminal when the argument is left out. run watch redraws the run on the
alternate screen, then prints it with a summary; an expired --timeout
names the run and suspects a missing runner when no job started.

run cancel no longer asks for confirmation, rerun refuses unfinished runs
up front, reruns a single job with --job and reports the new attempt,
and delete names the run in its prompt. run logs follows several jobs
with --follow, prefixing lines with the job's name, selects jobs by name
or with --failed, and downloads the archive with --output or --dir.
run download extracts the artifacts of a run by name, and artifact list
shows sizes and expiry.

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

49 lines
2.1 KiB
Go

// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package services
import (
"context"
"encoding/json"
"net/http"
"testing"
gitea "gitea.dev/sdk"
"github.com/stretchr/testify/require"
)
func TestArtifactListingProjectsMetadataAndEmptyArrays(t *testing.T) {
client := newTestClient(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
require.Equal(t, http.MethodGet, r.Method)
require.Equal(t, "/api/v1/repos/owner/repo/actions/runs/7/artifacts", r.URL.Path)
require.Equal(t, "20", r.URL.Query().Get("limit"))
if r.URL.Query().Get("page") == "2" {
_, _ = w.Write([]byte(`{"artifacts":null,"total_count":0}`))
return
}
_, _ = w.Write([]byte(`{"artifacts":[{"id":9,"name":"build","size_in_bytes":128,"url":"https://example.test/artifact","expired":false,"expires_at":null,"workflow_run":{"head_sha":"excluded"},"archive_download_url":"excluded"}]}`))
}))
service := Actions{Client: client, Repository: "owner/repo"}
page, err := service.Artifacts(context.Background(), 7, 20, 1)
require.NoError(t, err)
require.Len(t, page.Items, 1)
data, err := json.Marshal(page.Items)
require.NoError(t, err)
require.JSONEq(t, `[{"id":9,"name":"build","size_in_bytes":128,"url":"https://example.test/artifact","expired":false,"created_at":"","updated_at":"","expires_at":null}]`, string(data))
page, err = service.Artifacts(context.Background(), 7, 20, 2)
require.NoError(t, err)
require.Empty(t, page.Items)
require.NotNil(t, page.Items)
}
func TestArtifactFromMapsServerFields(t *testing.T) {
artifact := decode[gitea.ActionsArtifact](t, `{"id":9,"name":"build","size_in_bytes":128,"url":"https://example.test/artifact","expired":true,
"created_at":"2028-01-02T03:04:05Z","updated_at":"2028-01-02T03:04:05Z","expires_at":"2028-01-03T03:04:05Z"}`)
expires := "2028-01-03T03:04:05Z"
require.Equal(t, Artifact{
ID: 9, Name: "build", Size: 128, URL: "https://example.test/artifact", Expired: true,
CreatedAt: "2028-01-02T03:04:05Z", UpdatedAt: "2028-01-02T03:04:05Z", ExpiresAt: &expires,
}, artifactFrom(artifact))
}