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

Function sharedCmds

acceptance/acceptance_test.go:315–494  ·  view source on GitHub ↗

sharedCmds defines a collection of custom testscript commands for our use.

(tsEnv testScriptEnv)

Source from the content-addressed store, hash-verified

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) {
316 return map[string]func(ts *testscript.TestScript, neg bool, args []string){
317 "defer": func(ts *testscript.TestScript, neg bool, args []string) {
318 if neg {
319 ts.Fatalf("unsupported: ! defer")
320 }
321
322 if tsEnv.skipDefer {
323 return
324 }
325
326 tt, ok := ts.Value(keyT).(testscript.T)
327 if !ok {
328 ts.Fatalf("%v is not a testscript.T", ts.Value(keyT))
329 }
330
331 ts.Defer(func() {
332 // If you're wondering why we're not using ts.Check here, it's because it raises a panic, and testscript
333 // only catches the panics directly from commands, not from the deferred functions. So what we do
334 // instead is grab the `t` in the setup function and store it as a value. It's important that we use
335 // `t` from the setup function because it represents the subtest created for each individual script,
336 // rather than each top-level test.
337 // See: https://github.com/rogpeppe/go-internal/issues/276
338 if err := ts.Exec(args[0], args[1:]...); err != nil {
339 tt.FailNow()
340 }
341 })
342 },
343 "env2upper": func(ts *testscript.TestScript, neg bool, args []string) {
344 if neg {
345 ts.Fatalf("unsupported: ! env2upper")
346 }
347 if len(args) == 0 {
348 ts.Fatalf("usage: env2upper name=value ...")
349 }
350 for _, env := range args {
351 i := strings.Index(env, "=")
352
353 if i < 0 {
354 ts.Fatalf("env2upper: argument does not match name=value")
355 }
356
357 ts.Setenv(env[:i], strings.ToUpper(env[i+1:]))
358 }
359 },
360 "generate-ssh-key": func(ts *testscript.TestScript, neg bool, args []string) {
361 if neg {
362 ts.Fatalf("unsupported: ! generate-ssh-key")
363 }
364 if len(args) < 1 || len(args) > 2 {
365 ts.Fatalf("usage: generate-ssh-key file [comment]")
366 }
367
368 comment := ""
369 if len(args) == 2 {
370 comment = args[1]
371 }
372 publicKey, err := generateSSHPublicKey(comment)

Callers 1

testScriptParamsForFunction · 0.85

Calls 6

generateSSHPublicKeyFunction · 0.85
sandboxFilePathFunction · 0.85
ValueMethod · 0.80
CheckMethod · 0.80
DurationMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected