view mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgRepoTest.java @ 1002:138c9ab0b1f0 Jaipur-2018.1.x

TW-55764: remove option
author pavel.sher
date Fri, 29 Jun 2018 11:48:54 +0200
parents 1168c4c64d49
children
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.buildTriggers.vcs.mercurial.command.AuthSettings;
import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.TestCommandSettingsFactory;
import jetbrains.buildServer.util.TestFor;
import jetbrains.buildServer.vcs.VcsException;
import org.jetbrains.annotations.NotNull;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import java.io.File;
import java.util.List;

import static jetbrains.buildServer.buildTriggers.vcs.mercurial.Util.copyRepository;
import static org.testng.AssertJUnit.*;

@Test
public class HgRepoTest extends BaseMercurialTestCase {

  public void subrepos() throws Exception {
    File repository = myTempFiles.createTempDir();
    copyRepository(new File("mercurial-tests/testData/subrepos/r1"), repository);
    HgRepo repo = new HgRepo(new TestCommandSettingsFactory(), repository, Util.getHgPath(), new AuthSettings());
    List<HgSubrepoConfigChange> changes = repo.getSubrepoConfigChanges("09c256b6163e");
    assertEquals(1, changes.size());
    HgSubrepoConfigChange c = changes.get(0);
    assertEquals("r2", c.getPath());
    //noinspection ConstantConditions
    assertTrue(c.getPrevious().get(0).revision().startsWith("9e4a2fef1a1c"));
    //noinspection ConstantConditions
    assertTrue(c.getCurrent().revision().startsWith("ebb884b1b691"));

    changes = repo.getSubrepoConfigChanges("4d7b3db8779f");
    assertEquals(1, changes.size());
    c = changes.get(0);
    assertEquals("r2", c.getPath());
    //noinspection ConstantConditions
    assertTrue(c.getPrevious().get(0).revision().startsWith("916933c1dd8e"));
    assertNull(c.getCurrent());

    changes = repo.getSubrepoConfigChanges("d350e7209906");
    assertEquals(1, changes.size());
  }


  @DataProvider(name = "urlsWithNewLines")
  public static Object[][] urlsWithNewLines() {
    return new Object[][] {
            new Object[] { "http://some.org/repo\n" },
            new Object[] { "http://some.org/repo\r" },
            new Object[] { "http://some.org/repo\n[section]" },
            new Object[] { "http://some.org/repo\r[section]" },
            new Object[] { "http://some.org/repo\r\n[section]" },
    };
  }

  @TestFor(issues = "TW-50043")//TW-50043 is about git, but hg suffers from the same problem
  @Test(dataProvider = "urlsWithNewLines")
  public void newline_in_url(@NotNull String url) throws Exception {
    File repository = myTempFiles.createTempDir();
    HgRepo repo = new HgRepo(new TestCommandSettingsFactory(), repository, Util.getHgPath(), new AuthSettings());
    repo.init().call();
    try {
      repo.setDefaultPath(url);
      fail("no error for url '" + url + "'");
    } catch (VcsException e) {
      //expected
    }
  }
}