(tsEnv testScriptEnv)
| 272 | var keyT struct{} |
| 273 | |
| 274 | func sharedSetup(tsEnv testScriptEnv) func(ts *testscript.Env) error { |
| 275 | return func(ts *testscript.Env) error { |
| 276 | scriptName, ok := extractScriptName(ts.Vars) |
| 277 | if !ok { |
| 278 | ts.T().Fatal("script name not found") |
| 279 | } |
| 280 | |
| 281 | // When using script name to uniquely identify where test data comes from, |
| 282 | // some places like GitHub Actions secret names don't accept hyphens. |
| 283 | // Replace them with underscores until such a time this becomes a problem. |
| 284 | ts.Setenv("SCRIPT_NAME", strings.ReplaceAll(scriptName, "-", "_")) |
| 285 | ts.Setenv("HOME", ts.Cd) |
| 286 | ts.Setenv("GH_CONFIG_DIR", ts.Cd) |
| 287 | |
| 288 | ts.Setenv("GH_HOST", tsEnv.host) |
| 289 | ts.Setenv("ORG", tsEnv.org) |
| 290 | ts.Setenv("GH_TOKEN", tsEnv.token) |
| 291 | |
| 292 | ts.Setenv("RANDOM_STRING", randomString(10)) |
| 293 | |
| 294 | ts.Setenv("GH_TELEMETRY", "false") |
| 295 | |
| 296 | // The sandbox overrides HOME, so git cannot find the user's global |
| 297 | // config. Write a minimal identity so commits inside the sandbox |
| 298 | // don't fail with "Author identity unknown". |
| 299 | gitCfg := filepath.Join(ts.Cd, ".gitconfig") |
| 300 | gitCfgContent := heredoc.Doc(` |
| 301 | [user] |
| 302 | name = GitHub CLI Acceptance Test Runner |
| 303 | email = cli-acceptance-test-runner@github.com |
| 304 | `) |
| 305 | if err := os.WriteFile(gitCfg, []byte(gitCfgContent), 0o644); err != nil { |
| 306 | return fmt.Errorf("writing sandbox .gitconfig: %w", err) |
| 307 | } |
| 308 | |
| 309 | ts.Values[keyT] = ts.T() |
| 310 | return nil |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | // sharedCmds defines a collection of custom testscript commands for our use. |
| 315 | func sharedCmds(tsEnv testScriptEnv) map[string]func(ts *testscript.TestScript, neg bool, args []string) { |
no test coverage detected