Search in sources :

Example 46 with TestingConsole

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

the class FileConsoleTest method testShutDownCase.

@Test
public void testShutDownCase() throws Exception {
    TestingConsole delegate = new TestingConsole();
    FileConsole fileConsole = new FileConsole(delegate, file, Duration.ofSeconds(2));
    ExecutorService exec = Executors.newFixedThreadPool(2);
    Future<?> f1 = exec.submit(() -> {
        Thread.sleep(1000);
        fileConsole.close();
        return null;
    });
    Future<?> f2 = exec.submit(() -> {
        fileConsole.info("This is info");
        Thread.sleep(2000);
        fileConsole.warn("This is warning");
        return null;
    });
    f1.get();
    f2.get();
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) ExecutorService(java.util.concurrent.ExecutorService) Test(org.junit.Test)

Example 47 with TestingConsole

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

the class FileConsoleTest method runTest.

private void runTest(Path file) throws IOException {
    TestingConsole delegate = new TestingConsole();
    try (FileConsole fileConsole = new FileConsole(delegate, file, Duration.ZERO)) {
        fileConsole.startupMessage("v1");
        fileConsole.info("This is info");
        fileConsole.warn("This is warning");
        fileConsole.error("This is error");
        fileConsole.verbose("This is verbose");
        fileConsole.progress("This is progress");
    }
    List<String> lines = Files.readAllLines(file);
    assertThat(lines).hasSize(6);
    assertThat(lines.get(0)).contains("INFO: Copybara source mover (Version: v1)");
    assertThat(lines.get(1)).contains("INFO: This is info");
    assertThat(lines.get(2)).contains("WARNING: This is warning");
    assertThat(lines.get(3)).contains("ERROR: This is error");
    assertThat(lines.get(4)).contains("VERBOSE: This is verbose");
    assertThat(lines.get(5)).contains("PROGRESS: This is progress");
    delegate.assertThat().matchesNext(MessageType.INFO, "Copybara source mover [(]Version: v1[)]").matchesNext(MessageType.INFO, "This is info").matchesNext(MessageType.WARNING, "This is warning").matchesNext(MessageType.ERROR, "This is error").matchesNext(MessageType.VERBOSE, "This is verbose").matchesNext(MessageType.PROGRESS, "This is progress");
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole)

Example 48 with TestingConsole

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

the class FileConsoleTest method testFlushingFrequency_disabled.

@Test
public void testFlushingFrequency_disabled() throws Exception {
    TestingConsole delegate = new TestingConsole();
    try (FileConsole fileConsole = new FileConsole(delegate, file, Duration.ZERO)) {
        fileConsole.startupMessage("v1");
        fileConsole.info("This is info");
        fileConsole.warn("This is warning");
        fileConsole.error("This is error");
        fileConsole.verbose("This is verbose");
        fileConsole.progress("This is progress");
        assertThat(Files.readAllLines(file)).isEmpty();
    }
    List<String> lines = Files.readAllLines(file);
    assertThat(lines).hasSize(6);
    assertThat(lines.get(0)).contains("INFO: Copybara source mover (Version: v1)");
    assertThat(lines.get(1)).contains("INFO: This is info");
    assertThat(lines.get(2)).contains("WARNING: This is warning");
    assertThat(lines.get(3)).contains("ERROR: This is error");
    assertThat(lines.get(4)).contains("VERBOSE: This is verbose");
    assertThat(lines.get(5)).contains("PROGRESS: This is progress");
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) Test(org.junit.Test)

Example 49 with TestingConsole

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

the class FileConsoleTest method testFlushingFrequency.

@Test
public void testFlushingFrequency() throws Exception {
    TestingConsole delegate = new TestingConsole();
    try (FileConsole fileConsole = new FileConsole(delegate, file, Duration.ofSeconds(2))) {
        fileConsole.startupMessage("v1");
        fileConsole.info("This is info");
        fileConsole.warn("This is warning");
        assertThat(Files.readAllLines(file)).isEmpty();
        Thread.sleep(3000);
        fileConsole.error("This is error");
        fileConsole.verbose("This is verbose");
        List<String> lines = Files.readAllLines(file);
        assertThat(lines).hasSize(3);
        assertThat(lines.get(0)).contains("INFO: Copybara source mover (Version: v1)");
        assertThat(lines.get(1)).contains("INFO: This is info");
        assertThat(lines.get(2)).contains("WARNING: This is warning");
        fileConsole.progress("This is progress");
    }
    List<String> lines = Files.readAllLines(file);
    assertThat(lines).hasSize(6);
    assertThat(lines.get(0)).contains("INFO: Copybara source mover (Version: v1)");
    assertThat(lines.get(1)).contains("INFO: This is info");
    assertThat(lines.get(2)).contains("WARNING: This is warning");
    assertThat(lines.get(3)).contains("ERROR: This is error");
    assertThat(lines.get(4)).contains("VERBOSE: This is verbose");
    assertThat(lines.get(5)).contains("PROGRESS: This is progress");
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) Test(org.junit.Test)

Example 50 with TestingConsole

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

the class GithubPrOriginTest method setup.

@Before
public void setup() throws Exception {
    repoGitDir = Files.createTempDirectory("GithubPrDestinationTest-repoGitDir");
    workdir = Files.createTempDirectory("workdir");
    localHub = Files.createTempDirectory("localHub");
    git("init", "--bare", repoGitDir.toString());
    console = new TestingConsole();
    options = new OptionsBuilder().setConsole(console).setOutputRootToTmpDir();
    options.git = new TestGitOptions(localHub, () -> this.options.general, new Validator() {

        @Override
        public void validateFetch(String url, boolean prune, boolean force, Iterable<String> refspecs) {
            for (String refspec : refspecs) {
                // WARNING! This check is important. While using short names like
                // 'master' in git fetch works for local git invocations, other
                // implementations of GitRepository might have problems if we don't
                // pass the whole reference.
                assertThat(refspec).startsWith("refs/");
                assertThat(refspec).contains(":refs/");
            }
        }
    });
    options.github = new GithubOptions(() -> options.general, options.git) {

        @Override
        public GithubApi getApi(String project) throws RepoException {
            assertThat(project).isEqualTo(expectedProject);
            return super.getApi(project);
        }

        @Override
        protected HttpTransport getHttpTransport() {
            return gitApiMockHttpTransport;
        }
    };
    Path credentialsFile = Files.createTempFile("credentials", "test");
    Files.write(credentialsFile, "https://user:SECRET@github.com".getBytes(UTF_8));
    options.git.credentialHelperStorePath = credentialsFile.toString();
    skylark = new SkylarkTestExecutor(options, GitModule.class);
    skylarkParser = new SkylarkParser(ImmutableSet.of(Core.class, Authoring.Module.class, FolderModule.class, GitModule.class));
}
Also used : Path(java.nio.file.Path) SkylarkParser(com.google.copybara.config.SkylarkParser) TestGitOptions(com.google.copybara.testing.git.GitTestUtil.TestGitOptions) GithubApi(com.google.copybara.git.github.api.GithubApi) RepoException(com.google.copybara.exception.RepoException) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) HttpTransport(com.google.api.client.http.HttpTransport) GitApiMockHttpTransport(com.google.copybara.testing.OptionsBuilder.GitApiMockHttpTransport) Authoring(com.google.copybara.authoring.Authoring) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) Validator(com.google.copybara.testing.git.GitTestUtil.Validator) Before(org.junit.Before)

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