MCPcopy Index your code
hub / github.com/google/go-github / TestActionsService_DownloadArtifact

Function TestActionsService_DownloadArtifact

github/actions_artifacts_test.go:273–334  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

271}
272
273func TestActionsService_DownloadArtifact(t *testing.T) {
274 t.Parallel()
275
276 tcs := []struct {
277 name string
278 respectRateLimits bool
279 }{
280 {
281 name: "withoutRateLimits",
282 respectRateLimits: false,
283 },
284 {
285 name: "withRateLimits",
286 respectRateLimits: true,
287 },
288 }
289
290 for _, tc := range tcs {
291 t.Run(tc.name, func(t *testing.T) {
292 t.Parallel()
293 client, mux, _ := setup(t)
294 client.rateLimitRedirectionalEndpoints = tc.respectRateLimits
295
296 mux.HandleFunc("/repos/o/r/actions/artifacts/1/zip", func(w http.ResponseWriter, r *http.Request) {
297 testMethod(t, r, "GET")
298 http.Redirect(w, r, "https://github.com/artifact", http.StatusFound)
299 })
300
301 ctx := t.Context()
302 url, resp, err := client.Actions.DownloadArtifact(ctx, "o", "r", 1, 1)
303 if err != nil {
304 t.Errorf("Actions.DownloadArtifact returned error: %v", err)
305 }
306 if resp.StatusCode != http.StatusFound {
307 t.Errorf("Actions.DownloadArtifact returned status: %v, want %v", resp.StatusCode, http.StatusFound)
308 }
309
310 want := "https://github.com/artifact"
311 if url.String() != want {
312 t.Errorf("Actions.DownloadArtifact returned %+v, want %+v", url, want)
313 }
314
315 const methodName = "DownloadArtifact"
316 testBadOptions(t, methodName, func() (err error) {
317 _, _, err = client.Actions.DownloadArtifact(ctx, "\n", "\n", -1, 1)
318 return err
319 })
320
321 // Create "bad" client with custom round tripper
322 badClient, err := client.Clone(WithTransport(roundTripperFunc(func(*http.Request) (*http.Response, error) {
323 return nil, errors.New("failed to download artifact")
324 })))
325 if err != nil {
326 t.Fatalf("failed to clone client: %v", err)
327 }
328 testBadOptions(t, methodName, func() (err error) {
329 _, _, err = badClient.Actions.DownloadArtifact(ctx, "o", "r", 1, 1)
330 return err

Callers

nothing calls this directly

Calls 9

testMethodFunction · 0.85
testBadOptionsFunction · 0.85
WithTransportFunction · 0.85
roundTripperFuncFuncType · 0.85
DownloadArtifactMethod · 0.80
CloneMethod · 0.80
setupFunction · 0.70
RunMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…