From a449a1a6f727368ae597c9789a201800899d756c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Wed, 7 Apr 2021 20:22:30 +0200 Subject: [PATCH] Add tests for artifact rendering in `run view` --- pkg/cmd/run/view/view.go | 16 ++++++------- pkg/cmd/run/view/view_test.go | 43 +++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 9 deletions(-) diff --git a/pkg/cmd/run/view/view.go b/pkg/cmd/run/view/view.go index fe38ab033..31494879b 100644 --- a/pkg/cmd/run/view/view.go +++ b/pkg/cmd/run/view/view.go @@ -277,17 +277,15 @@ func runView(opts *ViewOptions) error { } if selectedJob == nil { - var validArtifacts []shared.Artifact - for _, a := range artifacts { - if !a.Expired { - validArtifacts = append(validArtifacts, a) - } - } - if len(validArtifacts) > 0 { + if len(artifacts) > 0 { fmt.Fprintln(out) fmt.Fprintln(out, cs.Bold("ARTIFACTS")) - for _, a := range validArtifacts { - fmt.Fprintln(out, a.Name) + for _, a := range artifacts { + expiredBadge := "" + if a.Expired { + expiredBadge = cs.Gray(" (expired)") + } + fmt.Fprintf(out, "%s%s\n", a.Name, expiredBadge) } } diff --git a/pkg/cmd/run/view/view_test.go b/pkg/cmd/run/view/view_test.go index e652ee695..b88995e07 100644 --- a/pkg/cmd/run/view/view_test.go +++ b/pkg/cmd/run/view/view_test.go @@ -7,6 +7,7 @@ import ( "testing" "time" + "github.com/MakeNowJust/heredoc" "github.com/cli/cli/internal/ghrepo" "github.com/cli/cli/pkg/cmd/run/shared" "github.com/cli/cli/pkg/cmdutil" @@ -205,6 +206,48 @@ func TestViewRun(t *testing.T) { wantOut: "\nX trunk failed · 1234\nTriggered via push about 59 minutes ago\n\nJOBS\nX sad job in 4m34s (ID 20)\n ✓ barf the quux\n X quux the barf\n\nANNOTATIONS\nX the job is sad\nsad job: blaze.py#420\n\n\nFor more information about a job, try: gh run view --job=\nview this run on GitHub: runs/1234\n", wantErr: true, }, + { + name: "with artifacts", + opts: &ViewOptions{ + RunID: "3", + }, + httpStubs: func(reg *httpmock.Registry) { + reg.Register( + httpmock.REST("GET", "repos/OWNER/REPO/actions/runs/3"), + httpmock.JSONResponse(shared.SuccessfulRun)) + reg.Register( + httpmock.REST("GET", "repos/OWNER/REPO/actions/runs/3/artifacts"), + httpmock.JSONResponse(map[string][]shared.Artifact{ + "artifacts": { + shared.Artifact{Name: "artifact-1", Expired: false}, + shared.Artifact{Name: "artifact-2", Expired: true}, + shared.Artifact{Name: "artifact-3", Expired: false}, + }, + })) + reg.Register( + httpmock.GraphQL(`query PullRequestForRun`), + httpmock.StringResponse(``)) + reg.Register( + httpmock.REST("GET", "runs/3/jobs"), + httpmock.JSONResponse(shared.JobsPayload{})) + }, + wantOut: heredoc.Doc(` + + ✓ trunk successful · 3 + Triggered via push about 59 minutes ago + + JOBS + + + ARTIFACTS + artifact-1 + artifact-2 (expired) + artifact-3 + + For more information about a job, try: gh run view --job= + view this run on GitHub: runs/3 + `), + }, { name: "exit status, successful run", opts: &ViewOptions{