use of com.thoughtworks.go.util.command.InMemoryStreamConsumer in project gocd by gocd.
the class ProcessWrapperTest method run.
private ConsoleResult run(CommandLine line, String... inputs) {
InMemoryStreamConsumer outputStreamConsumer = inMemoryConsumer();
EnvironmentVariableContext environmentVariableContext = new EnvironmentVariableContext();
environmentVariableContext.setProperty("GO_DEPENDENCY_LABEL_PIPELINE_NAME", "999", false);
line.addInput(inputs);
ProcessWrapper processWrapper = line.execute(outputStreamConsumer, environmentVariableContext, null);
return new ConsoleResult(processWrapper.waitForExit(), outputStreamConsumer.getStdLines(), outputStreamConsumer.getErrLines(), line.getArguments(), new ArrayList<>());
}
use of com.thoughtworks.go.util.command.InMemoryStreamConsumer in project gocd by gocd.
the class GitMaterialTest method shouldUpdateToSpecificRevision.
@Test
public void shouldUpdateToSpecificRevision() throws Exception {
File newFile = new File(workingDir, "second.txt");
assertThat(outputStreamConsumer.getStdError(), is(""));
InMemoryStreamConsumer output = inMemoryConsumer();
git.updateTo(output, workingDir, new RevisionContext(GitTestRepo.REVISION_1, GitTestRepo.REVISION_0, 2), new TestSubprocessExecutionContext());
assertThat(output.getStdOut(), containsString("Start updating files at revision " + GitTestRepo.REVISION_1.getRevision()));
assertThat(newFile.exists(), is(false));
output = inMemoryConsumer();
git.updateTo(output, workingDir, new RevisionContext(GitTestRepo.REVISION_2, GitTestRepo.REVISION_1, 2), new TestSubprocessExecutionContext());
assertThat(output.getStdOut(), containsString("Start updating files at revision " + GitTestRepo.REVISION_2.getRevision()));
assertThat(newFile.exists(), is(true));
}
use of com.thoughtworks.go.util.command.InMemoryStreamConsumer in project gocd by gocd.
the class BackupServiceIntegrationTest method shouldBackupConfigRepository.
@Test
public void shouldBackupConfigRepository() throws IOException {
configHelper.addPipeline("too-unique-to-be-present", "stage-name");
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
backupService.startBackup(admin, result);
assertThat(result.isSuccessful(), is(true));
assertThat(result.message(localizer), is("Backup completed successfully."));
File repoZip = backedUpFile("config-repo.zip");
File repoDir = temporaryFolder.newFolder("expanded-config-repo-backup");
TestUtils.extractZipToDir(repoZip, repoDir);
File cloneDir = temporaryFolder.newFolder("cloned-config-repo-backup");
GitMaterial git = new GitMaterial(repoDir.getAbsolutePath());
List<Modification> modifications = git.latestModification(cloneDir, subprocessExecutionContext);
String latestChangeRev = modifications.get(0).getRevision();
git.checkout(cloneDir, new StringRevision(latestChangeRev), subprocessExecutionContext);
assertThat(FileUtils.readFileToString(new File(cloneDir, "cruise-config.xml"), UTF_8).indexOf("too-unique-to-be-present"), greaterThan(0));
StringRevision revision = new StringRevision(latestChangeRev + "~1");
git.updateTo(new InMemoryStreamConsumer(), cloneDir, new RevisionContext(revision), subprocessExecutionContext);
assertThat(FileUtils.readFileToString(new File(cloneDir, "cruise-config.xml"), UTF_8).indexOf("too-unique-to-be-present"), is(-1));
}
use of com.thoughtworks.go.util.command.InMemoryStreamConsumer in project gocd by gocd.
the class GitCommandTest method freshCloneOnAgentSideShouldHaveWorkingCopyCheckedOut.
@Test
public void freshCloneOnAgentSideShouldHaveWorkingCopyCheckedOut() throws IOException {
InMemoryStreamConsumer output = inMemoryConsumer();
File workingDir = createTempWorkingDirectory();
GitCommand git = new GitCommand(null, workingDir, GitMaterialConfig.DEFAULT_BRANCH, false, new HashMap<>(), null);
git.clone(output, repoUrl);
assertWorkingCopyCheckedOut(workingDir);
}
use of com.thoughtworks.go.util.command.InMemoryStreamConsumer in project gocd by gocd.
the class GitCommandTest method shouldCleanUnversionedFilesInsideSubmodulesBeforeUpdating.
@Test
public void shouldCleanUnversionedFilesInsideSubmodulesBeforeUpdating() throws Exception {
GitSubmoduleRepos submoduleRepos = new GitSubmoduleRepos(temporaryFolder);
String submoduleDirectoryName = "local-submodule";
submoduleRepos.addSubmodule(SUBMODULE, submoduleDirectoryName);
File cloneDirectory = createTempWorkingDirectory();
GitCommand clonedCopy = new GitCommand(null, cloneDirectory, GitMaterialConfig.DEFAULT_BRANCH, false, new HashMap<>(), null);
InMemoryStreamConsumer outputStreamConsumer = inMemoryConsumer();
// Clone repository without submodules
clonedCopy.clone(outputStreamConsumer, submoduleRepos.mainRepo().getUrl());
// Pull submodules to working copy - Pipeline counter 1
clonedCopy.resetWorkingDir(outputStreamConsumer, new StringRevision("HEAD"));
File unversionedFile = new File(new File(cloneDirectory, submoduleDirectoryName), "unversioned_file.txt");
FileUtils.writeStringToFile(unversionedFile, "this is an unversioned file. lets see you deleting me.. come on.. I dare you!!!!", UTF_8);
// Should clean unversioned file on next fetch - Pipeline counter 2
clonedCopy.resetWorkingDir(outputStreamConsumer, new StringRevision("HEAD"));
assertThat(unversionedFile.exists(), is(false));
}
Aggregations