view mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/TagsTest.java @ 976:7bf4d943d5bb

Update copyright
author pavel.sher
date Mon, 22 Jan 2018 11:39:20 +0100
parents 31a1aca3305c
children 10dc26b32c35
line wrap: on
line source
/*
 * Copyright 2000-2018 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package jetbrains.buildServer.buildTriggers.vcs.mercurial;

import jetbrains.buildServer.vcs.RepositoryStateData;
import jetbrains.buildServer.vcs.VcsRoot;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.io.File;
import java.io.IOException;

import static jetbrains.buildServer.buildTriggers.vcs.mercurial.BookmarksTest.RepositoryStateDataMatcher.hasBranch;
import static jetbrains.buildServer.buildTriggers.vcs.mercurial.BookmarksTest.RepositoryStateDataMatcher.hasNoBranch;
import static jetbrains.buildServer.buildTriggers.vcs.mercurial.MercurialSupportBuilder.mercurialSupport;
import static jetbrains.buildServer.buildTriggers.vcs.mercurial.ServerPluginConfigBuilder.serverPluginConfig;
import static jetbrains.buildServer.buildTriggers.vcs.mercurial.VcsRootBuilder.vcsRoot;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.not;

@RequiredHgVersion(min = "1.7.0")
@Test(dataProviderClass = HgVersionConstraint.class, dataProvider = "installedHgVersion")
public class TagsTest extends BaseMercurialTestCase {

  private File myRemoteRepository;
  private ServerPluginConfigBuilder myConfig;

  @BeforeMethod
  public void setUp() throws Exception {
    super.setUp();
    myConfig = serverPluginConfig()
            .cachesDir(myTempFiles.createTempDir())
            .hgPath(Util.getHgPath());

    myRemoteRepository = myTempFiles.createTempDir();
    Util.copyRepository(new File("mercurial-tests/testData/tags"), myRemoteRepository);
  }

  public void no_tags_reported_by_default(HgVersion _) throws Exception {
    VcsRoot root = vcsRoot().withUrl(myRemoteRepository.getAbsolutePath()).build();
    RepositoryStateData state = getVcs().getCollectChangesPolicy().getCurrentState(root);
    assertThat(state, not(hasBranch("v1").withRevision("fa7ad5b80a88")));
    assertThat(state, not(hasBranch("v4").withRevision("f7fbcc489e40")));
  }

  public void should_report_tag_revisions(HgVersion _) throws Exception {
    VcsRoot root = vcsRoot().withUrl(myRemoteRepository.getAbsolutePath()).withTagsEnabled(true).build();
    RepositoryStateData state = getVcs().getCollectChangesPolicy().getCurrentState(root);
    assertThat(state, hasBranch("v1").withRevision("fa7ad5b80a88"));
    assertThat(state, hasBranch("v4").withRevision("f7fbcc489e40"));
  }

  public void branch_has_higher_precedence_over_tag(HgVersion _) throws Exception {
    VcsRoot root = vcsRoot().withUrl(myRemoteRepository.getAbsolutePath()).withTagsEnabled(true).build();
    RepositoryStateData state = getVcs().getCollectChangesPolicy().getCurrentState(root);
    assertThat(state, hasBranch("topic").withRevision("efde33cd0b66"));
  }

  public void tags_can_be_turned_off_globally(HgVersion _) throws Exception {
    myConfig.withTagsAsBranches(false);
    VcsRoot root = vcsRoot().withUrl(myRemoteRepository.getAbsolutePath()).withTagsEnabled(true).build();
    RepositoryStateData state = getVcs().getCollectChangesPolicy().getCurrentState(root);
    assertThat(state, not(hasBranch("v1").withRevision("fa7ad5b80a88")));
    assertThat(state, not(hasBranch("v4").withRevision("f7fbcc489e40")));
  }

  public void tags_should_not_include_tip(HgVersion _) throws Exception {
    VcsRoot root = vcsRoot().withUrl(myRemoteRepository.getAbsolutePath()).withTagsEnabled(true).build();
    RepositoryStateData state = getVcs().getCollectChangesPolicy().getCurrentState(root);
    assertThat(state, hasNoBranch("tip"));
  }

  private MercurialVcsSupport getVcs() throws IOException {
    return mercurialSupport().withConfig(myConfig.build()).build();
  }
}