use of com.google.copybara.testing.DummyRevision in project copybara by google.
the class GithubPrDestinationTest method testWriteNoMaster.
@Test
public void testWriteNoMaster() throws ValidationException, IOException, RepoException {
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\":\"other\",\"body\":\"test summary\",\"head\":\"feature\",\"title\":\"test summary\"}");
return ("{\n" + " \"id\": 1,\n" + " \"number\": 12345,\n" + " \"state\": \"open\",\n" + " \"title\": \"test summary\",\n" + " \"body\": \"test summary\"" + "}").getBytes();
}
fail(method + " " + url);
throw new IllegalStateException();
}
};
GithubPrDestination d = skylark.eval("r", "r = git.github_pr_destination(" + " url = 'https://github.com/foo'," + " destination_ref = 'other'," + ")");
Writer<GitRevision> writer = d.newWriter(Glob.ALL_FILES, /*dryRun=*/
false, "feature", /*oldWriter=*/
null);
GitRepository remote = localHubRepo("foo");
addFiles(remote, "master", "first change", ImmutableMap.<String, String>builder().put("foo.txt", "").build());
addFiles(remote, "other", "second change", ImmutableMap.<String, String>builder().put("foo.txt", "test").build());
Files.write(this.workdir.resolve("test.txt"), "some content".getBytes());
writer.write(TransformResults.of(this.workdir, new DummyRevision("one")), console);
assertThat(remote.refExists("feature")).isTrue();
assertThat(Iterables.transform(remote.log("feature").run(), GitLogEntry::getBody)).containsExactly("first change\n", "second change\n", "test summary\n" + "\n" + "DummyOrigin-RevId: one\n");
}
use of com.google.copybara.testing.DummyRevision in project copybara by google.
the class GerritDestinationTest method changeAlreadyMergedTooOften.
@Test
public void changeAlreadyMergedTooOften() throws Exception {
fetch = "master";
Files.write(workdir.resolve("file"), "some content".getBytes());
options.setForce(true);
String firstChangeId = "I" + Hashing.sha1().newHasher().putString("origin_ref", StandardCharsets.UTF_8).putString(options.gitDestination.committerEmail, StandardCharsets.UTF_8).putInt(0).hash();
String secondChangeId = "I" + Hashing.sha1().newHasher().putString("origin_ref", Charsets.UTF_8).putString(options.gitDestination.committerEmail, StandardCharsets.UTF_8).putInt(1).hash();
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 change = changeIdFromRequest(url);
String result = "[" + "{" + " change_id : \"" + change + "\"," + " status : \"MERGED\"" + "}]";
return result.getBytes(UTF_8);
}
throw new IllegalArgumentException(method + " " + url);
}
};
try {
process(new DummyRevision("origin_ref"));
fail("Should have thrown RepoException");
} catch (RepoException expected) {
assertThat(expected.getMessage()).contains("Unable to find unmerged change for ");
}
}
use of com.google.copybara.testing.DummyRevision in project copybara by google.
the class GerritDestinationTest method changeAlreadyMergedOnce.
@Test
public void changeAlreadyMergedOnce() throws Exception {
fetch = "master";
Files.write(workdir.resolve("file"), "some content".getBytes());
options.setForce(true);
String firstChangeId = "I" + Hashing.sha1().newHasher().putString("origin_ref", StandardCharsets.UTF_8).putString(options.gitDestination.committerEmail, StandardCharsets.UTF_8).putInt(0).hash();
String secondChangeId = "I" + Hashing.sha1().newHasher().putString("origin_ref", StandardCharsets.UTF_8).putString(options.gitDestination.committerEmail, StandardCharsets.UTF_8).putInt(1).hash();
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 change = changeIdFromRequest(url);
String result = "[" + "{" + " change_id : \"" + change + "\"," + " status : \"" + (change.equals(firstChangeId) ? "MERGED" : "NEW") + "\"" + "}]";
return result.getBytes(UTF_8);
}
throw new IllegalArgumentException(method + " " + url);
}
};
process(new DummyRevision("origin_ref"));
assertThat(lastCommitChangeIdLine("origin_ref", repo())).isEqualTo(GerritDestination.CHANGE_ID_LABEL + ": " + secondChangeId);
}
use of com.google.copybara.testing.DummyRevision in project copybara by google.
the class CopybaraTest method testInfoAvailableToMigrate.
@Test
public void testInfoAvailableToMigrate() throws Exception {
MigrationReference<DummyRevision> workflow = MigrationReference.create("workflow", new DummyRevision("1111"), ImmutableList.of(newChange("2222"), newChange("3333")));
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 3333.*");
}
use of com.google.copybara.testing.DummyRevision in project copybara by google.
the class InfoTest method testInfoAvailableToMigrate.
@Test
public void testInfoAvailableToMigrate() throws Exception {
info = new InfoCmd((configPath, sourceRef) -> new ConfigLoader(skylark.createModuleSet(), skylark.createConfigFile("copy.bara.sky", configInfo), optionsBuilder.general.getStarlarkMode()) {
@Override
public Config load(Console console) {
return config;
}
@Override
public ConfigWithDependencies loadWithDependencies(Console console) {
return configWithDeps;
}
}, getFakeContextProvider());
MigrationReference<DummyRevision> workflow = MigrationReference.create("workflow", new DummyRevision("1111"), ImmutableList.of(newChange("2222", "First change", ZonedDateTime.ofInstant(Instant.ofEpochSecond(1541631979), ZoneId.of("-08:00"))), newChange("3333", "Second change", ZonedDateTime.ofInstant(Instant.ofEpochSecond(1541639979), ZoneId.of("-08:00")))));
Info<?> mockedInfo = Info.create(dummyOriginDescription, dummyDestinationDescription, ImmutableList.of(workflow));
Mockito.<Info<? extends Revision>>when(migration.getInfo()).thenReturn(mockedInfo);
// Copybara copybara = new Copybara(new ConfigValidator() {}, migration -> {});
// copybara.info(optionsBuilder.build(), config, "workflow");
info.run(new CommandEnv(temp, optionsBuilder.build(), ImmutableList.of("copy.bara.sky", "workflow")));
assertThat(eventMonitor.infoFinishedEvent).isNotNull();
assertThat(eventMonitor.infoFinishedEvent.getInfo()).isEqualTo(mockedInfo);
console.assertThat().onceInLog(MessageType.INFO, ".*last_migrated 1111 - last_available 3333.*").onceInLog(MessageType.INFO, ".*Date.*Revision.*Description.*Author.*").onceInLog(MessageType.INFO, ".*2018-11-07 15:06:19.*2222.*First change.*Foo <Bar>.*").onceInLog(MessageType.INFO, ".*2018-11-07 17:19:39.*3333.*Second change.*Foo <Bar>.*");
}
Aggregations