Search in sources :

Example 6 with OptionsBuilder

use of com.google.copybara.testing.OptionsBuilder in project copybara by google.

the class GerritOriginTest method setup.

@Before
public void setup() throws Exception {
    options = new OptionsBuilder();
    TestingConsole console = new TestingConsole();
    options = new OptionsBuilder().setConsole(console).setOutputRootToTmpDir();
    SkylarkTestExecutor skylark = new SkylarkTestExecutor(options, GitModule.class);
    // Pass custom HOME directory so that we run an hermetic test and we
    // can add custom configuration to $HOME/.gitconfig.
    Path userHomeForTest = Files.createTempDirectory("home");
    options.setEnvironment(GitTestUtil.getGitEnv());
    options.setHomeDir(userHomeForTest.toString());
    createTestRepo(Files.createTempDirectory("remote"));
    String url = "file://" + remote.toFile().getAbsolutePath();
    origin = skylark.eval("result", String.format("result = " + "git.gerrit_origin(" + "    url = '%s'," + ")", url));
    Files.write(remote.resolve("base.txt"), new byte[0]);
    repo.add().files("base.txt").run();
    git("commit", "-m", "baseline", "--date", commitTime);
    baseline = repo.parseRef("HEAD");
    Files.write(remote.resolve("test.txt"), "some content".getBytes());
    repo.add().files("test.txt").run();
    git("commit", "-m", "first change", "--date", commitTime);
    firstRevision = new GitRevision(repo, repo.parseRef("HEAD"), GitRepoType.gerritPatchSetAsReviewReference(1), "12345", ImmutableMap.of(GERRIT_CHANGE_NUMBER_LABEL, "12345", GERRIT_CHANGE_ID_LABEL, CHANGE_ID, GERRIT_CHANGE_DESCRIPTION_LABEL, CHANGE_DESCRIPTION, DEFAULT_INTEGRATE_LABEL, "gerrit " + url + " 12345 Patch Set 1 " + CHANGE_ID), url);
    git("update-ref", "refs/changes/45/12345/1", firstRevision.getSha1());
    git("commit", "-m", "second change", "--date", commitTime, "--amend");
    secondRevision = new GitRevision(repo, repo.parseRef("HEAD"), GitRepoType.gerritPatchSetAsReviewReference(2), "12345", ImmutableMap.of(GERRIT_CHANGE_NUMBER_LABEL, "12345", GERRIT_CHANGE_ID_LABEL, CHANGE_ID, GERRIT_CHANGE_DESCRIPTION_LABEL, CHANGE_DESCRIPTION, DEFAULT_INTEGRATE_LABEL, "gerrit " + url + " 12345 Patch Set 2 " + CHANGE_ID), url);
    git("update-ref", "refs/changes/45/12345/2", secondRevision.getSha1());
    git("commit", "-m", "third change", "--date", commitTime, "--amend");
    thirdRevision = new GitRevision(repo, repo.parseRef("HEAD"), GitRepoType.gerritPatchSetAsReviewReference(3), "12345", ImmutableMap.of(GERRIT_CHANGE_NUMBER_LABEL, "12345", GERRIT_CHANGE_ID_LABEL, CHANGE_ID, GERRIT_CHANGE_DESCRIPTION_LABEL, CHANGE_DESCRIPTION, DEFAULT_INTEGRATE_LABEL, "gerrit " + url + " 12345 Patch Set 3 " + CHANGE_ID), url);
    git("update-ref", "refs/changes/45/12345/3", thirdRevision.getSha1());
    GitTestUtil.createFakeGerritNodeDbMeta(repo, 12345, CHANGE_ID);
}
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) Before(org.junit.Before)

Example 7 with OptionsBuilder

use of com.google.copybara.testing.OptionsBuilder 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 8 with OptionsBuilder

use of com.google.copybara.testing.OptionsBuilder in project copybara by google.

the class GerritApiTest method setUp.

@Before
public void setUp() throws Exception {
    OptionsBuilder options = new OptionsBuilder().setWorkdirToRealTempDir().setEnvironment(GitTestUtil.getGitEnv()).setOutputRootToTmpDir();
    credentialsFile = Files.createTempFile("credentials", "test");
    Files.write(credentialsFile, "https://user:SECRET@copybara-not-real.com".getBytes(UTF_8));
    GitRepository repo = newBareRepo(Files.createTempDirectory("test_repo"), getGitEnv(), /*verbose=*/
    true).init().withCredentialHelper("store --file=" + credentialsFile);
    httpTransport = new MockHttpTransport() {

        @Override
        public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
            String requestString = method + " " + url;
            MockLowLevelHttpRequest request = new MockLowLevelHttpRequest();
            MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
            request.setResponse(response);
            for (Entry<Predicate<String>, byte[]> entry : requestToResponse.entrySet()) {
                if (entry.getKey().test(requestString)) {
                    byte[] content = entry.getValue();
                    assertWithMessage("'" + method + " " + url + "'").that(content).isNotNull();
                    response.setContent(content);
                    return request;
                }
            }
            response.setStatusCode(404);
            response.setContent(("NO URL MATCHED! (Returning 404) REQUEST: " + requestString));
            return request;
        }
    };
    GerritOptions gerritOptions = new GerritOptions(() -> options.general, options.git) {

        @Override
        protected HttpTransport getHttpTransport() {
            return httpTransport;
        }

        @Override
        protected GitRepository getCredentialsRepo() throws RepoException {
            return repo;
        }
    };
    gerritApi = gerritOptions.newGerritApi(getHost() + "/foo/bar/baz");
}
Also used : GitRepository(com.google.copybara.git.GitRepository) Entry(java.util.Map.Entry) MockHttpTransport(com.google.api.client.testing.http.MockHttpTransport) MockLowLevelHttpResponse(com.google.api.client.testing.http.MockLowLevelHttpResponse) LowLevelHttpRequest(com.google.api.client.http.LowLevelHttpRequest) MockLowLevelHttpRequest(com.google.api.client.testing.http.MockLowLevelHttpRequest) GerritOptions(com.google.copybara.git.GerritOptions) IOException(java.io.IOException) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) MockLowLevelHttpRequest(com.google.api.client.testing.http.MockLowLevelHttpRequest) Before(org.junit.Before)

Example 9 with OptionsBuilder

use of com.google.copybara.testing.OptionsBuilder in project copybara by google.

the class PatchTransformationTest method setup.

@Before
public void setup() throws IOException {
    checkoutDir = Files.createTempDirectory("workdir");
    Files.createDirectories(checkoutDir);
    console = new TestingConsole();
    options = new OptionsBuilder().setConsole(console);
    general = options.build().get(GeneralOptions.class);
    skylark = new SkylarkTestExecutor(options, PatchModule.class);
    ImmutableMap<String, byte[]> configFiles = ImmutableMap.of("diff.patch", (DIFF).getBytes(UTF_8), "series", ("diff.patch\n").getBytes(UTF_8));
    patchFile = new MapConfigFile(configFiles, "diff.patch");
    seriesFile = new MapConfigFile(configFiles, "series");
    options.setEnvironment(GitTestUtil.getGitEnv());
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) GeneralOptions(com.google.copybara.GeneralOptions) MapConfigFile(com.google.copybara.config.MapConfigFile) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Before(org.junit.Before)

Example 10 with OptionsBuilder

use of com.google.copybara.testing.OptionsBuilder in project copybara by google.

the class CoreTransformTest method setup.

@Before
public void setup() throws IOException {
    FileSystem fs = Jimfs.newFileSystem();
    checkoutDir = fs.getPath("/test-checkoutDir");
    Files.createDirectories(checkoutDir);
    OptionsBuilder options = new OptionsBuilder();
    skylark = new SkylarkTestExecutor(options, Core.class);
    console = new TestingConsole();
    options.setConsole(console);
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) FileSystem(java.nio.file.FileSystem) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Before(org.junit.Before)

Aggregations

OptionsBuilder (com.google.copybara.testing.OptionsBuilder)34 Before (org.junit.Before)33 TestingConsole (com.google.copybara.util.console.testing.TestingConsole)28 SkylarkTestExecutor (com.google.copybara.testing.SkylarkTestExecutor)26 FileSystem (java.nio.file.FileSystem)7 Core (com.google.copybara.Core)5 SkylarkParser (com.google.copybara.config.SkylarkParser)5 DummyOrigin (com.google.copybara.testing.DummyOrigin)5 Path (java.nio.file.Path)5 Authoring (com.google.copybara.authoring.Authoring)4 RepoException (com.google.copybara.exception.RepoException)4 RecordsProcessCallDestination (com.google.copybara.testing.RecordsProcessCallDestination)4 TestGitOptions (com.google.copybara.testing.git.GitTestUtil.TestGitOptions)4 HttpTransport (com.google.api.client.http.HttpTransport)3 GitApiMockHttpTransport (com.google.copybara.testing.OptionsBuilder.GitApiMockHttpTransport)3 MockLowLevelHttpRequest (com.google.api.client.testing.http.MockLowLevelHttpRequest)2 GeneralOptions (com.google.copybara.GeneralOptions)2 GithubApi (com.google.copybara.git.github.api.GithubApi)2 TestingEventMonitor (com.google.copybara.testing.TestingEventMonitor)2 IOException (java.io.IOException)2