Execute will execute the given test on the current node
(test TestCase)
| 22 | |
| 23 | // Execute will execute the given test on the current node |
| 24 | func (e LocalExecutor) Execute(test TestCase) TestResult { |
| 25 | timeoutOpt, err := createTimeoutOption(test.Command.Timeout) |
| 26 | if err != nil { |
| 27 | test.Result = CommandResult{Error: err} |
| 28 | return TestResult{ |
| 29 | TestCase: test, |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | envOpt := createEnvVarsOption(test) |
| 34 | |
| 35 | // cut = command under test |
| 36 | cut := cmd.NewCommand( |
| 37 | test.Command.Cmd, |
| 38 | cmd.WithWorkingDir(test.Command.Dir), |
| 39 | timeoutOpt, |
| 40 | envOpt) |
| 41 | |
| 42 | if err := cut.Execute(); err != nil { |
| 43 | log.Println(test.Title, " failed ", err.Error()) |
| 44 | test.Result = CommandResult{ |
| 45 | Error: err, |
| 46 | } |
| 47 | |
| 48 | return TestResult{ |
| 49 | TestCase: test, |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | log.Println("title: '"+test.Title+"'", " Command: ", test.Command.Cmd) |
| 54 | log.Println("title: '"+test.Title+"'", " Directory: ", cut.Dir) |
| 55 | log.Println("title: '"+test.Title+"'", " Env: ", cut.Env) |
| 56 | |
| 57 | // Write test result |
| 58 | test.Result = CommandResult{ |
| 59 | ExitCode: cut.ExitCode(), |
| 60 | Stdout: strings.TrimSpace(strings.Replace(cut.Stdout(), "\r\n", "\n", -1)), |
| 61 | Stderr: strings.TrimSpace(strings.Replace(cut.Stderr(), "\r\n", "\n", -1)), |
| 62 | } |
| 63 | |
| 64 | log.Println("title: '"+test.Title+"'", " ExitCode: ", test.Result.ExitCode) |
| 65 | log.Println("title: '"+test.Title+"'", " Stdout: ", test.Result.Stdout) |
| 66 | log.Println("title: '"+test.Title+"'", " Stderr: ", test.Result.Stderr) |
| 67 | |
| 68 | return Validate(test) |
| 69 | } |
| 70 | |
| 71 | func createEnvVarsOption(test TestCase) func(c *cmd.Command) { |
| 72 | return func(c *cmd.Command) { |