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

Function TestEnsureGHESRepoConfig_NoDetection

pkg/cli/init_test.go:380–412  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

378}
379
380func TestEnsureGHESRepoConfig_NoDetection(t *testing.T) {
381 // Without GH_HOST or GITHUB_SERVER_URL pointing to GHES, and without a git remote,
382 // ensureGHESRepoConfig should do nothing (detection fails gracefully).
383 tempDir := t.TempDir()
384 oldWd, err := os.Getwd()
385 if err != nil {
386 t.Fatalf("Failed to get cwd: %v", err)
387 }
388 defer func() { _ = os.Chdir(oldWd) }()
389 if err := os.Chdir(tempDir); err != nil {
390 t.Fatalf("Failed to chdir: %v", err)
391 }
392
393 // Set up a git repo with a github.com remote (not GHES)
394 cmd := exec.Command("git", "init")
395 cmd.Dir = tempDir
396 _ = cmd.Run()
397 cmd = exec.Command("git", "remote", "add", "origin", "https://github.com/owner/repo.git")
398 cmd.Dir = tempDir
399 _ = cmd.Run()
400
401 // Unset any env vars that might signal GHES
402 t.Setenv("GH_HOST", "")
403 t.Setenv("GITHUB_SERVER_URL", "")
404
405 updated, err := ensureGHESRepoConfig(false)
406 if err != nil {
407 t.Fatalf("ensureGHESRepoConfig returned unexpected error: %v", err)
408 }
409 if updated {
410 t.Error("ensureGHESRepoConfig should not update aw.json when not on GHES")
411 }
412}
413
414func TestEnsureGHESRepoConfig_GHHostEnvVar(t *testing.T) {
415 // When GH_HOST points to a GHES host, ensureGHESRepoConfig should write aw.json.

Callers

nothing calls this directly

Calls 4

ensureGHESRepoConfigFunction · 0.85
SetenvMethod · 0.80
RunMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected