Search in sources :

Example 1 with InMemoryStreamConsumer

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<>());
}
Also used : ConsoleResult(com.thoughtworks.go.util.command.ConsoleResult) InMemoryStreamConsumer(com.thoughtworks.go.util.command.InMemoryStreamConsumer) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext)

Example 2 with InMemoryStreamConsumer

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));
}
Also used : InMemoryStreamConsumer(com.thoughtworks.go.util.command.InMemoryStreamConsumer) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Test(org.junit.Test)

Example 3 with InMemoryStreamConsumer

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));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Modification(com.thoughtworks.go.domain.materials.Modification) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) RevisionContext(com.thoughtworks.go.domain.materials.RevisionContext) StringRevision(com.thoughtworks.go.domain.materials.mercurial.StringRevision) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) InMemoryStreamConsumer(com.thoughtworks.go.util.command.InMemoryStreamConsumer) Test(org.junit.Test)

Example 4 with InMemoryStreamConsumer

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);
}
Also used : InMemoryStreamConsumer(com.thoughtworks.go.util.command.InMemoryStreamConsumer) ModifiedFile(com.thoughtworks.go.domain.materials.ModifiedFile) File(java.io.File) Test(org.junit.Test)

Example 5 with InMemoryStreamConsumer

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));
}
Also used : GitSubmoduleRepos(com.thoughtworks.go.helper.GitSubmoduleRepos) StringRevision(com.thoughtworks.go.domain.materials.mercurial.StringRevision) StringContains.containsString(org.hamcrest.core.StringContains.containsString) InMemoryStreamConsumer(com.thoughtworks.go.util.command.InMemoryStreamConsumer) ModifiedFile(com.thoughtworks.go.domain.materials.ModifiedFile) File(java.io.File) Test(org.junit.Test)

Aggregations

InMemoryStreamConsumer (com.thoughtworks.go.util.command.InMemoryStreamConsumer)31 Test (org.junit.Test)17 GitSubmoduleRepos (com.thoughtworks.go.helper.GitSubmoduleRepos)8 StringRevision (com.thoughtworks.go.domain.materials.mercurial.StringRevision)7 File (java.io.File)7 StringContains.containsString (org.hamcrest.core.StringContains.containsString)7 Test (org.junit.jupiter.api.Test)5 ModifiedFile (com.thoughtworks.go.domain.materials.ModifiedFile)4 CommandLine (com.thoughtworks.go.util.command.CommandLine)4 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)3 Modification (com.thoughtworks.go.domain.materials.Modification)3 RevisionContext (com.thoughtworks.go.domain.materials.RevisionContext)3 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)2 GitTestRepo (com.thoughtworks.go.domain.materials.git.GitTestRepo)2 P4Client (com.thoughtworks.go.domain.materials.perforce.P4Client)2 IOException (java.io.IOException)2 SubprocessExecutionContext (com.thoughtworks.go.config.materials.SubprocessExecutionContext)1 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)1 DependencyMaterialRevision (com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision)1 PluggableSCMMaterialAgent (com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialAgent)1