Search in sources :

Example 21 with TestFor

use of jetbrains.buildServer.util.TestFor in project teamcity-git by JetBrains.

the class CollectChangesTest method branch_turned_into_dir.

@TestFor(issues = { "TW-36080", "TW-35700" })
@Test(dataProvider = "separateProcess,newConnectionForPrune")
public void branch_turned_into_dir(boolean fetchInSeparateProcess, boolean newConnectionForPrune) throws Exception {
    myConfig.setSeparateProcessForFetch(fetchInSeparateProcess).setNewConnectionForPrune(newConnectionForPrune);
    VcsRoot root = vcsRoot().withFetchUrl(myRepo).withBranch("master").build();
    RepositoryStateData s1 = createVersionState("refs/heads/master", map("refs/heads/master", "f3f826ce85d6dad25156b2d7550cedeb1a422f4c", "refs/heads/patch-tests", "a894d7d58ffde625019a9ecf8267f5f1d1e5c341"));
    RepositoryStateData s2 = createVersionState("refs/heads/master", map("refs/heads/master", "3b9fbfbb43e7edfad018b482e15e7f93cca4e69f", "refs/heads/patch-tests", "a894d7d58ffde625019a9ecf8267f5f1d1e5c341"));
    git().getCollectChangesPolicy().collectChanges(root, s1, s2, CheckoutRules.DEFAULT);
    // rename refs/heads/patch-tests to refs/heads/patch-tests/a and make it point to commit not yet fetched by TC, so the fetch is required
    Repository r = new RepositoryBuilder().setGitDir(myRepo).build();
    r.getRefDatabase().newRename("refs/heads/patch-tests", "refs/heads/patch-tests/a").rename();
    RefUpdate refUpdate = r.updateRef("refs/heads/patch-tests/a");
    refUpdate.setForceUpdate(true);
    refUpdate.setNewObjectId(ObjectId.fromString("39679cc440c83671fbf6ad8083d92517f9602300"));
    refUpdate.update();
    RepositoryStateData s3 = createVersionState("refs/heads/master", map("refs/heads/master", "3b9fbfbb43e7edfad018b482e15e7f93cca4e69f", "refs/heads/patch-tests/a", "39679cc440c83671fbf6ad8083d92517f9602300"));
    git().getCollectChangesPolicy().collectChanges(root, s2, s3, CheckoutRules.DEFAULT);
}
Also used : GitTestUtil.copyRepository(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.copyRepository) Repository(org.eclipse.jgit.lib.Repository) RepositoryBuilder(org.eclipse.jgit.lib.RepositoryBuilder) RefUpdate(org.eclipse.jgit.lib.RefUpdate) Test(org.testng.annotations.Test) TestFor(jetbrains.buildServer.util.TestFor)

Example 22 with TestFor

use of jetbrains.buildServer.util.TestFor in project teamcity-git by JetBrains.

the class CollectChangesTest method fetch_should_not_fail_if_remote_repository_does_not_have_some_branches.

@Test
@TestFor(issues = "http://youtrack.jetbrains.com/issue/TW-29798#comment=27-537697")
public void fetch_should_not_fail_if_remote_repository_does_not_have_some_branches() throws Exception {
    VcsRoot root = vcsRoot().withFetchUrl(myRepo).withBranch("master").withReportTags(true).build();
    // setup fetcher with a counter
    ServerPluginConfig config = myConfig.build();
    VcsRootSshKeyManager manager = new EmptyVcsRootSshKeyManager();
    FetchCommand fetchCommand = new FetchCommandImpl(config, new TransportFactoryImpl(config, manager), new FetcherProperties(config), manager);
    FetchCommandCountDecorator fetchCounter = new FetchCommandCountDecorator(fetchCommand);
    GitVcsSupport git = gitSupport().withPluginConfig(myConfig).withFetchCommand(fetchCounter).build();
    RepositoryStateData state = git.getCurrentState(root);
    // has a single branch
    RepositoryStateData s1 = createVersionState("refs/heads/master", map("refs/heads/master", state.getBranchRevisions().get("refs/heads/master")));
    Map<String, String> branches = new HashMap<String, String>(state.getBranchRevisions());
    // unknown branch that points to a commit that exists in remote repo
    branches.put("refs/heads/unknown.branch", branches.get(state.getDefaultBranchName()));
    // has many branches, some of them don't exist in remote repository
    RepositoryStateData s2 = createVersionState("refs/heads/master", branches);
    // no failure if 'fromState' contains non-existing branch
    git.getCollectChangesPolicy().collectChanges(root, s2, s1, CheckoutRules.DEFAULT);
    assertEquals(fetchCounter.getFetchCount(), 1);
    FileUtil.delete(config.getCachesDir());
    fetchCounter.resetFetchCounter();
    try {
        git.getCollectChangesPolicy().collectChanges(root, s1, s2, CheckoutRules.DEFAULT);
        fail("Changes collection was expected to fail because 'toState' contains non-existing branch");
    } catch (VcsException e) {
    // expected
    }
}
Also used : VcsRootSshKeyManager(jetbrains.buildServer.ssh.VcsRootSshKeyManager) Test(org.testng.annotations.Test) TestFor(jetbrains.buildServer.util.TestFor)

Example 23 with TestFor

use of jetbrains.buildServer.util.TestFor in project teamcity-git by JetBrains.

the class CollectChangesTest method ignore_missing_branch.

@TestFor(issues = "TW-38899")
@Test(dataProvider = "doFetchInSeparateProcess", dataProviderClass = FetchOptionsDataProvider.class)
public void ignore_missing_branch(boolean fetchInSeparateProcess) throws Exception {
    myConfig.setSeparateProcessForFetch(fetchInSeparateProcess);
    myConfig.setIgnoreMissingRemoteRef(true);
    myConfig.withFetcherProperties(PluginConfigImpl.IGNORE_MISSING_REMOTE_REF, "true");
    File repo = copyRepository(myTempFiles, dataFile("repo_for_fetch.2.personal"), "repo.git");
    ServerPluginConfig config = myConfig.build();
    VcsRootSshKeyManager manager = new EmptyVcsRootSshKeyManager();
    AtomicBoolean updateRepo = new AtomicBoolean(false);
    // wrapper for fetch command which will remove ref in remote repository just before fetch
    FetchCommand fetchCommand = new FetchCommandImpl(config, new TransportFactoryImpl(config, manager), new FetcherProperties(config), manager) {

        @Override
        public void fetch(@NotNull Repository db, @NotNull URIish fetchURI, @NotNull FetchSettings settings) throws IOException, VcsException {
            if (updateRepo.get()) {
                FileUtil.delete(repo);
                copyRepository(dataFile("repo_for_fetch.3"), repo);
            }
            super.fetch(db, fetchURI, settings);
        }
    };
    GitVcsSupport git = gitSupport().withPluginConfig(myConfig).withFetchCommand(fetchCommand).build();
    VcsRoot root = vcsRoot().withFetchUrl(repo).build();
    RepositoryStateData s0 = createVersionState("refs/heads/master", map("refs/heads/master", "add81050184d3c818560bdd8839f50024c188586", "refs/heads/personal", "add81050184d3c818560bdd8839f50024c188586"));
    RepositoryStateData s1 = createVersionState("refs/heads/master", map("refs/heads/master", "add81050184d3c818560bdd8839f50024c188586", "refs/heads/personal", "d47dda159b27b9a8c4cee4ce98e4435eb5b17168"));
    // init repo on server:
    git.getCollectChangesPolicy().collectChanges(root, s0, s1, CheckoutRules.DEFAULT);
    RepositoryStateData s2 = createVersionState("refs/heads/master", map("refs/heads/master", "bba7fbcc200b4968e6abd2f7d475dc15306cafc6", "refs/heads/personal", "d47dda159b27b9a8c4cee4ce98e4435eb5b17168"));
    // refs/heads/personal ref disappears from remote repo:
    updateRepo.set(true);
    // changes collecting doesn't fail
    git.getCollectChangesPolicy().collectChanges(root, s1, s2, CheckoutRules.DEFAULT);
}
Also used : URIish(org.eclipse.jgit.transport.URIish) NotNull(org.jetbrains.annotations.NotNull) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) GitTestUtil.copyRepository(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.copyRepository) Repository(org.eclipse.jgit.lib.Repository) VcsRootSshKeyManager(jetbrains.buildServer.ssh.VcsRootSshKeyManager) GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) File(java.io.File) Test(org.testng.annotations.Test) TestFor(jetbrains.buildServer.util.TestFor)

Example 24 with TestFor

use of jetbrains.buildServer.util.TestFor in project teamcity-git by JetBrains.

the class CollectChangesTest method collect_changes_between_repositories_with_different_urls_and_branches.

@TestFor(issues = "TW-23781")
public void collect_changes_between_repositories_with_different_urls_and_branches() throws Exception {
    File forkDir = myTempFiles.createTempDir();
    copyRepository(myRepo, forkDir);
    VcsRoot root1 = vcsRoot().withFetchUrl(myRepo).withBranch("master").build();
    VcsRoot root2 = vcsRoot().withFetchUrl(forkDir).withBranch("patch-tests").build();
    RepositoryStateData state1 = createVersionState("refs/heads/master", map("refs/heads/master", "465ad9f630e451b9f2b782ffb09804c6a98c4bb9"));
    RepositoryStateData state2 = createVersionState("refs/heads/patch-tests", map("refs/heads/patch-tests", "27de3d118ca320d3a8a08320ff05aa0567996590"));
    List<ModificationData> changes = git().getCollectChangesPolicy().collectChanges(root1, state1, root2, state2, CheckoutRules.DEFAULT);
    then(changes).extracting("version").containsOnly("27de3d118ca320d3a8a08320ff05aa0567996590", "d1a88fd33c516c1b607db75eb62244b2ea495c42", "37c371a6db0acefc77e3be99d16a44413e746591", "b5d65401a4e8a09b80b8d73ca4392f1913e99ff5", "592c5bcee6d906482177a62a6a44efa0cff9bbc7", "1837cf38309496165054af8bf7d62a9fe8997202", "049a98762a29677da352405b27b3d910cb94eb3b", "7e916b0edd394d0fca76456af89f4ff7f7f65049", "0dd03338d20d2e8068fbac9f24899d45d443df38", "70dbcf426232f7a33c7e5ebdfbfb26fc8c467a46", "a894d7d58ffde625019a9ecf8267f5f1d1e5c341");
}
Also used : GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) File(java.io.File) TestFor(jetbrains.buildServer.util.TestFor)

Example 25 with TestFor

use of jetbrains.buildServer.util.TestFor in project teamcity-git by JetBrains.

the class CollectChangesTest method fetch_should_not_retrieve_all_tags_if_we_decided_to_fetch_all_specs.

@Test(enabled = false)
@TestFor(issues = "TW-64494")
public void fetch_should_not_retrieve_all_tags_if_we_decided_to_fetch_all_specs() throws Exception {
    myConfig.setSeparateProcessForFetch(false);
    final File fetchUrl = getRemoteRepositoryDir("repo_with_tags");
    VcsRoot root = vcsRoot().withFetchUrl(fetchUrl).withBranch("master").withReportTags(false).build();
    GitVcsSupport git = gitSupport().withPluginConfig(myConfig).build();
    // also fetches repository
    RepositoryStateData curState = git.getCurrentState(root);
    URIish uri = new URIish(fetchUrl.getCanonicalPath());
    File dir = git.getRepositoryManager().getMirrorDir(uri.toString());
    then(dir).isDirectory();
    checkCommitNotFetched(git, uri, "74577c15655ab221af62663d8977a2d083aca952");
    Map<String, String> branches = new HashMap<>(curState.getBranchRevisions());
    // unknown branch that points to some non existing commit
    branches.put("refs/heads/unknown.branch", "xxx");
    RepositoryStateData newState = createVersionState("refs/heads/master", branches);
    try {
        git.getCollectChangesPolicy().collectChanges(root, curState, newState, CheckoutRules.DEFAULT);
    } catch (VcsException e) {
    // this is ok, since our revision for unknown.branch is fake
    }
    checkCommitNotFetched(git, uri, "74577c15655ab221af62663d8977a2d083aca952");
}
Also used : URIish(org.eclipse.jgit.transport.URIish) GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) File(java.io.File) Test(org.testng.annotations.Test) TestFor(jetbrains.buildServer.util.TestFor)

Aggregations

TestFor (jetbrains.buildServer.util.TestFor)129 Test (org.testng.annotations.Test)81 File (java.io.File)65 GitTestUtil.dataFile (jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile)56 VcsRootImpl (jetbrains.buildServer.vcs.impl.VcsRootImpl)26 CheckoutRules (jetbrains.buildServer.vcs.CheckoutRules)21 VcsRoot (jetbrains.buildServer.vcs.VcsRoot)17 SFinishedBuild (jetbrains.buildServer.serverSide.SFinishedBuild)12 VcsException (jetbrains.buildServer.vcs.VcsException)11 URIish (org.eclipse.jgit.transport.URIish)11 Repository (org.eclipse.jgit.lib.Repository)9 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)7 AfterMethod (org.testng.annotations.AfterMethod)7 BeforeMethod (org.testng.annotations.BeforeMethod)7 Method (java.lang.reflect.Method)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 GitTestUtil.copyRepository (jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.copyRepository)6 Build (jetbrains.buildServer.server.rest.model.build.Build)6 BuildTypeImpl (jetbrains.buildServer.serverSide.impl.BuildTypeImpl)6 FileUtil.writeFile (jetbrains.buildServer.util.FileUtil.writeFile)6