Search in sources :

Example 11 with InMemoryStreamConsumer

use of com.thoughtworks.go.util.command.InMemoryStreamConsumer in project gocd by gocd.

the class GitCommandTest method shouldRetrieveListOfSubmoduleFolders.

@Test
public void shouldRetrieveListOfSubmoduleFolders() throws Exception {
    GitSubmoduleRepos submoduleRepos = new GitSubmoduleRepos(temporaryFolder);
    submoduleRepos.addSubmodule(SUBMODULE, "sub1");
    GitCommand gitWithSubmodule = new GitCommand(null, createTempWorkingDirectory(), GitMaterialConfig.DEFAULT_BRANCH, false, new HashMap<>(), null);
    InMemoryStreamConsumer outputStreamConsumer = inMemoryConsumer();
    gitWithSubmodule.clone(outputStreamConsumer, submoduleRepos.mainRepo().getUrl());
    gitWithSubmodule.fetchAndResetToHead(outputStreamConsumer);
    gitWithSubmodule.updateSubmoduleWithInit(outputStreamConsumer);
    List<String> folders = gitWithSubmodule.submoduleFolders();
    assertThat(folders.size(), is(1));
    assertThat(folders.get(0), is("sub1"));
}
Also used : GitSubmoduleRepos(com.thoughtworks.go.helper.GitSubmoduleRepos) InMemoryStreamConsumer(com.thoughtworks.go.util.command.InMemoryStreamConsumer) StringContains.containsString(org.hamcrest.core.StringContains.containsString) Test(org.junit.Test)

Example 12 with InMemoryStreamConsumer

use of com.thoughtworks.go.util.command.InMemoryStreamConsumer in project gocd by gocd.

the class BackupServiceIntegrationTest method shouldBackupConfigRepository.

@Test
public void shouldBackupConfigRepository(@TempDir Path temporaryFolder) throws IOException {
    configHelper.addPipeline("too-unique-to-be-present", "stage-name");
    ServerBackup backup = backupService.startBackup(admin);
    assertThat(backup.isSuccessful(), is(true));
    assertThat(backup.getMessage(), is("Backup was generated successfully."));
    File repoZip = backedUpFile("config-repo.zip");
    File repoDir = TempDirUtils.createTempDirectoryIn(temporaryFolder, "expanded-config-repo-backup").toFile();
    new ZipUtil().unzip(repoZip, repoDir);
    File cloneDir = TempDirUtils.createTempDirectoryIn(temporaryFolder, "cloned-config-repo-backup").toFile();
    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));
    // Workaround issue with deletion of symlinks via JUnit TempDir by pre-deleting
    FileUtils.deleteQuietly(cloneDir);
}
Also used : ServerBackup(com.thoughtworks.go.server.domain.ServerBackup) 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) Hex.encodeHexString(org.apache.commons.codec.binary.Hex.encodeHexString) InMemoryStreamConsumer(com.thoughtworks.go.util.command.InMemoryStreamConsumer) Test(org.junit.jupiter.api.Test)

Example 13 with InMemoryStreamConsumer

use of com.thoughtworks.go.util.command.InMemoryStreamConsumer in project gocd by gocd.

the class P4CommandTestBase method shouldInitializeClient.

@Test
void shouldInitializeClient() {
    InMemoryStreamConsumer output = inMemoryConsumer();
    p4.client(clientConfig("new_p4_client", clientFolder), output, true);
    assertThat(output.getStdOut()).contains("Client new_p4_client saved.");
    p4.client(clientConfig("new_p4_client", clientFolder), output, true);
    assertThat(output.getStdOut()).contains("Client new_p4_client not changed.");
}
Also used : InMemoryStreamConsumer(com.thoughtworks.go.util.command.InMemoryStreamConsumer) Test(org.junit.jupiter.api.Test)

Example 14 with InMemoryStreamConsumer

use of com.thoughtworks.go.util.command.InMemoryStreamConsumer in project gocd by gocd.

the class P4CommandTestBase method shouldCreateClientSpecWithProvidedValues.

@Test
void shouldCreateClientSpecWithProvidedValues() {
    InMemoryStreamConsumer output = inMemoryConsumer();
    p4.execute(p4.p4("client", "-o"), null, output, true);
    String actualClientSpec = output.getStdOut();
    assertThat(actualClientSpec.contains("Client:\tp4test_1")).isTrue();
    assertThat(actualClientSpec.contains("Options:\tnoallwrite clobber nocompress unlocked nomodtime rmdir")).isTrue();
    assertThat(actualClientSpec.contains("View:\n\t//depot/... //p4test_1/...")).isTrue();
    assertThat(actualClientSpec.contains("LineEnd:\tlocal")).isTrue();
}
Also used : InMemoryStreamConsumer(com.thoughtworks.go.util.command.InMemoryStreamConsumer) Test(org.junit.jupiter.api.Test)

Example 15 with InMemoryStreamConsumer

use of com.thoughtworks.go.util.command.InMemoryStreamConsumer in project gocd by gocd.

the class MaterialAgentFactoryTest method shouldCreateMaterialAgent_withAgentsUuidAsSubprocessExecutionContextNamespace.

@Test
public void shouldCreateMaterialAgent_withAgentsUuidAsSubprocessExecutionContextNamespace() throws IOException {
    String agentUuid = "uuid-01783738";
    MaterialAgentFactory factory = new MaterialAgentFactory(new InMemoryStreamConsumer(), tempWorkingDirectory, new AgentIdentifier("host", "1.1.1.1", agentUuid), scmExtension);
    GitMaterial gitMaterial = new GitMaterial("http://foo", "master", "dest_folder");
    MaterialAgent agent = factory.createAgent(new MaterialRevision(gitMaterial));
    assertThat(agent, is(instanceOf(AbstractMaterialAgent.class)));
    SubprocessExecutionContext execCtx = (SubprocessExecutionContext) ReflectionUtil.getField(agent, "execCtx");
    assertThat(execCtx.getProcessNamespace("fingerprint"), is(CachedDigestUtils.sha256Hex(String.format("%s%s%s", "fingerprint", agentUuid, gitMaterial.workingdir(tempWorkingDirectory)))));
}
Also used : GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) SubprocessExecutionContext(com.thoughtworks.go.config.materials.SubprocessExecutionContext) AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) PluggableSCMMaterialAgent(com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialAgent) InMemoryStreamConsumer(com.thoughtworks.go.util.command.InMemoryStreamConsumer) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) Test(org.junit.jupiter.api.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