()
| 104 | } |
| 105 | |
| 106 | func (execT *execTestCmdFlags) executeCommand() (string, testResult) { |
| 107 | // build up the command args and flags value |
| 108 | var args []string |
| 109 | if execT.noParent { |
| 110 | args = []string{execT.cmd.Name()} |
| 111 | } else { |
| 112 | args = []string{execT.cmd.Parent().Name(), execT.cmd.Name()} |
| 113 | } |
| 114 | if len(execT.args) > 0 { |
| 115 | args = append(args, execT.args...) |
| 116 | } |
| 117 | for k, v := range execT.flagsMap { |
| 118 | arg := fmt.Sprintf("--%s=%s", k, v) |
| 119 | args = append(args, arg) |
| 120 | } |
| 121 | |
| 122 | // NOTE: program exits with error should be captured here |
| 123 | stdout, err := executeCommand(rootCmd, args...) |
| 124 | if err != nil { |
| 125 | // any errors from the executeCommand should go here |
| 126 | // and not exit the program with error! |
| 127 | return err.Error(), fail |
| 128 | } |
| 129 | |
| 130 | // flags must be set back to their default value |
| 131 | if err := resetFlagsFromMap(execT.cmd, execT.flagsMap); err != nil { |
| 132 | return err.Error(), fail |
| 133 | } |
| 134 | tInfo(string(pass)) |
| 135 | return stdout, pass |
| 136 | } |
| 137 | |
| 138 | // A helper to ignore os.Exit(1) errors when running a cobra Command |
| 139 | func executeCommand(root *cobra.Command, |
no test coverage detected