Search in sources :

Example 6 with TestingConsole

use of com.google.copybara.util.console.testing.TestingConsole in project copybara by google.

the class WorkflowTest method testTestWorkflowWithDiffInOrigin.

@Test
public void testTestWorkflowWithDiffInOrigin() throws Exception {
    GitRepository remote = GitRepository.newBareRepo(Files.createTempDirectory("gitdir"), getGitEnv(), /*verbose=*/
    true, DEFAULT_TIMEOUT, /*noVerify=*/
    false).withWorkTree(workdir);
    remote.init();
    String primaryBranch = remote.getPrimaryBranch();
    Files.write(workdir.resolve("foo.txt"), new byte[] {});
    remote.add().files("foo.txt").run();
    remote.simpleCommand("commit", "foo.txt", "-m", "message_a");
    GitRevision lastRev = remote.resolveReference(primaryBranch);
    Files.write(workdir.resolve("bar.txt"), "change content".getBytes(UTF_8));
    remote.add().files("bar.txt").run();
    remote.simpleCommand("commit", "bar.txt", "-m", "message_s");
    TestingConsole testingConsole = new TestingConsole().respondYes();
    options.workflowOptions.lastRevision = lastRev.getSha1();
    options.setWorkdirToRealTempDir().setConsole(testingConsole).setHomeDir(StandardSystemProperty.USER_HOME.value());
    Workflow<?, ?> workflow = (Workflow<?, ?>) new SkylarkTestExecutor(options).loadConfig("core.workflow(\n" + "    name = 'foo',\n" + "    origin = git.origin(url='" + remote.getGitDir() + "',\n" + "                        ref = '" + primaryBranch + "'\n" + "    ),\n" + "    destination = folder.destination(),\n" + "    mode = 'ITERATIVE',\n" + "    authoring = " + authoring + ",\n" + "    transformations = [metadata.replace_message(''),],\n" + ")\n").getMigration("foo");
    workflow.getWorkflowOptions().diffInOrigin = true;
    workflow.run(workdir, ImmutableList.of(primaryBranch));
    testingConsole.assertThat().onceInLog(MessageType.WARNING, "Change 1 of 1 \\(.*\\)\\: Continue to migrate with '" + workflow.getMode() + "'" + " to " + workflow.getDestination().getType() + "\\?");
}
Also used : GitRepository(com.google.copybara.git.GitRepository) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) GitRevision(com.google.copybara.git.GitRevision) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Test(org.junit.Test)

Example 7 with TestingConsole

use of com.google.copybara.util.console.testing.TestingConsole in project copybara by google.

the class BuildozerBatchTest method setup.

@Before
public void setup() throws IOException {
    console = new TestingConsole();
    options = new OptionsBuilder();
    options.setConsole(console);
    BuildozerTesting.enable(options);
    checkoutDir = Files.createTempDirectory("BuildozerBatchTest-" + name.getMethodName());
    skylark = new SkylarkTestExecutor(options);
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Before(org.junit.Before)

Example 8 with TestingConsole

use of com.google.copybara.util.console.testing.TestingConsole in project copybara by google.

the class BuildozerDeleteTest method setup.

@Before
public void setup() throws Exception {
    console = new TestingConsole();
    options = new OptionsBuilder();
    options.setConsole(console);
    BuildozerTesting.enable(options);
    checkoutDir = Files.createTempDirectory("BuildozerDeleteTest");
    skylark = new SkylarkTestExecutor(options);
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Before(org.junit.Before)

Example 9 with TestingConsole

use of com.google.copybara.util.console.testing.TestingConsole in project copybara by google.

the class ApiCheckerTest method testCheckInternalError.

@Test
public void testCheckInternalError() throws CheckerException {
    ApiChecker checker = new ApiChecker(new FakeChecker() {

        @Override
        public void doCheck(ImmutableMap<String, String> fields, Console console) throws IOException {
            throw new IOException("Tool error!");
        }
    }, new TestingConsole());
    RuntimeException e1 = assertThrows(RuntimeException.class, () -> checker.check("foo", new Object()));
    assertThat(e1).hasMessageThat().isEqualTo("Error running checker");
    RuntimeException e2 = assertThrows(RuntimeException.class, () -> checker.check("foo", new Object(), "bar", new Object()));
    assertThat(e2).hasMessageThat().isEqualTo("Error running checker");
    RuntimeException e3 = assertThrows(RuntimeException.class, () -> checker.check("foo", new Object(), "bar", new Object(), "baz", new Object()));
    assertThat(e3).hasMessageThat().isEqualTo("Error running checker");
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) Console(com.google.copybara.util.console.Console) IOException(java.io.IOException) Test(org.junit.Test)

Example 10 with TestingConsole

use of com.google.copybara.util.console.testing.TestingConsole in project copybara by google.

the class ApiCheckerTest method testCheck.

@Test
public void testCheck() throws CheckerException {
    ApiChecker checker = new ApiChecker(new FakeChecker() {

        @Override
        public void doCheck(ImmutableMap<String, String> fields, Console console) {
        }
    }, new TestingConsole());
    checker.check("foo", new Object());
    checker.check("foo", new Object(), "bar", new Object());
    checker.check("foo", new Object(), "bar", new Object(), "baz", new Object());
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) Console(com.google.copybara.util.console.Console) Test(org.junit.Test)

Aggregations

TestingConsole (com.google.copybara.util.console.testing.TestingConsole)96 Before (org.junit.Before)57 OptionsBuilder (com.google.copybara.testing.OptionsBuilder)55 SkylarkTestExecutor (com.google.copybara.testing.SkylarkTestExecutor)54 Test (org.junit.Test)34 Path (java.nio.file.Path)15 GitTestUtil (com.google.copybara.testing.git.GitTestUtil)8 FileSystem (java.nio.file.FileSystem)8 IOException (java.io.IOException)7 LowLevelHttpRequest (com.google.api.client.http.LowLevelHttpRequest)6 DummyChecker (com.google.copybara.testing.DummyChecker)6 DummyOrigin (com.google.copybara.testing.DummyOrigin)6 Console (com.google.copybara.util.console.Console)6 MockHttpTransport (com.google.api.client.testing.http.MockHttpTransport)5 MockLowLevelHttpRequest (com.google.api.client.testing.http.MockLowLevelHttpRequest)5 MockLowLevelHttpResponse (com.google.api.client.testing.http.MockLowLevelHttpResponse)5 Truth.assertWithMessage (com.google.common.truth.Truth.assertWithMessage)5 GitRepository (com.google.copybara.git.GitRepository)5 LowLevelHttpResponse (com.google.api.client.http.LowLevelHttpResponse)4 RepoException (com.google.copybara.exception.RepoException)4