MCPcopy Create free account
hub / github.com/github/gh-aw / TestRunUpdateForOrgStopsOnCriticalRateLimit

Function TestRunUpdateForOrgStopsOnCriticalRateLimit

pkg/cli/update_org_test.go:371–419  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

369}
370
371func TestRunUpdateForOrgStopsOnCriticalRateLimit(t *testing.T) {
372 origSearch := searchOrgWorkflowReposFn
373 origPreview := previewOrgRepoUpdatesFn
374 origUpdate := runUpdateForTargetRepoFn
375 origWait := waitForOrgRateLimitFn
376 searchOrgWorkflowReposFn = func(ctx context.Context, org string, workflowNames []string, verbose bool) ([]string, error) {
377 return []string{"octo/a", "octo/b", "octo/c"}, nil
378 }
379 var previewed []string
380 previewOrgRepoUpdatesFn = func(ctx context.Context, repo string, opts UpdateWorkflowsOptions, verbose bool) (orgRepoPreview, error) {
381 previewed = append(previewed, repo)
382 return orgRepoPreview{
383 Repo: repo,
384 TotalWorkflows: 1,
385 Workflows: []orgWorkflowPreview{{
386 Name: "repo-assist",
387 CurrentRef: "v1.0.0",
388 LatestRef: "v1.1.0",
389 }},
390 }, nil
391 }
392 runUpdateForTargetRepoFn = func(ctx context.Context, targetRepo string, opts UpdateWorkflowsOptions, createPR bool, verbose bool) error {
393 return nil
394 }
395 calls := 0
396 waitForOrgRateLimitFn = func(ctx context.Context, resource string, verbose bool) error {
397 calls++
398 if calls >= 2 {
399 return errOrgRateLimitCritical
400 }
401 return nil
402 }
403 defer func() {
404 searchOrgWorkflowReposFn = origSearch
405 previewOrgRepoUpdatesFn = origPreview
406 runUpdateForTargetRepoFn = origUpdate
407 waitForOrgRateLimitFn = origWait
408 }()
409
410 output := captureUpdateOrgStderr(t, func() {
411 err := runUpdateForOrg(context.Background(), "octo", nil, UpdateWorkflowsOptions{}, false, false, false)
412 require.NoError(t, err)
413 })
414
415 // Critical budget on the second repo stops the scan but still shows the report.
416 assert.Equal(t, []string{"octo/a"}, previewed)
417 assert.Contains(t, output, "budget critical")
418 assert.Contains(t, output, "- octo/a")
419}
420
421func TestRunUpdateForOrgStopsOnCancellation(t *testing.T) {
422 origSearch := searchOrgWorkflowReposFn

Callers

nothing calls this directly

Calls 3

captureUpdateOrgStderrFunction · 0.85
runUpdateForOrgFunction · 0.85
BackgroundMethod · 0.80

Tested by

no test coverage detected