(t *testing.T)
| 14 | ) |
| 15 | |
| 16 | func TestDownloadWorkflowArtifactsPageinates(t *testing.T) { |
| 17 | testRepoOwner := "OWNER" |
| 18 | testRepoName := "REPO" |
| 19 | testRunId := "1234567890" |
| 20 | |
| 21 | reg := &httpmock.Registry{} |
| 22 | defer reg.Verify(t) |
| 23 | |
| 24 | firstReq := httpmock.QueryMatcher( |
| 25 | "GET", |
| 26 | fmt.Sprintf("repos/%s/%s/actions/runs/%s/artifacts", testRepoOwner, testRepoName, testRunId), |
| 27 | url.Values{"per_page": []string{"100"}}, |
| 28 | ) |
| 29 | |
| 30 | firstArtifact := Artifact{ |
| 31 | Name: "artifact-0", |
| 32 | Size: 2, |
| 33 | DownloadURL: fmt.Sprintf("https://api.github.com/repos/%s/%s/actions/artifacts/987654320/zip", testRepoOwner, testRepoName), |
| 34 | Expired: true, |
| 35 | } |
| 36 | firstRes := httpmock.JSONResponse(artifactsPayload{Artifacts: []Artifact{firstArtifact}}) |
| 37 | testLinkUri := fmt.Sprintf("repositories/123456789/actions/runs/%s/artifacts", testRunId) |
| 38 | testLinkUrl := fmt.Sprintf("https://api.github.com/%s", testLinkUri) |
| 39 | firstRes = httpmock.WithHeader( |
| 40 | firstRes, |
| 41 | "Link", |
| 42 | fmt.Sprintf(`<%s?per_page=100&page=2>; rel="next", <%s?per_page=100&page=2>; rel="last"`, testLinkUrl, testLinkUrl), |
| 43 | ) |
| 44 | |
| 45 | secondReq := httpmock.QueryMatcher( |
| 46 | "GET", |
| 47 | testLinkUri, |
| 48 | url.Values{"per_page": []string{"100"}, "page": []string{"2"}}, |
| 49 | ) |
| 50 | |
| 51 | secondArtifact := Artifact{ |
| 52 | Name: "artifact-1", |
| 53 | Size: 2, |
| 54 | DownloadURL: fmt.Sprintf("https://api.github.com/repos/%s/%s/actions/artifacts/987654321/zip", testRepoOwner, testRepoName), |
| 55 | Expired: false, |
| 56 | } |
| 57 | secondRes := httpmock.JSONResponse(artifactsPayload{Artifacts: []Artifact{secondArtifact}}) |
| 58 | |
| 59 | reg.Register(firstReq, firstRes) |
| 60 | reg.Register(secondReq, secondRes) |
| 61 | |
| 62 | httpClient := &http.Client{Transport: reg} |
| 63 | repo := ghrepo.New(testRepoOwner, testRepoName) |
| 64 | |
| 65 | result, err := ListArtifacts(httpClient, repo, testRunId) |
| 66 | assert.NoError(t, err) |
| 67 | assert.Equal(t, []Artifact{firstArtifact, secondArtifact}, result) |
| 68 | } |
| 69 | |
| 70 | func TestListArtifactsReturnsAPIErrorMessage(t *testing.T) { |
| 71 | reg := &httpmock.Registry{} |
nothing calls this directly
no test coverage detected