MCPcopy Create free account
hub / github.com/cli/cli / sharedSetup

Function sharedSetup

acceptance/acceptance_test.go:274–312  ·  view source on GitHub ↗
(tsEnv testScriptEnv)

Source from the content-addressed store, hash-verified

272var keyT struct{}
273
274func 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.
315func sharedCmds(tsEnv testScriptEnv) map[string]func(ts *testscript.TestScript, neg bool, args []string) {

Callers 1

testScriptParamsForFunction · 0.85

Calls 4

extractScriptNameFunction · 0.85
randomStringFunction · 0.85
JoinMethod · 0.80
ErrorfMethod · 0.65

Tested by

no test coverage detected