Mercurial > hg > mercurial
view mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/IdentifyCommandTest.java @ 1049:0022415d251d cloud
from trunk: fixed tests for recent hg versions
(grafted from 5bec80ce92ae32b6e271be3131dcfbd4cebbf918)
(grafted from a377f996514e4b9dfc66a4f47196cd4a6d3aa82d)
author | victory.bedrosova |
---|---|
date | Thu, 21 Jan 2021 12:01:07 +0100 |
parents | 2181ba80259c |
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.command; import jetbrains.buildServer.util.SimpleHttpServer; import jetbrains.buildServer.util.SimpleHttpServerBase; import jetbrains.buildServer.vcs.VcsException; import org.testng.annotations.Test; import java.io.IOException; import java.util.Collections; /** * @author dmitry.neverov */ @Test public class IdentifyCommandTest extends BaseCommandTestCase { public void should_throw_exception_if_cset_is_not_present() throws IOException { setRepository("mercurial-tests/testData/rep1", true); String nonExistingVersion = "1d446e82d355"; try { runIdentify(new ChangeSet(nonExistingVersion)); fail("Should throw exception for non-existing change set"); } catch (VcsException e) { assertTrue(true); } } public void should_not_throw_exception_if_cset_is_present() throws IOException { setRepository("mercurial-tests/testData/rep1", true); String nonExistingVersion = "1d446e82d356"; try { runIdentify(new ChangeSet(nonExistingVersion)); } catch (VcsException e) { fail("Should not throw an exception if change set is present"); } } public void should_escape_url_before_calling_command() throws IOException, VcsException { setRepository("mercurial-tests/testData/rep1", false); runCommand((root, hgPathProvider, workingDir) -> { MercurialCommandLine cli = new IdentifyCommand(new TestCommandSettingsFactory().create(), hgPathProvider.getHgPath(root), workingDir, root.getAuthSettings()) .repository("www.google.com `\"';") .withAuthSettings(new AuthSettings()) .createCL(); String commandLine = cli.toGeneralCommandLine().getCommandLineString(); assertTrue(commandLine, commandLine.contains("identify www.google.com%20%60%22%27%3B")); return null; }); } public void do_not_include_web_service_output_in_identify_command_error_message() throws IOException, VcsException { SimpleHttpServer httpServer = new SimpleHttpServer(); httpServer.setResponse(SimpleHttpServerBase.STATUS_LINE_200, Collections.singletonList("Content-type: text/html"), "Some response from web server"); httpServer.start(); final String url = "http://localhost:" + httpServer.getPort(); try { setRepository("mercurial-tests/testData/rep1", true); runCommand((root, hgPathProvider, workingDir) -> { new IdentifyCommand(new TestCommandSettingsFactory().create(), hgPathProvider.getHgPath(root), workingDir, root.getAuthSettings()) .repository(url) .withAuthSettings(new AuthSettings()) .call(); return null; }); fail("VcsException expected"); } catch (VcsException e) { assertFalse(e.getMessage().contains("Some response from web server")); System.out.println(e.getMessage()); } finally { httpServer.stop(); } } private void runIdentify(final ChangeSet cset) throws IOException, VcsException { runCommand((root, hgPathProvider, workingDir) -> { new IdentifyCommand(new TestCommandSettingsFactory().create(), hgPathProvider.getHgPath(root), workingDir, root.getAuthSettings()) .revision(cset) .inLocalRepository() .call(); return null; }); } }