Search in sources :

Example 56 with TestingConsole

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

the class FeedbackTest method setup.

@Before
public void setup() throws Exception {
    workdir = Jimfs.newFileSystem().getPath("/");
    console = new TestingConsole(/*verbose=*/
    false);
    eventMonitor = new TestingEventMonitor();
    options = new OptionsBuilder();
    options.setConsole(console);
    options.general.enableEventMonitor("justTesting", eventMonitor);
    dummyTrigger = new DummyTrigger();
    options.testingOptions.feedbackTrigger = dummyTrigger;
    skylark = new SkylarkTestExecutor(options);
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) DummyTrigger(com.google.copybara.testing.DummyTrigger) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) TestingEventMonitor(com.google.copybara.testing.TestingEventMonitor) Before(org.junit.Before)

Example 57 with TestingConsole

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

the class WorkflowTest method setup.

@Before
public void setup() throws Exception {
    options = new OptionsBuilder();
    options.setOutputRootToTmpDir();
    authoring = "authoring.overwrite('" + DEFAULT_AUTHOR + "')";
    includeReleaseNotes = false;
    workdir = Files.createTempDirectory("workdir");
    Files.createDirectories(workdir);
    origin = new DummyOrigin().setAuthor(ORIGINAL_AUTHOR);
    originFiles = "glob(['**'], exclude = ['copy.bara.sky', 'excluded/**'])";
    destinationFiles = "glob(['**'])";
    destination = new RecordsProcessCallDestination();
    transformations = ImmutableList.of("" + "        core.replace(\n" + "             before = '${linestart}${number}',\n" + "             after = '${linestart}" + PREFIX + "${number}',\n" + "             regex_groups = {\n" + "                 'number'    : '[0-9]+',\n" + "                 'linestart' : '^',\n" + "             },\n" + "             multiline = True," + "        )");
    TestingConsole console = new TestingConsole();
    options.setConsole(console);
    options.testingOptions.origin = origin;
    options.testingOptions.destination = destination;
    // Force by default unless we are testing the flag.
    options.setForce(true);
    skylark = new SkylarkTestExecutor(options);
    eventMonitor = new TestingEventMonitor();
    options.general.enableEventMonitor("test", eventMonitor);
    transformWork = TransformWorks.of(workdir, "example", console);
    setRevId = true;
    smartPrune = false;
    migrateNoopChangesField = false;
    extraWorkflowFields = ImmutableList.of();
}
Also used : RecordsProcessCallDestination(com.google.copybara.testing.RecordsProcessCallDestination) DummyOrigin(com.google.copybara.testing.DummyOrigin) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) TestingEventMonitor(com.google.copybara.testing.TestingEventMonitor) Before(org.junit.Before)

Example 58 with TestingConsole

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

the class WorkflowTest method testTestWorkflowWithDiffInOriginAndRespondNo.

@Test
public void testTestWorkflowWithDiffInOriginAndRespondNo() 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().respondNo();
    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" + "    destination = folder.destination(),\n" + "    mode = 'ITERATIVE',\n" + "    authoring = " + authoring + ",\n" + "    transformations = [metadata.replace_message(''),],\n" + ")\n").getMigration("foo");
    workflow.getWorkflowOptions().diffInOrigin = true;
    ChangeRejectedException e = assertThrows(ChangeRejectedException.class, () -> workflow.run(workdir, ImmutableList.of(primaryBranch)));
    assertThat(e.getMessage()).contains("User aborted execution: did not confirm diff in origin changes.");
}
Also used : GitRepository(com.google.copybara.git.GitRepository) ChangeRejectedException(com.google.copybara.exception.ChangeRejectedException) 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 59 with TestingConsole

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

the class WorkflowTest method testWorkflowWithEmptyDiffInOrigin.

@Test
public void testWorkflowWithEmptyDiffInOrigin() 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("foo.txt"), "change content".getBytes(UTF_8));
    remote.add().files("foo.txt").run();
    remote.simpleCommand("commit", "foo.txt", "-m", "message_a");
    Files.write(workdir.resolve("foo.txt"), new byte[] {});
    remote.add().files("foo.txt").run();
    remote.simpleCommand("commit", "foo.txt", "-m", "message_a");
    TestingConsole testingConsole = new TestingConsole().respondYes();
    options.workflowOptions.lastRevision = lastRev.getSha1();
    options.general.force = false;
    options.setWorkdirToRealTempDir().setConsole(testingConsole).setHomeDir(StandardSystemProperty.USER_HOME.value());
    Workflow<?, ?> workflow = (Workflow<?, ?>) new SkylarkTestExecutor(options).loadConfig("core.workflow(\n" + "    name = 'foo',\n" + String.format("    origin = git.origin(url='%s', ref='%s'),\n", remote.getGitDir(), primaryBranch) + "    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, ".*No difference at diff_in_origin.*");
}
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 60 with TestingConsole

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

the class ApiCheckerTest method testCheckError.

@Test
public void testCheckError() {
    ApiChecker checker = new ApiChecker(new FakeChecker() {

        @Override
        public void doCheck(ImmutableMap<String, String> fields, Console console) throws CheckerException {
            throw new CheckerException("Check failed!");
        }
    }, new TestingConsole());
    ValidationException e = assertThrows(ValidationException.class, () -> checker.check("foo", new Object()));
    assertThat(e).hasMessageThat().isEqualTo("Check failed!");
    ValidationException failedCheck = assertThrows(ValidationException.class, () -> checker.check("foo", new Object(), "bar", new Object()));
    assertThat(failedCheck).hasMessageThat().isEqualTo("Check failed!");
    ValidationException failedCheckArgs = assertThrows(ValidationException.class, () -> checker.check("foo", new Object(), "bar", new Object(), "baz", new Object()));
    assertThat(failedCheckArgs).hasMessageThat().isEqualTo("Check failed!");
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) ValidationException(com.google.copybara.exception.ValidationException) 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