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

Function sharedCmds

acceptance/acceptance_test.go:931–1222  ·  view source on GitHub ↗

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

(tsEnv testScriptEnv, fixtureRepositories *fixtureRepositoryManager)

Source from the content-addressed store, hash-verified

929
930// sharedCmds defines a collection of custom testscript commands for our use.
931func sharedCmds(tsEnv testScriptEnv, fixtureRepositories *fixtureRepositoryManager) map[string]func(ts *testscript.TestScript, neg bool, args []string) {
932 return map[string]func(ts *testscript.TestScript, neg bool, args []string){
933 "defer": func(ts *testscript.TestScript, neg bool, args []string) {
934 if neg {
935 ts.Fatalf("unsupported: ! defer")
936 }
937
938 if tsEnv.skipDefer {
939 return
940 }
941
942 tt, ok := ts.Value(keyT).(testscript.T)
943 if !ok {
944 ts.Fatalf("%v is not a testscript.T", ts.Value(keyT))
945 }
946
947 ts.Defer(func() {
948 if args[0] == "cleanup-repo" {
949 if len(args) != 2 {
950 tt.Fatal("usage: defer cleanup-repo REPO")
951 return
952 }
953 if err := fixtureRepositories.delete(args[1]); err != nil {
954 tt.Fatal(err)
955 }
956 return
957 }
958
959 // If you're wondering why we're not using ts.Check here, it's because it raises a panic, and testscript
960 // only catches the panics directly from commands, not from the deferred functions. So what we do
961 // instead is grab the `t` in the setup function and store it as a value. It's important that we use
962 // `t` from the setup function because it represents the subtest created for each individual script,
963 // rather than each top-level test.
964 // See: https://github.com/rogpeppe/go-internal/issues/276
965 if err := ts.Exec(args[0], args[1:]...); err != nil {
966 tt.FailNow()
967 }
968 })
969 },
970 "env2upper": func(ts *testscript.TestScript, neg bool, args []string) {
971 if neg {
972 ts.Fatalf("unsupported: ! env2upper")
973 }
974 if len(args) == 0 {
975 ts.Fatalf("usage: env2upper name=value ...")
976 }
977 for _, env := range args {
978 i := strings.Index(env, "=")
979
980 if i < 0 {
981 ts.Fatalf("env2upper: argument does not match name=value")
982 }
983
984 ts.Setenv(env[:i], strings.ToUpper(env[i+1:]))
985 }
986 },
987 "fixture-repo": func(ts *testscript.TestScript, neg bool, args []string) {
988 if neg {

Calls 15

generateSSHPublicKeyFunction · 0.85
sandboxFilePathFunction · 0.85
outputForEnvironmentFunction · 0.85
resolveWorkflowRunIDFunction · 0.85
waitForWorkflowFunction · 0.85
waitForRepositoryReadyFunction · 0.85
waitForWorkflowRunStatusFunction · 0.85
ValueMethod · 0.80
repositoryMethod · 0.80
CheckMethod · 0.80
LogfMethod · 0.80

Tested by

no test coverage detected