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"));
}
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);
}
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.");
}
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();
}
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)))));
}
Aggregations