MCPcopy
hub / github.com/cli/cli / sharedSetup

Function sharedSetup

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

Source from the content-addressed store, hash-verified

237var keyT struct{}
238
239func sharedSetup(tsEnv testScriptEnv) func(ts *testscript.Env) error {
240 return func(ts *testscript.Env) error {
241 scriptName, ok := extractScriptName(ts.Vars)
242 if !ok {
243 ts.T().Fatal("script name not found")
244 }
245
246 // When using script name to uniquely identify where test data comes from,
247 // some places like GitHub Actions secret names don't accept hyphens.
248 // Replace them with underscores until such a time this becomes a problem.
249 ts.Setenv("SCRIPT_NAME", strings.ReplaceAll(scriptName, "-", "_"))
250 ts.Setenv("HOME", ts.Cd)
251 ts.Setenv("GH_CONFIG_DIR", ts.Cd)
252
253 ts.Setenv("GH_HOST", tsEnv.host)
254 ts.Setenv("ORG", tsEnv.org)
255 ts.Setenv("GH_TOKEN", tsEnv.token)
256
257 ts.Setenv("RANDOM_STRING", randomString(10))
258
259 ts.Setenv("GH_TELEMETRY", "false")
260
261 // The sandbox overrides HOME, so git cannot find the user's global
262 // config. Write a minimal identity so commits inside the sandbox
263 // don't fail with "Author identity unknown".
264 gitCfg := filepath.Join(ts.Cd, ".gitconfig")
265 gitCfgContent := heredoc.Doc(`
266 [user]
267 name = GitHub CLI Acceptance Test Runner
268 email = cli-acceptance-test-runner@github.com
269 `)
270 if err := os.WriteFile(gitCfg, []byte(gitCfgContent), 0o644); err != nil {
271 return fmt.Errorf("writing sandbox .gitconfig: %w", err)
272 }
273
274 ts.Values[keyT] = ts.T()
275 return nil
276 }
277}
278
279// sharedCmds defines a collection of custom testscript commands for our use.
280func 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