@Test public void shouldCleanWorkingDir() throws Exception { P4Material material = p4Fixture.material(VIEW); updateTo(material, new RevisionContext(REVISION_2), JobResult.Passed); File tmpFile = new File(workingDir, "shouldBeDeleted"); FileUtils.writeStringToFile(tmpFile, "testing", UTF_8); assert(tmpFile.exists()); updateTo(material, new RevisionContext(REVISION_2), JobResult.Passed); assert(!tmpFile.exists()); }
@Test public void shouldSyncToSpecifiedRevision() throws Exception { P4Material material = p4Fixture.material(VIEW); updateTo(material, new RevisionContext(REVISION_2), JobResult.Passed); assertThat(workingDir.listFiles().length, is(7)); updateTo(material, new RevisionContext(REVISION_3), JobResult.Passed); assertThat(workingDir.listFiles().length, is(6)); }
@Test public void shouldDoAFreshCheckoutIfDestIsNotARepo() throws Exception { updateTo(svnMaterial, new RevisionContext(revision), JobResult.Passed); console.clear(); FileUtils.deleteQuietly(new File(workingDir, "svnDir/.svn")); updateTo(svnMaterial, new RevisionContext(revision), JobResult.Passed); assertThat(console.output(), containsString("Checked out revision")); assertThat(console.output(), not(containsString("Updating"))); }
@Test public void shouldSupportCustomDestinations() throws Exception { P4Material material = p4Fixture.material(VIEW); material.setFolder("dest"); updateTo(material, new RevisionContext(REVISION_2), JobResult.Passed); assertThat(workingDir.listFiles().length, is(1)); assertThat(new File(workingDir, "dest").listFiles().length, is(7)); }
@Test public void shouldNotDeleteAndRecheckoutDirectoryUnlessUrlChanges() throws Exception { String repositoryUrl = new HgTestRepo(temporaryFolder).projectRepositoryUrl(); HgMaterial material = MaterialsMother.hgMaterial(repositoryUrl); updateTo(material, new RevisionContext(REVISION_0), JobResult.Passed); File shouldNotBeRemoved = new File(workingFolder, "shouldBeRemoved"); shouldNotBeRemoved.createNewFile(); assertThat(shouldNotBeRemoved.exists(), is(true)); updateTo(material, new RevisionContext(REVISION_2), JobResult.Passed); assert(MaterialUrl.sameUrl(material.getUrl(), repositoryUrl)); assertThat(shouldNotBeRemoved.exists(), is(true)); }
@Test public void shouldNotDeleteAndRecheckoutDirectoryWhenUrlSame() throws Exception { GitMaterial material = new GitMaterial(new GitTestRepo(temporaryFolder).projectRepositoryUrl(), true); updateTo(material, new RevisionContext(new StringRevision("origin/master")), JobResult.Passed); File shouldNotBeRemoved = new File(new File(workingDir, ".git"), "shouldNotBeRemoved"); FileUtils.writeStringToFile(shouldNotBeRemoved, "gundi", UTF_8); assertThat(shouldNotBeRemoved.exists(), is(true)); updateTo(material, new RevisionContext(new StringRevision("origin/master")), JobResult.Passed); assertThat("Should not have deleted whole folder", shouldNotBeRemoved.exists(), is(true)); }
@Test @RunIf(value = EnhancedOSChecker.class, arguments = {DO_NOT_RUN_ON, WINDOWS}) public void shouldUpdateIfNotCheckingOutFreshCopy() throws IOException { updateTo(svnMaterial, new RevisionContext(revision), JobResult.Passed); console.clear(); updateTo(svnMaterial, new RevisionContext(revision), JobResult.Passed); assertThat(console.output(), not(containsString("Checked out revision"))); assertThat(console.output(), containsString("Updating")); }
@Test public void shouldNotDeleteAndRecheckoutDirectoryWhenBranchIsBlank() throws Exception { String repositoryUrl = new GitTestRepo(temporaryFolder).projectRepositoryUrl(); GitMaterial material = new GitMaterial(repositoryUrl, false); updateTo(material, new RevisionContext(new StringRevision("origin/master")), JobResult.Passed); File shouldNotBeRemoved = new File(new File(workingDir, ".git"), "shouldNotBeRemoved"); FileUtils.writeStringToFile(shouldNotBeRemoved, "Text file", UTF_8); GitMaterial material1 = new GitMaterial(repositoryUrl, " "); updateTo(material1, new RevisionContext(new StringRevision("origin/master")), JobResult.Passed); assertThat("Should not have deleted whole folder", shouldNotBeRemoved.exists(), is(true)); }
@Test public void cloneWithDeepWorkingDir() throws Exception { GitMaterial material = new GitMaterial(new GitTestRepo(temporaryFolder).projectRepositoryUrl(), "", "foo/bar/baz", true); updateTo(material, new RevisionContext(REVISION_4), JobResult.Passed); assertThat(new File(workingDir, "foo/bar/baz/build.xml").exists(), is(true)); }
@Test public void failureCommandShouldNotLeakPasswordOnUrl() throws Exception { HgMaterial material = MaterialsMother.hgMaterial("https://foo:foopassword@this.is.absolute.not.exists"); updateTo(material, new RevisionContext(REVISION_1), JobResult.Failed); assertThat(console.output(), containsString("https://foo:******@this.is.absolute.not.exists")); assertThat(console.output(), not(containsString("foopassword"))); }
@Test public void shouldNotDisplayPassword() throws Exception { P4Material material = p4Fixture.material(VIEW); material.setPassword("wubba lubba dub dub"); updateTo(material, new RevisionContext(REVISION_2), JobResult.Failed); assertThat(console.output(), not(containsString("wubba lubba dub dub"))); } }
@Test public void shouldNotLeakPasswordInUrlIfCheckoutFails() throws Exception { SvnMaterial material = MaterialsMother.svnMaterial("https://foo:foopassword@thisdoesnotexist.io/repo"); updateTo(material, new RevisionContext(revision), JobResult.Failed); assertThat(console.output(), containsString("https://foo:******@thisdoesnotexist.io/repo")); assertThat(console.output(), not(containsString("foopassword"))); }
@Test public void shouldLogRepoInfoToConsoleOutWithoutFolder() throws Exception { git.updateTo(outputStreamConsumer, workingDir, new RevisionContext(GitTestRepo.REVISION_1), new TestSubprocessExecutionContext()); assertThat(outputStreamConsumer.getStdOut(), containsString( String.format("Start updating %s at revision %s from %s", "files", GitTestRepo.REVISION_1.getRevision(), git.getUrl()))); }
private void updateMaterials(Materials materials, Revision revision) { ProcessOutputStreamConsumer outputStreamConsumer = inMemoryConsumer(); TestSubprocessExecutionContext execCtx = new TestSubprocessExecutionContext(); materials.cleanUp(pipelineDir, outputStreamConsumer); for (Material material : materials) { material.updateTo(outputStreamConsumer, pipelineDir, new RevisionContext(revision), execCtx); } } }
@Test public void failureCommandShouldNotLeakPasswordOnUrl() throws Exception { GitMaterial material = new GitMaterial("https://foo:foopassword@this.is.absolute.not.exists", true); updateTo(material, new RevisionContext(new StringRevision("origin/master")), JobResult.Failed); assertThat(console.output(), containsString("https://foo:******@this.is.absolute.not.exists/")); assertThat(console.output(), not(containsString("foopassword"))); }
@Test public void updateToANewRevisionShouldNotResultInUnshallowing() throws IOException { GitMaterial material = new GitMaterial(repo.projectRepositoryUrl(), true); material.updateTo(inMemoryConsumer(), workingDir, new RevisionContext(REVISION_4, REVISION_4, 1), context()); assertThat(localRepoFor(material).isShallow(), is(true)); List<Modification> modifications = repo.addFileAndPush("newfile", "add new file"); StringRevision newRevision = new StringRevision(modifications.get(0).getRevision()); material.updateTo(inMemoryConsumer(), workingDir, new RevisionContext(newRevision, newRevision, 1), context()); assertThat(new File(workingDir, "newfile").exists(), is(true)); assertThat(localRepoFor(material).isShallow(), is(true)); }
@Test public void shouldConvertExistingRepoToFullRepoWhenShallowCloneIsOff() throws IOException { String repositoryUrl = new GitTestRepo(temporaryFolder).projectRepositoryUrl(); GitMaterial shallowMaterial = new GitMaterial(repositoryUrl, true); updateTo(shallowMaterial, new RevisionContext(REVISION_3), JobResult.Passed); assertThat(localRepoFor(shallowMaterial).isShallow(), is(true)); GitMaterial fullMaterial = new GitMaterial(repositoryUrl, false); updateTo(fullMaterial, new RevisionContext(REVISION_4), JobResult.Passed); assertThat(localRepoFor(fullMaterial).isShallow(), is(false)); }
@Test public void shouldAllowSubmoduleUrlstoChange() throws Exception { GitSubmoduleRepos submoduleRepos = new GitSubmoduleRepos(temporaryFolder); String submoduleDirectoryName = "local-submodule"; submoduleRepos.addSubmodule(SUBMODULE, submoduleDirectoryName); GitMaterial material = new GitMaterial(submoduleRepos.projectRepositoryUrl(), true); updateTo(material, new RevisionContext(new StringRevision("origin/HEAD")), JobResult.Passed); submoduleRepos.changeSubmoduleUrl(submoduleDirectoryName); updateTo(material, new RevisionContext(new StringRevision("origin/HEAD")), JobResult.Passed); assertThat(console.output(), containsString("Synchronizing submodule url for 'local-submodule'")); }
public HgMaterial updateTo(File baseDir) { HgMaterial material = material(); Revision tip = latestRevision(material, baseDir, new TestSubprocessExecutionContext()); material.updateTo(ProcessOutputStreamConsumer.inMemoryConsumer(), baseDir, new RevisionContext(tip), new TestSubprocessExecutionContext()); return material; }
@Test public void shouldBeAbleToUpdateToRevisionNotFetched() { GitMaterial material = new GitMaterial(repo.projectRepositoryUrl(), true); material.updateTo(inMemoryConsumer(), workingDir, new RevisionContext(REVISION_3, REVISION_2, 2), context()); assertThat(localRepoFor(material).currentRevision(), is(REVISION_3.getRevision())); assertThat(localRepoFor(material).containsRevisionInBranch(REVISION_2), is(true)); assertThat(localRepoFor(material).containsRevisionInBranch(REVISION_3), is(true)); }