Search in sources :

Example 1 with TestGitOptions

use of com.google.copybara.testing.git.GitTestUtil.TestGitOptions in project copybara by google.

the class GithubPrDestinationTest 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, () -> GithubPrDestinationTest.this.options.general);
    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();
    options.gitDestination = new GitDestinationOptions(() -> options.general, options.git);
    options.gitDestination.committerEmail = "commiter@email";
    options.gitDestination.committerName = "Bara Kopi";
    skylark = new SkylarkTestExecutor(options, GitModule.class);
}
Also used : Path(java.nio.file.Path) 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) GitApiMockHttpTransport(com.google.copybara.testing.OptionsBuilder.GitApiMockHttpTransport) HttpTransport(com.google.api.client.http.HttpTransport) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) Before(org.junit.Before)

Example 2 with TestGitOptions

use of com.google.copybara.testing.git.GitTestUtil.TestGitOptions in project copybara by google.

the class GerritDestinationTest method setup.

@Before
public void setup() throws Exception {
    workdir = Files.createTempDirectory("workdir");
    console = new TestingConsole();
    options = new OptionsBuilder().setConsole(console).setOutputRootToTmpDir();
    urlMapper = Files.createTempDirectory("url_mapper");
    options.git = new TestGitOptions(urlMapper, () -> options.general);
    options.gerrit = new GerritOptions(() -> options.general, options.git) {

        @Override
        protected GerritApiTransportImpl getGerritApiTransport(URI uri) throws RepoException {
            return new GerritApiTransportImpl(repo(), uri, gitApiMockHttpTransport);
        }
    };
    options.gitDestination = new GitDestinationOptions(() -> options.general, options.git);
    options.gitDestination.committerEmail = "commiter@email";
    options.gitDestination.committerName = "Bara Kopi";
    excludedDestinationPaths = ImmutableList.of();
    repoGitDir = localGerritRepo("localhost:33333/foo/bar").getGitDir();
    url = "https://localhost:33333/foo/bar";
    repo().init();
    skylark = new SkylarkTestExecutor(options, GitModule.class);
    gitApiMockHttpTransport = new GitApiMockHttpTransport() {

        @Override
        protected byte[] getContent(String method, String url, MockLowLevelHttpRequest request) throws IOException {
            if (method.equals("GET") && url.startsWith("https://localhost:33333/changes/")) {
                String result = "[" + "{" + "  change_id : \"" + changeIdFromRequest(url) + "\"," + "  status : \"NEW\"" + "}]";
                return result.getBytes(UTF_8);
            }
            throw new IllegalArgumentException(method + " " + url);
        }
    };
}
Also used : TestGitOptions(com.google.copybara.testing.git.GitTestUtil.TestGitOptions) RepoException(com.google.copybara.exception.RepoException) IOException(java.io.IOException) URI(java.net.URI) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) MockLowLevelHttpRequest(com.google.api.client.testing.http.MockLowLevelHttpRequest) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) GerritApiTransportImpl(com.google.copybara.git.gerritapi.GerritApiTransportImpl) GitApiMockHttpTransport(com.google.copybara.testing.OptionsBuilder.GitApiMockHttpTransport) Before(org.junit.Before)

Example 3 with TestGitOptions

use of com.google.copybara.testing.git.GitTestUtil.TestGitOptions in project copybara by google.

the class GitDestinationIntegrateTest method setup.

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

        @Override
        protected HttpTransport getHttpTransport() {
            return GitTestUtil.NO_GITHUB_API_CALLS;
        }
    };
    options.gitDestination = new GitDestinationOptions(() -> options.general, options.git);
    options.gitDestination.committerEmail = "commiter@email";
    options.gitDestination.committerName = "Bara Kopi";
    destinationFiles = Glob.createGlob(ImmutableList.of("**"), ImmutableList.of("ignore*"));
    options.setForce(true);
    url = "file://" + repoGitDir;
    skylark = new SkylarkTestExecutor(options, GitModule.class);
}
Also used : HttpTransport(com.google.api.client.http.HttpTransport) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) TestGitOptions(com.google.copybara.testing.git.GitTestUtil.TestGitOptions) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Before(org.junit.Before)

Example 4 with TestGitOptions

use of com.google.copybara.testing.git.GitTestUtil.TestGitOptions 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

OptionsBuilder (com.google.copybara.testing.OptionsBuilder)4 SkylarkTestExecutor (com.google.copybara.testing.SkylarkTestExecutor)4 TestGitOptions (com.google.copybara.testing.git.GitTestUtil.TestGitOptions)4 TestingConsole (com.google.copybara.util.console.testing.TestingConsole)4 Before (org.junit.Before)4 HttpTransport (com.google.api.client.http.HttpTransport)3 RepoException (com.google.copybara.exception.RepoException)3 GitApiMockHttpTransport (com.google.copybara.testing.OptionsBuilder.GitApiMockHttpTransport)3 GithubApi (com.google.copybara.git.github.api.GithubApi)2 Path (java.nio.file.Path)2 MockLowLevelHttpRequest (com.google.api.client.testing.http.MockLowLevelHttpRequest)1 Authoring (com.google.copybara.authoring.Authoring)1 SkylarkParser (com.google.copybara.config.SkylarkParser)1 GerritApiTransportImpl (com.google.copybara.git.gerritapi.GerritApiTransportImpl)1 Validator (com.google.copybara.testing.git.GitTestUtil.Validator)1 IOException (java.io.IOException)1 URI (java.net.URI)1