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

Function TestRunGHFunctions

pkg/workflow/github_cli_test.go:345–383  ·  view source on GitHub ↗

TestRunGHFunctions tests that RunGH and RunGHCombined delegate correctly to their context variants.

(t *testing.T)

Source from the content-addressed store, hash-verified

343
344// TestRunGHFunctions tests that RunGH and RunGHCombined delegate correctly to their context variants.
345func TestRunGHFunctions(t *testing.T) {
346 // Save original environment
347 originalGHToken := os.Getenv("GH_TOKEN")
348 originalGitHubToken := os.Getenv("GITHUB_TOKEN")
349 defer func() {
350 os.Setenv("GH_TOKEN", originalGHToken)
351 os.Setenv("GITHUB_TOKEN", originalGitHubToken)
352 }()
353
354 // Set up test environment with no tokens to keep behavior deterministic for unit tests.
355 os.Unsetenv("GH_TOKEN")
356 os.Unsetenv("GITHUB_TOKEN")
357
358 t.Run("RunGH matches RunGHContext", func(t *testing.T) {
359 gotOut, gotErr := RunGH("Test spinner...", "auth", "status")
360 wantOut, wantErr := RunGHContext(context.Background(), "Test spinner...", "auth", "status")
361
362 assert.Equal(t, wantOut, gotOut, "RunGH should return the same output as RunGHContext")
363 if wantErr == nil {
364 assert.NoError(t, gotErr, "RunGH should match RunGHContext error behavior")
365 } else {
366 require.Error(t, gotErr, "RunGH should match RunGHContext error behavior")
367 assert.Equal(t, wantErr.Error(), gotErr.Error(), "RunGH should return the same error text as RunGHContext")
368 }
369 })
370
371 t.Run("RunGHCombined matches RunGHCombinedContext", func(t *testing.T) {
372 gotOut, gotErr := RunGHCombined("Test spinner...", "auth", "status")
373 wantOut, wantErr := RunGHCombinedContext(context.Background(), "Test spinner...", "auth", "status")
374
375 assert.Equal(t, wantOut, gotOut, "RunGHCombined should return the same output as RunGHCombinedContext")
376 if wantErr == nil {
377 assert.NoError(t, gotErr, "RunGHCombined should match RunGHCombinedContext error behavior")
378 } else {
379 require.Error(t, gotErr, "RunGHCombined should match RunGHCombinedContext error behavior")
380 assert.Equal(t, wantErr.Error(), gotErr.Error(), "RunGHCombined should return the same error text as RunGHCombinedContext")
381 }
382 })
383}
384
385// TestEnrichGHError tests that enrichGHError appends stderr from *exec.ExitError
386func TestEnrichGHError(t *testing.T) {

Callers

nothing calls this directly

Calls 9

RunGHCombinedContextFunction · 0.85
GetenvMethod · 0.80
SetenvMethod · 0.80
BackgroundMethod · 0.80
RunGHFunction · 0.70
RunGHContextFunction · 0.70
RunGHCombinedFunction · 0.70
RunMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected