use of com.google.copybara.testing.DummyRevision in project copybara by google.
the class GitDestinationTest method processWithBaselineNotFoundMasterNotFound.
@Test
public void processWithBaselineNotFoundMasterNotFound() throws Exception {
fetch = "test_test_test";
push = "master";
Files.write(workdir.resolve("test.txt"), "more content".getBytes());
thrown.expect(RepoException.class);
thrown.expectMessage("Cannot find baseline 'I_dont_exist' and fetch reference 'test_test_test'");
processWithBaseline(firstCommitWriter(), new DummyRevision("origin_ref"), "I_dont_exist");
}
use of com.google.copybara.testing.DummyRevision in project copybara by google.
the class GithubPrDestinationTest method testDestinationStatus.
@Test
public void testDestinationStatus() throws ValidationException, IOException, RepoException {
options.githubDestination.createPullRequest = false;
gitApiMockHttpTransport = GitTestUtil.NO_GITHUB_API_CALLS;
GithubPrDestination d = skylark.eval("r", "r = git.github_pr_destination(" + " url = 'https://github.com/foo'" + ")");
Writer<GitRevision> writer = d.newWriter(Glob.ALL_FILES, /*dryRun=*/
false, "feature", /*oldWriter=*/
null);
GitRepository remote = localHubRepo("foo");
addFiles(remote, "master", "first change\n\nDummyOrigin-RevId: baseline", ImmutableMap.<String, String>builder().put("foo.txt", "").build());
DestinationStatus status = writer.getDestinationStatus("DummyOrigin-RevId");
assertThat(status.getBaseline()).isEqualTo("baseline");
assertThat(status.getPendingChanges()).isEmpty();
Files.write(this.workdir.resolve("test.txt"), "some content".getBytes());
writer.write(TransformResults.of(this.workdir, new DummyRevision("one")), console);
// New writer since after changes it keeps state internally for ITERATIVE mode
status = d.newWriter(Glob.ALL_FILES, /*dryRun=*/
false, "feature", /*oldWriter=*/
null).getDestinationStatus("DummyOrigin-RevId");
assertThat(status.getBaseline()).isEqualTo("baseline");
// Not supported for now as we rewrite the whole branch history.
assertThat(status.getPendingChanges()).isEmpty();
}
use of com.google.copybara.testing.DummyRevision in project copybara by google.
the class GithubPrDestinationTest method testCustomTitleAndBody.
@Test
public void testCustomTitleAndBody() throws ValidationException, IOException, RepoException {
options.githubDestination.destinationPrBranch = "feature";
gitApiMockHttpTransport = new GitApiMockHttpTransport() {
@Override
protected byte[] getContent(String method, String url, MockLowLevelHttpRequest request) throws IOException {
boolean isPulls = "https://api.github.com/repos/foo/pulls".equals(url);
if ("GET".equals(method) && isPulls) {
return "[]".getBytes(UTF_8);
} else if ("POST".equals(method) && isPulls) {
assertThat(request.getContentAsString()).isEqualTo("{\"base\":\"master\"," + "\"body\":\"custom body\"," + "\"head\":\"feature\"," + "\"title\":\"custom title\"}");
return ("{\n" + " \"id\": 1,\n" + " \"number\": 12345,\n" + " \"state\": \"open\",\n" + " \"title\": \"custom title\",\n" + " \"body\": \"custom body\"" + "}").getBytes();
}
fail(method + " " + url);
throw new IllegalStateException();
}
};
GithubPrDestination d = skylark.eval("r", "r = git.github_pr_destination(" + " url = 'https://github.com/foo', \n" + " title = 'custom title',\n" + " body = 'custom body',\n" + ")");
Writer<GitRevision> writer = d.newWriter(Glob.ALL_FILES, /*dryRun=*/
false, null, /*oldWriter=*/
null);
GitRepository remote = localHubRepo("foo");
addFiles(remote, null, "first change", ImmutableMap.<String, String>builder().put("foo.txt", "").build());
Files.write(this.workdir.resolve("test.txt"), "some content".getBytes());
writer.write(TransformResults.of(this.workdir, new DummyRevision("one")), console);
}
use of com.google.copybara.testing.DummyRevision in project copybara by google.
the class GerritDestinationTest method specifyTopic.
@Test
public void specifyTopic() throws Exception {
fetch = "master";
options.setForce(true);
Files.write(workdir.resolve("file"), "some content".getBytes());
options.gerrit.gerritTopic = "testTopic";
process(new DummyRevision("origin_ref"));
boolean correctMessage = console.getMessages().stream().anyMatch(message -> message.getText().contains("refs/for/master%topic=testTopic"));
assertThat(correctMessage).isTrue();
}
use of com.google.copybara.testing.DummyRevision in project copybara by google.
the class CopybaraTest method testInfoUpToDate.
@Test
public void testInfoUpToDate() throws Exception {
MigrationReference<DummyRevision> workflow = MigrationReference.create("workflow", new DummyRevision("1111"), ImmutableList.of());
Info<? extends Revision> mockedInfo = Info.create(ImmutableList.of(workflow));
Mockito.<Info<? extends Revision>>when(migration.getInfo()).thenReturn(mockedInfo);
Copybara copybara = new Copybara(new ConfigValidator() {
}, migration -> {
}, /*configLoaderProvider=*/
null);
copybara.info(optionsBuilder.build(), config, "workflow");
assertThat(eventMonitor.infoFinishedEvent).isNotNull();
assertThat(eventMonitor.infoFinishedEvent.getInfo()).isEqualTo(mockedInfo);
console.assertThat().onceInLog(MessageType.INFO, ".*last_migrated 1111 - last_available None.*");
}
Aggregations