Search in sources :

Example 71 with TestingConsole

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

the class GitOriginSubmodulesTest method testRewriteUrl.

@Test
public void testRewriteUrl() throws Exception {
    Path base = Files.createTempDirectory("testRewriteUrl");
    GitRepository r1 = createRepoWithFoo(base, "r1");
    GitRepository r2 = createRepoWithFoo(base, "r2");
    GitRepository r3 = GitRepository.newBareRepo(base.resolve("testRewriteUrl").resolve("r3"), getGitEnv(), false, Duration.ofMinutes(1), false).init();
    r3.fetch("file://" + r1.getGitDir(), false, true, ImmutableList.of("refs/heads/*:refs/heads/*"), false);
    String primaryBranch = r2.getPrimaryBranch();
    OptionsBuilder options = new OptionsBuilder().setConsole(new TestingConsole()).setOutputRootToTmpDir();
    options.git = new GitOptions(options.general) {

        @Override
        public String rewriteSubmoduleUrl(String url) {
            return r3.getGitDir().toString();
        }
    };
    skylark = new SkylarkTestExecutor(options);
    r2.simpleCommand("submodule", "add", "-f", "--name", "r1", "file://" + r1.getWorkTree(), "r1");
    commit(r2, "adding r3->r1 submodule");
    // Nuke r1 to verify r3 is read
    MoreFiles.deleteRecursively(r1.getGitDir());
    GitOrigin origin = origin("file://" + r2.getGitDir(), primaryBranch);
    GitRevision main = origin.resolve(primaryBranch);
    origin.newReader(Glob.ALL_FILES, authoring).checkout(main, checkoutDir);
    FileSubjects.assertThatPath(checkoutDir).containsFiles(GITMODULES).containsFile("r1/foo", "1");
}
Also used : Path(java.nio.file.Path) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Test(org.junit.Test)

Example 72 with TestingConsole

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

the class SubmodulesInDestinationTest method setup.

@Before
public void setup() throws Exception {
    repoGitDir = Files.createTempDirectory("SubmodulesInDestinationTest-repoGitDir");
    workdir = Files.createTempDirectory("workdir");
    git("init", "--bare", repoGitDir.toString());
    console = new TestingConsole();
    options = new OptionsBuilder().setConsole(console).setOutputRootToTmpDir();
    options.gitDestination.committerEmail = "commiter@email";
    options.gitDestination.committerName = "Bara Kopi";
    destinationFiles = Glob.createGlob(ImmutableList.of("**"));
    url = "file://" + repoGitDir;
    skylark = new SkylarkTestExecutor(options);
    submodule = GitRepository.newBareRepo(Files.createTempDirectory("gitdir"), getGitEnv(), /*verbose=*/
    true, DEFAULT_TIMEOUT, /*noVerify=*/
    false).withWorkTree(Files.createTempDirectory("worktree")).init();
    primaryBranch = submodule.getPrimaryBranch();
    Files.write(submodule.getWorkTree().resolve("foo"), new byte[] { 1 });
    submodule.add().files("foo").run();
    submodule.simpleCommand("commit", "-m", "dummy commit");
}
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 73 with TestingConsole

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

the class GerritApiTransportWithCheckerTest method setup.

@Before
public void setup() throws Exception {
    console = new TestingConsole();
    delegate = Mockito.mock(GerritApiTransport.class);
    checker = Mockito.mock(Checker.class);
    transport = new GerritApiTransportWithChecker(delegate, new ApiChecker(checker, console));
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) Checker(com.google.copybara.checks.Checker) ApiChecker(com.google.copybara.checks.ApiChecker) ApiChecker(com.google.copybara.checks.ApiChecker) Before(org.junit.Before)

Example 74 with TestingConsole

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

the class GitHubApiTransportImplTest method runTestThrowsHttpResponseException.

private void runTestThrowsHttpResponseException(Callable<?> c) throws Exception {
    HttpResponseException ex = new HttpResponseException.Builder(STATUS_CODE, ERROR_MESSAGE, new HttpHeaders()).build();
    httpTransport = createMockHttpTransport(ex);
    transport = new GitHubApiTransportImpl(repo, httpTransport, "store", new TestingConsole());
    try {
        c.call();
        fail();
    } catch (GitHubApiException e) {
        assertThat(e.getHttpCode()).isEqualTo(STATUS_CODE);
        assertThat(e.getError()).isNull();
    }
}
Also used : HttpHeaders(com.google.api.client.http.HttpHeaders) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) HttpResponseException(com.google.api.client.http.HttpResponseException)

Example 75 with TestingConsole

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

the class GitHubApiTransportImplTest method runTestThrowsIOException.

private void runTestThrowsIOException(Callable<?> c) throws Exception {
    IOException ioException = new IOException();
    httpTransport = createMockHttpTransport(ioException);
    transport = new GitHubApiTransportImpl(repo, httpTransport, "store", new TestingConsole());
    try {
        c.call();
        fail();
    } catch (RepoException e) {
        assertThat(e.getCause()).isEqualTo(ioException);
    }
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) IOException(java.io.IOException) RepoException(com.google.copybara.exception.RepoException)

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