Esempio n. 1
0
  @Test
  public void getStagesUsedAsMaterials() {
    HgMaterialConfig hg = MaterialConfigsMother.hgMaterialConfig();

    StageConfig upStage = new StageConfig(new CaseInsensitiveString("stage1"), new JobConfigs());
    PipelineConfig up1 =
        new PipelineConfig(new CaseInsensitiveString("up1"), new MaterialConfigs(hg), upStage);
    PipelineConfig up2 =
        new PipelineConfig(
            new CaseInsensitiveString("up2"),
            new MaterialConfigs(hg),
            new StageConfig(new CaseInsensitiveString("stage2"), new JobConfigs()));

    DependencyMaterialConfig dependency1 =
        MaterialConfigsMother.dependencyMaterialConfig("up1", "stage1");
    DependencyMaterialConfig dependency2 =
        MaterialConfigsMother.dependencyMaterialConfig("up2", "stage2");

    PipelineConfig down1 =
        new PipelineConfig(
            new CaseInsensitiveString("down1"), new MaterialConfigs(dependency1, dependency2, hg));
    PipelineConfig down2 =
        new PipelineConfig(
            new CaseInsensitiveString("down2"), new MaterialConfigs(dependency1, dependency2, hg));

    CruiseConfig config = new CruiseConfig(new PipelineConfigs(up1, up2, down1, down2));
    Set<StageConfig> stages = config.getStagesUsedAsMaterials(up1);
    assertThat(stages.size(), is(1));
    assertThat(stages.contains(upStage), is(true));
  }
Esempio n. 2
0
 private PipelineConfig pipelineWithManyMaterials(boolean autoUpdate) {
   SvnMaterialConfig svnMaterialConfig = MaterialConfigsMother.svnMaterialConfig();
   svnMaterialConfig.setAutoUpdate(autoUpdate);
   MaterialConfig gitMaterialConfig = MaterialConfigsMother.gitMaterialConfig("/foo/bar.git");
   HgMaterialConfig hgMaterialConfig = MaterialConfigsMother.hgMaterialConfig();
   P4MaterialConfig p4MaterialConfig = MaterialConfigsMother.p4MaterialConfig();
   return new PipelineConfig(
       new CaseInsensitiveString("pipeline1"),
       new MaterialConfigs(
           svnMaterialConfig, hgMaterialConfig, gitMaterialConfig, p4MaterialConfig));
 }
Esempio n. 3
0
  @Test
  public void shouldHaveBothMaterialsIfTheTypeIsDifferent() {
    SvnMaterialConfig svn = MaterialConfigsMother.svnMaterialConfig("url", "folder1", true);
    HgMaterialConfig hg = MaterialConfigsMother.hgMaterialConfig("url", "folder2");
    PipelineConfig pipeline1 =
        new PipelineConfig(new CaseInsensitiveString("pipeline1"), new MaterialConfigs(svn));
    PipelineConfig pipeline2 =
        new PipelineConfig(new CaseInsensitiveString("pipeline2"), new MaterialConfigs(hg));

    CruiseConfig config = new CruiseConfig(new PipelineConfigs(pipeline1, pipeline2));
    assertThat(config.getAllUniqueMaterialsBelongingToAutoPipelines().size(), is(2));
  }
  @Before
  public void setup() throws Exception {
    CONFIG_HELPER = new GoConfigFileHelper();
    dbHelper.onSetUp();
    CONFIG_HELPER.usingCruiseConfigDao(goConfigDao).initializeConfigFile();
    CONFIG_HELPER.onSetUp();

    repository = new SvnCommand(null, testRepo.projectRepositoryUrl());
    goConfigService.forceNotifyListeners();
    agentAssignment.clear();
    goCache.clear();

    CONFIG_HELPER.addPipeline(
        "blahPipeline",
        "blahStage",
        MaterialConfigsMother.hgMaterialConfig(
            "file:///home/cruise/projects/cruisen/manual-testing/ant_hg/dummy"),
        "job1",
        "job2");
    CONFIG_HELPER.makeJobRunOnAllAgents("blahPipeline", "blahStage", "job2");
  }
Esempio n. 5
0
 public void replaceMaterialWithHgRepoForPipeline(String pipelinename, String hgUrl) {
   replaceMaterialForPipeline(pipelinename, MaterialConfigsMother.hgMaterialConfig(hgUrl));
 }
Esempio n. 6
0
public class IgnoreTest {
  private MaterialConfig hgMaterialConfig = MaterialConfigsMother.hgMaterialConfig();
  private String separator = File.separator;

  @Test
  public void shouldIncludeWhenTheTextDoesnotMatchDocumentUnderRoot() {
    IgnoredFiles ignore = new IgnoredFiles("a.doc");

    assertThat(ignore.shouldIgnore(hgMaterialConfig, "b.doc"), is(false));
    assertThat(ignore.shouldIgnore(hgMaterialConfig, "a.doc1"), is(false));
    assertThat(
        ignore.shouldIgnore(hgMaterialConfig, "A" + separator + "B" + separator + "a.doc"),
        is(false));
    assertThat(ignore.shouldIgnore(hgMaterialConfig, "A" + separator + "a.doc"), is(false));
  }

  @Test
  public void shouldIgnoreWhenTheTextDoesMatchDocumentUnderRoot() {
    IgnoredFiles ignore = new IgnoredFiles("a.doc");

    assertThat(ignore.shouldIgnore(hgMaterialConfig, "a.doc"), is(true));
  }

  @Test
  public void shouldIncludeWhenTheTextUnderRootIsNotADocument() {
    IgnoredFiles ignore = new IgnoredFiles("*.doc");

    assertThat(ignore.shouldIgnore(hgMaterialConfig, "a.pdf"), is(false));
    assertThat(ignore.shouldIgnore(hgMaterialConfig, "a.doc.aaa"), is(false));
    assertThat(ignore.shouldIgnore(hgMaterialConfig, "A" + separator + "a.doc"), is(false));
  }

  @Test
  public void shouldIgnoreWhenTheTextUnderRootIsADocument() {
    IgnoredFiles ignore = new IgnoredFiles("*.doc");

    assertThat(ignore.shouldIgnore(hgMaterialConfig, "a.doc"), is(true));
  }

  @Test
  public void shouldIncludeWhenTextIsNotDocumentInChildOfRootFolder() throws Exception {
    IgnoredFiles ignore = new IgnoredFiles("*/*.doc");

    assertThat(ignore.shouldIgnore(hgMaterialConfig, "a.doc"), is(false));
    assertThat(
        ignore.shouldIgnore(hgMaterialConfig, "A" + separator + "B" + separator + "c.doc"),
        is(false));
  }

  @Test
  public void shouldIgnoreWhenTextIsDocumentInChildOfRootFolder() throws Exception {
    IgnoredFiles ignore = new IgnoredFiles("*/*.doc");

    assertThat(ignore.shouldIgnore(hgMaterialConfig, "A" + separator + "a.doc"), is(true));
    assertThat(ignore.shouldIgnore(hgMaterialConfig, "B" + separator + "c.doc"), is(true));
  }

  @Test
  public void shouldNormalizeRegex() throws Exception {
    IgnoredFiles ignore = new IgnoredFiles("*\\*.doc");

    assertThat(ignore.shouldIgnore(hgMaterialConfig, "A" + separator + "a.doc"), is(true));
    assertThat(ignore.shouldIgnore(hgMaterialConfig, "B" + separator + "c.doc"), is(true));
  }

  @Test
  public void shouldIncludeWhenTextIsNotADocumentInAnyFolder() throws Exception {
    IgnoredFiles ignore = new IgnoredFiles("**/*.doc");
    assertThat(ignore.shouldIgnore(hgMaterialConfig, "a.pdf"), is(false));
    assertThat(ignore.shouldIgnore(hgMaterialConfig, "B" + separator + "a.pdf"), is(false));
    assertThat(
        ignore.shouldIgnore(hgMaterialConfig, "A" + separator + "B" + separator + "a.pdf"),
        is(false));
  }

  @Test
  public void shouldIgnoreWhenTextIsADocumentInAnyFolder() throws Exception {
    IgnoredFiles ignore = new IgnoredFiles("**/*.doc");

    assertThat(ignore.shouldIgnore(hgMaterialConfig, "a.doc"), is(true));
    assertThat(ignore.shouldIgnore(hgMaterialConfig, "A" + separator + "a.doc"), is(true));
    assertThat(
        ignore.shouldIgnore(hgMaterialConfig, "A" + separator + "B" + separator + "a.doc"),
        is(true));
  }

  @Test
  public void shouldIgnoreWhenTextIsADocumentInAnyFolderWhenDirectoryWildcardNotInTheBegining()
      throws Exception {
    IgnoredFiles ignore = new IgnoredFiles("foo*/**/*.doc");

    assertThat(ignore.shouldIgnore(hgMaterialConfig, "foo-hi/bar/a.doc"), is(true));
    assertThat(ignore.shouldIgnore(hgMaterialConfig, "bar/baz/b.doc"), is(false));
  }

  @Test
  public void
      shouldIgnoreWhenTextIsADocumentInAnyFolderWhenDirectoryWildcardNotInTheBeginingAndTerminatesInWildcard()
          throws Exception {
    IgnoredFiles ignore = new IgnoredFiles("**/foo*/**/*");

    assertThat(ignore.shouldIgnore(hgMaterialConfig, "foo-hi/bar/a.doc"), is(true));
    assertThat(ignore.shouldIgnore(hgMaterialConfig, "bar/baz/b.doc"), is(false));
    assertThat(
        ignore.shouldIgnore(hgMaterialConfig, "hello-world/woods/foo-hi/bar/a.doc"), is(true));
  }

  @Test
  public void shouldIncludeIfTheTextIsNotADocumentInTheSpecifiedFolder() throws Exception {
    IgnoredFiles ignore = new IgnoredFiles("ROOTFOLDER/*.doc");
    assertThat(ignore.shouldIgnore(hgMaterialConfig, "shouldNotBeIgnored.doc"), is(false));
    assertThat(
        ignore.shouldIgnore(hgMaterialConfig, "ANYFOLDER" + separator + "shouldNotBeIgnored.doc"),
        is(false));
    assertThat(
        ignore.shouldIgnore(
            hgMaterialConfig,
            "ROOTFOLDER" + separator + "" + "ANYFOLDER" + separator + "shouldNotBeIgnored.doc"),
        is(false));
  }

  @Test
  public void shouldIncludIgnoreIfTextIsADocumentInTheSpecifiedFolder() throws Exception {
    IgnoredFiles ignore = new IgnoredFiles("ROOTFOLDER/*.doc");
    assertThat(ignore.shouldIgnore(hgMaterialConfig, "ROOTFOLDER" + separator + "a.doc"), is(true));
  }

  @Test
  public void shouldIncludeIfTextIsNotUnderAGivenFolder() throws Exception {
    IgnoredFiles ignore = new IgnoredFiles("**/DocumentFolder/*");
    assertThat(
        ignore.shouldIgnore(hgMaterialConfig, "A" + separator + "shouldNotBeIgnored.doc"),
        is(false));
    assertThat(
        ignore.shouldIgnore(
            hgMaterialConfig,
            "A" + separator + "DocumentFolder" + separator + "B" + separator + "d.doc"),
        is(false));
  }

  @Test
  public void shouldIgnoreIfTextIsUnderAGivenFolder() throws Exception {
    IgnoredFiles ignore = new IgnoredFiles("**/DocumentFolder/*");
    assertThat(
        ignore.shouldIgnore(
            hgMaterialConfig, "A" + separator + "DocumentFolder" + separator + "d.doc"),
        is(true));
  }

  @Test
  public void shouldIncludeIfTextIsNotUnderAFolderMatchingTheGivenFolder() throws Exception {
    IgnoredFiles ignore = new IgnoredFiles("**/*Test*/*");
    assertThat(
        ignore.shouldIgnore(hgMaterialConfig, "A" + separator + "shouldNotBeIgnored.doc"),
        is(false));
    assertThat(
        ignore.shouldIgnore(hgMaterialConfig, "B/NotIgnored" + separator + "isIgnored"), is(false));
  }

  @Test
  public void shouldIgnoreIfTextIsUnderAFolderMatchingTheGivenFolder() throws Exception {
    IgnoredFiles ignore = new IgnoredFiles("**/*Test*/*");
    assertThat(
        ignore.shouldIgnore(
            hgMaterialConfig, "B" + separator + "SomethingTestThis" + separator + "isIgnored"),
        is(true));
  }

  @Test
  public void shouldIgnoreEverythingUnderAFolderWithWildcards() throws Exception {
    IgnoredFiles ignore = new IgnoredFiles("Test/**/*.*");
    assertThat(ignore.shouldIgnore(hgMaterialConfig, "Test" + separator + "foo.txt"), is(true));
    assertThat(
        ignore.shouldIgnore(
            hgMaterialConfig, "Test" + separator + "subdir" + separator + "foo.txt"),
        is(true));
    assertThat(
        ignore.shouldIgnore(
            hgMaterialConfig,
            "Test" + separator + "subdir" + separator + "subdir" + separator + "foo.txt"),
        is(true));
    assertThat(
        ignore.shouldIgnore(
            hgMaterialConfig,
            "Test" + separator + "subdir" + separator + "subdir" + separator + "foo"),
        is(false));
  }

  @Test
  public void shouldIgnoreEverythingUnderAFolderWithWildcardsWithoutExtension() throws Exception {
    IgnoredFiles ignore = new IgnoredFiles("Test/**/*");
    assertThat(ignore.shouldIgnore(hgMaterialConfig, "Test" + separator + "foo.txt"), is(true));
    assertThat(
        ignore.shouldIgnore(
            hgMaterialConfig, "Test" + separator + "subdir" + separator + "foo.txt"),
        is(true));
    assertThat(
        ignore.shouldIgnore(
            hgMaterialConfig,
            "Test" + separator + "subdir" + separator + "subdir" + separator + "foo.txt"),
        is(true));
    assertThat(
        ignore.shouldIgnore(
            hgMaterialConfig,
            "Test" + separator + "subdir" + separator + "subdir" + separator + "foo"),
        is(true));
  }

  @Test
  public void shouldSkipDiot() throws Exception {
    IgnoredFiles ignore = new IgnoredFiles("helper/*.*");

    assertThat(
        ignore.shouldIgnore(
            hgMaterialConfig, "helper" + separator + "configuration_reference.html"),
        is(true));
    assertThat(
        ignore.shouldIgnore(
            hgMaterialConfig,
            "helper" + separator + "conf-docs" + separator + "configuration_reference.html"),
        is(false));
    assertThat(
        ignore.shouldIgnore(
            hgMaterialConfig,
            "helper"
                + separator
                + "resources"
                + separator
                + "images"
                + separator
                + "cruise"
                + separator
                + "dependent_build.png"),
        is(false));
  }

  @Test
  public void shouldAddErrorToItsErrorCollection() {
    IgnoredFiles ignore = new IgnoredFiles("helper/*.*");
    ignore.addError("pattern", "not allowed");
    assertThat(ignore.errors().on("pattern"), is("not allowed"));
  }

  @Test
  public void shouldEscapeAllValidSpecialCharactersInPattern() { // see mingle #5700
    hgMaterialConfig = new TfsMaterialConfig(new GoCipher());
    IgnoredFiles ignore = new IgnoredFiles("$/tfs_repo/Properties/*.*");
    assertThat(
        ignore.shouldIgnore(
            hgMaterialConfig,
            "$/tfs_repo" + separator + "Properties" + separator + "AssemblyInfo.cs"),
        is(true));
  }

  @Test
  public void understandPatternPunct() {
    assertThat(Pattern.matches("a\\.doc", "a.doc"), is(true));
    assertThat(Pattern.matches("\\p{Punct}", "*"), is(true));
    assertThat(Pattern.matches("\\p{Punct}", "{"), is(true));
    assertThat(Pattern.matches("\\p{Punct}", "]"), is(true));
    assertThat(Pattern.matches("\\p{Punct}", "-"), is(true));
    assertThat(Pattern.matches("\\p{Punct}", "."), is(true));
  }
}