Search in sources :

Example 1 with RegexMatcher

use of com.thoughtworks.go.matchers.RegexMatcher in project gocd by gocd.

the class GitCommandTest method shouldBombForResetWorkingDirWhenSubmoduleUpdateFails.

@Test
public void shouldBombForResetWorkingDirWhenSubmoduleUpdateFails() throws Exception {
    GitSubmoduleRepos submoduleRepos = new GitSubmoduleRepos(temporaryFolder);
    File submoduleFolder = submoduleRepos.addSubmodule(SUBMODULE, "sub1");
    GitCommand gitWithSubmodule = new GitCommand(null, createTempWorkingDirectory(), GitMaterialConfig.DEFAULT_BRANCH, false, new HashMap<>(), null);
    gitWithSubmodule.clone(inMemoryConsumer(), submoduleRepos.mainRepo().getUrl());
    FileUtils.deleteDirectory(submoduleFolder);
    assertThat(submoduleFolder.exists(), is(false));
    try {
        gitWithSubmodule.resetWorkingDir(new SysOutStreamConsumer(), new StringRevision("HEAD"));
        fail("should have failed for non 0 return code");
    } catch (Exception e) {
        assertThat(e.getMessage(), new RegexMatcher(String.format("[Cc]lone of '%s' into submodule path '((.*)[\\/])?sub1' failed", Pattern.quote(submoduleFolder.getAbsolutePath()))));
    }
}
Also used : GitSubmoduleRepos(com.thoughtworks.go.helper.GitSubmoduleRepos) SysOutStreamConsumer(com.thoughtworks.go.mail.SysOutStreamConsumer) StringRevision(com.thoughtworks.go.domain.materials.mercurial.StringRevision) RegexMatcher(com.thoughtworks.go.matchers.RegexMatcher) ModifiedFile(com.thoughtworks.go.domain.materials.ModifiedFile) File(java.io.File) CommandLineException(com.thoughtworks.go.util.command.CommandLineException) ExpectedException(org.junit.rules.ExpectedException) IOException(java.io.IOException) Test(org.junit.Test)

Example 2 with RegexMatcher

use of com.thoughtworks.go.matchers.RegexMatcher in project gocd by gocd.

the class GitMaterialUpdaterTest method shouldBombForFetchAndResetWhenSubmoduleUpdateFails.

@Test
public void shouldBombForFetchAndResetWhenSubmoduleUpdateFails() throws Exception {
    GitSubmoduleRepos submoduleRepos = new GitSubmoduleRepos(temporaryFolder);
    File submoduleFolder = submoduleRepos.addSubmodule(SUBMODULE, "sub1");
    GitMaterial material = new GitMaterial(submoduleRepos.projectRepositoryUrl(), true);
    FileUtils.deleteDirectory(submoduleFolder);
    assertThat(submoduleFolder.exists(), Matchers.is(false));
    updateTo(material, new RevisionContext(new StringRevision("origin/HEAD")), JobResult.Failed);
    assertThat(console.output(), // git on windows prints full submodule paths
    new RegexMatcher(String.format("[Cc]lone of '%s' into submodule path '((.*)[\\/])?sub1' failed", Pattern.quote(submoduleFolder.getAbsolutePath()))));
}
Also used : GitSubmoduleRepos(com.thoughtworks.go.helper.GitSubmoduleRepos) RevisionContext(com.thoughtworks.go.domain.materials.RevisionContext) StringRevision(com.thoughtworks.go.domain.materials.mercurial.StringRevision) RegexMatcher(com.thoughtworks.go.matchers.RegexMatcher) File(java.io.File) Test(org.junit.Test)

Aggregations

StringRevision (com.thoughtworks.go.domain.materials.mercurial.StringRevision)2 GitSubmoduleRepos (com.thoughtworks.go.helper.GitSubmoduleRepos)2 RegexMatcher (com.thoughtworks.go.matchers.RegexMatcher)2 File (java.io.File)2 Test (org.junit.Test)2 ModifiedFile (com.thoughtworks.go.domain.materials.ModifiedFile)1 RevisionContext (com.thoughtworks.go.domain.materials.RevisionContext)1 SysOutStreamConsumer (com.thoughtworks.go.mail.SysOutStreamConsumer)1 CommandLineException (com.thoughtworks.go.util.command.CommandLineException)1 IOException (java.io.IOException)1 ExpectedException (org.junit.rules.ExpectedException)1