Search in sources :

Example 6 with DummyChecker

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

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

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

the class GerritDestinationTest method testChecker.

@Test
public void testChecker() throws Exception {
    options.gerrit.gerritChangeId = null;
    fetch = "master";
    pushToRefsFor = "master";
    writeFile(workdir, "file", "BAD");
    options.setForce(true);
    url = "https://localhost:33333/foo/bar";
    GitRepository repo = gitUtil.mockRemoteRepo("localhost:33333/foo/bar");
    mockNoChangesFound();
    DummyRevision originRef = new DummyRevision("origin_ref");
    options.testingOptions.checker = new DummyChecker(ImmutableSet.of("BAD"));
    GerritDestination destination = destination("submit = True, checker = testing.dummy_checker()");
    Glob glob = Glob.createGlob(ImmutableList.of("**"), excludedDestinationPaths);
    WriterContext writerContext = new WriterContext("GerritDestinationTest", "test", false, originRef, Glob.ALL_FILES.roots());
    assertThat(assertThrows(CheckerException.class, () -> destination.newWriter(writerContext).write(TransformResults.of(workdir, originRef).withSummary("Test message").withIdentity(originRef.asString()), glob, console))).hasMessageThat().contains("Bad word 'bad' found");
}
Also used : WriterContext(com.google.copybara.WriterContext) CheckerException(com.google.copybara.checks.CheckerException) DummyRevision(com.google.copybara.testing.DummyRevision) Glob(com.google.copybara.util.Glob) DummyChecker(com.google.copybara.testing.DummyChecker) Test(org.junit.Test)

Example 9 with DummyChecker

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

the class GerritEndpointTest method setup.

@Before
public void setup() throws Exception {
    workdir = Jimfs.newFileSystem().getPath("/");
    TestingConsole console = new TestingConsole();
    OptionsBuilder options = new OptionsBuilder();
    options.setConsole(console).setOutputRootToTmpDir();
    dummyTrigger = new DummyTrigger();
    options.testingOptions.feedbackTrigger = dummyTrigger;
    options.testingOptions.checker = new DummyChecker(ImmutableSet.of("badword"));
    gitUtil = new GitTestUtil(options);
    Path credentialsFile = Files.createTempFile("credentials", "test");
    Files.write(credentialsFile, BASE_URL.getBytes(UTF_8));
    GitRepository repo = newBareRepo(Files.createTempDirectory("test_repo"), getGitEnv(), /*verbose=*/
    true, DEFAULT_TIMEOUT, /*noVerify=*/
    false).init().withCredentialHelper("store --file=" + credentialsFile);
    gitUtil.mockRemoteGitRepos(new Validator(), repo);
    url = BASE_URL + "/foo/bar";
    options.general.starlarkMode = "STRICT";
    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) Validator(com.google.copybara.testing.git.GitTestUtil.Validator) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Before(org.junit.Before)

Example 10 with DummyChecker

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

the class GitDestinationTest method testCheckerDescription_label_leak_is_fine.

@Test
public void testCheckerDescription_label_leak_is_fine() throws Exception {
    runDescriptionChecker(new DummyChecker(ImmutableSet.of(DummyOrigin.LABEL_NAME)));
    ImmutableList<GitLogEntry> head = repo().log(primaryBranch).withLimit(1).run();
    assertThat(head).isNotEmpty();
    assertThat(head.get(0).getBody()).isEqualTo("This is BAD\n\nDummyOrigin-RevId: ref2\n");
    assertThat(head.get(0).getAuthor()).isEqualTo(new Author("Dont", "rewri@te.me"));
}
Also used : Author(com.google.copybara.authoring.Author) DummyChecker(com.google.copybara.testing.DummyChecker) GitLogEntry(com.google.copybara.git.GitRepository.GitLogEntry) Test(org.junit.Test)

Aggregations

DummyChecker (com.google.copybara.testing.DummyChecker)11 Test (org.junit.Test)6 OptionsBuilder (com.google.copybara.testing.OptionsBuilder)5 SkylarkTestExecutor (com.google.copybara.testing.SkylarkTestExecutor)5 TestingConsole (com.google.copybara.util.console.testing.TestingConsole)5 Before (org.junit.Before)5 Author (com.google.copybara.authoring.Author)3 CheckerException (com.google.copybara.checks.CheckerException)3 DummyRevision (com.google.copybara.testing.DummyRevision)3 GitTestUtil (com.google.copybara.testing.git.GitTestUtil)3 Path (java.nio.file.Path)3 WriterContext (com.google.copybara.WriterContext)2 GitLogEntry (com.google.copybara.git.GitRepository.GitLogEntry)2 DummyTrigger (com.google.copybara.testing.DummyTrigger)2 Change (com.google.copybara.Change)1 Changes (com.google.copybara.Changes)1 DestinationEffect (com.google.copybara.DestinationEffect)1 TransformResult (com.google.copybara.TransformResult)1 CompleteRefValidator (com.google.copybara.testing.git.GitTestUtil.CompleteRefValidator)1 Validator (com.google.copybara.testing.git.GitTestUtil.Validator)1