Search in sources :

Example 21 with SkylarkTestExecutor

use of com.google.copybara.testing.SkylarkTestExecutor 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");
    git("init", "--bare", repoGitDir.toString());
    console = new TestingConsole();
    options = new OptionsBuilder().setConsole(console).setForce(true).setOutputRootToTmpDir();
    gitUtil = new GitTestUtil(options);
    gitUtil.mockRemoteGitRepos(new CompleteRefValidator());
    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);
    primaryBranchMigration = "False";
}
Also used : Path(java.nio.file.Path) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) GitTestUtil(com.google.copybara.testing.git.GitTestUtil) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) CompleteRefValidator(com.google.copybara.testing.git.GitTestUtil.CompleteRefValidator) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Before(org.junit.Before)

Example 22 with SkylarkTestExecutor

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

the class GitHubPrDestinationTest method getWriterForTestEmptyDiff.

private Writer<GitRevision> getWriterForTestEmptyDiff() throws Exception {
    gitUtil = new GitTestUtil(options);
    gitUtil.mockRemoteGitRepos();
    options.gitDestination = new GitDestinationOptions(options.general, options.git);
    options.gitDestination.committerEmail = "commiter@email";
    options.gitDestination.committerName = "Bara Kopi";
    skylark = new SkylarkTestExecutor(options);
    options.githubDestination.destinationPrBranch = "test_feature";
    GitHubPrDestination d = skylark.eval("r", "r = git.github_pr_destination(" + "    url = 'https://github.com/foo', \n" + "    title = 'Title ${aaa}',\n" + "    body = 'Body ${aaa}',\n" + "    allow_empty_diff = False,\n" + "    destination_ref = 'main',\n" + "    pr_branch = 'test_${CONTEXT_REFERENCE}',\n" + "    primary_branch_migration = " + primaryBranchMigration + ",\n" + ")");
    WriterContext writerContext = new WriterContext("piper_to_github", "TEST", false, new DummyRevision("feature", "feature"), Glob.ALL_FILES.roots());
    return d.newWriter(writerContext);
}
Also used : WriterContext(com.google.copybara.WriterContext) DummyRevision(com.google.copybara.testing.DummyRevision) GitTestUtil(com.google.copybara.testing.git.GitTestUtil) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor)

Example 23 with SkylarkTestExecutor

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

the class GitHubEndpointTest method setup.

@Before
public void setup() throws Exception {
    workdir = Jimfs.newFileSystem().getPath("/");
    console = new TestingConsole();
    OptionsBuilder options = new OptionsBuilder();
    options.setConsole(console).setOutputRootToTmpDir();
    gitUtil = new GitTestUtil(options);
    gitUtil.mockRemoteGitRepos();
    dummyTrigger = new DummyTrigger();
    options.testingOptions.feedbackTrigger = dummyTrigger;
    options.testingOptions.checker = new DummyChecker(ImmutableSet.of("badword"));
    gitUtil.mockApi(eq("GET"), contains("master/status"), mockResponse("{\n" + "    state : 'failure',\n" + "    total_count : 2,\n" + "    sha : 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',\n" + "    statuses : [\n" + "       { state : 'failure', context: 'some/context'},\n" + "       { state : 'success', context: 'other/context'}\n" + "    ]\n" + "}"));
    gitUtil.mockApi(eq("GET"), contains("/commits/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), mockResponse("{\n" + "    sha : 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',\n" + "    commit : {\n" + "       author: { name : 'theauthor', email: 'author@example.com'},\n" + "       committer: { name : 'thecommitter', email: 'committer@example.com'},\n" + "       message: \"This is a message\\n\\nWith body\\n\"\n" + "    },\n" + "    committer : { login : 'github_committer'},\n" + "    author : { login : 'github_author'}\n" + "}"));
    gitUtil.mockApi(eq("POST"), contains("/statuses/e59774"), mockResponse("{\n" + "    state : 'success',\n" + "    target_url : 'https://github.com/google/example',\n" + "    description : 'Observed foo',\n" + "    context : 'test'\n" + "}"));
    gitUtil.mockApi(anyString(), contains("/git/refs/heads/test"), mockResponse("{\n" + "    ref : 'refs/heads/test',\n" + "    url : 'https://github.com/google/example/git/refs/heads/test',\n" + "    object : { \n" + "       type : 'commit',\n" + "       sha : 'e597746de9c1704e648ddc3ffa0d2096b146d600', \n" + "       url :" + " 'https://github.com/google/example/git/commits/e597746de9c1704e648ddc3ffa0d2096b146d600'\n" + "   } \n" + "}"));
    gitUtil.mockApi(eq("GET"), contains("git/refs?per_page=100"), mockResponse("[{\n" + "    ref : 'refs/heads/test',\n" + "    url : 'https://github.com/google/example/git/refs/heads/test',\n" + "    object : { \n" + "       type : 'commit',\n" + "       sha : 'e597746de9c1704e648ddc3ffa0d2096b146d600', \n" + "       url :" + " 'https://github.com/google/example/git/commits/e597746de9c1704e648ddc3ffa0d2096b146d600'\n" + "   } \n" + "}]"));
    gitUtil.mockApi(eq("GET"), contains("commits/e597746de9c1704e648ddc3ffa0d2096b146d610/check-runs"), mockResponse("{\n" + "  total_count: 1,\n" + "  check_runs: [\n" + "    {\n" + "      id: 4,\n" + "      details_url: 'https://example.com',\n" + "      status: 'completed',\n" + "      conclusion: 'neutral',\n" + "      name: 'mighty_readme',\n" + "      output: {\n" + "        title: 'Mighty Readme report',\n" + "        summary: 'test_summary',\n" + "        text: 'test_text'\n" + "      },\n" + "      app: {\n" + "        id: 1,\n" + "        slug: 'octoapp',\n" + "        name: 'Octocat App'\n" + "      }\n" + "    }\n" + "  ]\n" + "}"));
    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);
}
Also used : Path(java.nio.file.Path) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) DummyTrigger(com.google.copybara.testing.DummyTrigger) GitTestUtil(com.google.copybara.testing.git.GitTestUtil) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) DummyChecker(com.google.copybara.testing.DummyChecker) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Before(org.junit.Before)

Example 24 with SkylarkTestExecutor

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

the class GitHubTriggerTest method setup.

@Before
public void setup() throws Exception {
    TestingConsole console = new TestingConsole();
    OptionsBuilder options = new OptionsBuilder();
    options.setConsole(console).setOutputRootToTmpDir();
    options.testingOptions.checker = new DummyChecker(ImmutableSet.of("badword"));
    skylarkTestExecutor = new SkylarkTestExecutor(options);
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) DummyChecker(com.google.copybara.testing.DummyChecker) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Before(org.junit.Before)

Example 25 with SkylarkTestExecutor

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

the class GitOriginSubmodulesTest method setup.

@Before
public void setup() throws Exception {
    OptionsBuilder options = new OptionsBuilder().setConsole(new TestingConsole()).setOutputRootToTmpDir();
    skylark = new SkylarkTestExecutor(options);
    // 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.setHomeDir(userHomeForTest.toString());
    checkoutDir = Files.createTempDirectory("checkout");
}
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)

Aggregations

SkylarkTestExecutor (com.google.copybara.testing.SkylarkTestExecutor)70 OptionsBuilder (com.google.copybara.testing.OptionsBuilder)58 Before (org.junit.Before)58 TestingConsole (com.google.copybara.util.console.testing.TestingConsole)54 Path (java.nio.file.Path)17 Test (org.junit.Test)14 GitTestUtil (com.google.copybara.testing.git.GitTestUtil)9 DummyOrigin (com.google.copybara.testing.DummyOrigin)8 ValidationException (com.google.copybara.exception.ValidationException)7 FileSystem (java.nio.file.FileSystem)7 DummyChecker (com.google.copybara.testing.DummyChecker)6 RecordsProcessCallDestination (com.google.copybara.testing.RecordsProcessCallDestination)6 MapConfigFile (com.google.copybara.config.MapConfigFile)4 RepoException (com.google.copybara.exception.RepoException)4 Console (com.google.copybara.util.console.Console)4 IOException (java.io.IOException)4 LowLevelHttpRequest (com.google.api.client.http.LowLevelHttpRequest)3 ImmutableList (com.google.common.collect.ImmutableList)3 Truth.assertThat (com.google.common.truth.Truth.assertThat)3 DummyRevision (com.google.copybara.testing.DummyRevision)3