func TestParserOnRealTests(t *testing.T) { // there are some issues with gccgo: testutil.SkipTestUnlessAll(t, "TestParserOnRealTests") var parser Parser Convey("With a parser", t, func() { parser = &VanillaParser{} Convey("and some real test output", func() { cmd := exec.Command("go", "test", "-v", "./.") stdout, err := cmd.StdoutPipe() testutil.HandleTestingErr(err, t, "error getting stdout pipe %v") testutil.HandleTestingErr(cmd.Start(), t, "couldn't run tests %v") err = parser.Parse(stdout) testutil.HandleTestingErr(cmd.Wait(), t, "error waiting on test %v") Convey("the parser should run successfully", func() { So(err, ShouldBeNil) Convey("and all results should line up with the logs", func() { for _, result := range parser.Results() { matchResultWithLog(result, parser.Logs()) } }) }) }) }) }
func TestScpCommand(t *testing.T) { testutil.SkipTestUnlessAll(t, "TestScpCommand") Convey("With files to scp", t, func() { // the local files and target directory for scping evgHome := evergreen.FindEvergreenHome() tmpBase := filepath.Join(evgHome, "command/testdata/tmp") fileToScp := filepath.Join(tmpBase, "copy_me_please.txt") directoryToScp := filepath.Join(tmpBase, "copy_my_children_please") nestedFileToScp := filepath.Join(directoryToScp, "copy_me_too_please.txt") targetDirectory := filepath.Join(tmpBase, "feed_me_files") // remove the files and directories, if they exist (start clean) exists, err := util.FileExists(tmpBase) So(err, ShouldBeNil) if exists { So(os.RemoveAll(tmpBase), ShouldBeNil) } So(os.MkdirAll(tmpBase, 0777), ShouldBeNil) // prevent permissions issues syscall.Umask(0000) // create the files / directories to be used So(ioutil.WriteFile(fileToScp, []byte("hello"), 0777), ShouldBeNil) So(os.Mkdir(directoryToScp, 0777), ShouldBeNil) So(ioutil.WriteFile(nestedFileToScp, []byte("hi"), 0777), ShouldBeNil) So(os.Mkdir(targetDirectory, 0777), ShouldBeNil) Convey("when running scp commands", func() { Convey("copying files should work in both directions (local to"+ " remote and remote to local)", func() { // scp the file from local to remote scpCommand := &ScpCommand{ Source: fileToScp, Dest: targetDirectory, Stdout: ioutil.Discard, Stderr: ioutil.Discard, RemoteHostName: TestRemote, User: TestRemoteUser, Options: []string{"-i", TestRemoteKey}, SourceIsRemote: false, } So(scpCommand.Run(), ShouldBeNil) // make sure the file was scp-ed over newFileContents, err := ioutil.ReadFile( filepath.Join(targetDirectory, "copy_me_please.txt")) So(err, ShouldBeNil) So(newFileContents, ShouldResemble, []byte("hello")) // remove the file So(os.Remove(filepath.Join(targetDirectory, "copy_me_please.txt")), ShouldBeNil) // scp the file from remote to local scpCommand = &ScpCommand{ Source: fileToScp, Dest: targetDirectory, Stdout: ioutil.Discard, Stderr: ioutil.Discard, RemoteHostName: TestRemote, User: TestRemoteUser, Options: []string{"-i", TestRemoteKey}, SourceIsRemote: true, } So(scpCommand.Run(), ShouldBeNil) // make sure the file was scp-ed over newFileContents, err = ioutil.ReadFile( filepath.Join(targetDirectory, "copy_me_please.txt")) So(err, ShouldBeNil) So(newFileContents, ShouldResemble, []byte("hello")) }) Convey("additional scp options should be passed correctly to the"+ " command", func() { // scp recursively, using the -r flag scpCommand := &ScpCommand{ Source: directoryToScp, Dest: targetDirectory, Stdout: ioutil.Discard, Stderr: ioutil.Discard, RemoteHostName: TestRemote, User: TestRemoteUser, Options: []string{"-i", TestRemoteKey, "-r"}, SourceIsRemote: false, } So(scpCommand.Run(), ShouldBeNil) // make sure the entire directory was scp-ed over nestedFileContents, err := ioutil.ReadFile( filepath.Join(targetDirectory, "copy_my_children_please", "copy_me_too_please.txt")) So(err, ShouldBeNil) So(nestedFileContents, ShouldResemble, []byte("hi")) }) }) }) }
func TestRemoteCommand(t *testing.T) { testutil.SkipTestUnlessAll(t, "TestRemoteCommand") Convey("With a remote command", t, func() { Convey("failure and success should be detected", func() { failCmd := &RemoteCommand{ CmdString: "false", Stdout: ioutil.Discard, Stderr: ioutil.Discard, RemoteHostName: TestRemote, User: TestRemoteUser, Options: []string{"-i", TestRemoteKey}, } So(failCmd.Run(), ShouldNotBeNil) trueCmd := &RemoteCommand{ CmdString: "true", Stdout: ioutil.Discard, Stderr: ioutil.Discard, RemoteHostName: TestRemote, User: TestRemoteUser, Options: []string{"-i", TestRemoteKey}, } So(trueCmd.Run(), ShouldBeNil) }) Convey("output should be passed appropriately to the stdout and stderr"+ " writers", func() { stdout := &CacheLastWritten{} stderr := &CacheLastWritten{} command := &RemoteCommand{ CmdString: "echo 'hi stdout'; echo 'hi stderr'>&2", Stdout: stdout, Stderr: stderr, RemoteHostName: TestRemote, User: TestRemoteUser, Options: []string{"-i", TestRemoteKey}, } // run the command, make sure the output was given to stdout So(command.Run(), ShouldBeNil) So(stdout.LastWritten, ShouldResemble, []byte("hi stdout\n")) So(stderr.LastWritten, ShouldResemble, []byte("hi stderr\n")) }) Convey("if the background option is set to true, the ssh connection"+ " should not wait for the command to finish", func() { // this command would sleep for 30 years if it were waited for sleepCmd := "sleep 1000000000" command := &RemoteCommand{ CmdString: sleepCmd, Stdout: ioutil.Discard, Stderr: ioutil.Discard, RemoteHostName: TestRemote, User: TestRemoteUser, Options: []string{"-i", TestRemoteKey}, Background: true, } // run the command, it should finish rather than sleeping forever So(command.Run(), ShouldBeNil) // clean up the sleeping process cleanupCmd := &RemoteCommand{ CmdString: fmt.Sprintf("pkill -xf '%v'", sleepCmd), Stdout: ioutil.Discard, Stderr: ioutil.Discard, RemoteHostName: TestRemote, User: TestRemoteUser, Options: []string{"-i", TestRemoteKey}, } So(cleanupCmd.Run(), ShouldBeNil) }) }) }