use of com.google.copybara.util.console.Console in project copybara by google.
the class WorkflowTest method checkIterativeModeWithError.
@SuppressWarnings("unchecked")
private <T extends Exception> T checkIterativeModeWithError(T exception) throws IOException, ValidationException {
for (int timestamp = 0; timestamp < 10; timestamp++) {
origin.addSimpleChange(timestamp);
}
// Override destination with one that always throws EmptyChangeException.
options.testingOptions.destination = new RecordsProcessCallDestination() {
@Override
public Writer<Revision> newWriter(WriterContext writerContext) {
return new WriterImpl(writerContext.isDryRun()) {
@Override
public ImmutableList<DestinationEffect> write(TransformResult transformResult, Glob destinationFiles, Console console) throws ValidationException, RepoException {
assert exception != null;
Throwables.propagateIfPossible(exception, ValidationException.class, RepoException.class);
throw new RuntimeException(exception);
}
};
}
};
Workflow<?, ?> workflow = iterativeWorkflow(/*previousRef=*/
"1");
try {
workflow.run(workdir, ImmutableList.of("3"));
fail();
} catch (Exception expected) {
assertThat(expected).isInstanceOf(expected.getClass());
return (T) expected;
}
return exception;
}
use of com.google.copybara.util.console.Console in project copybara by google.
the class WorkflowTest method testOnFinishHook_error.
// Validates that the hook is executed when the workflow throws ValidationException, and that
// the correct effect is populated
@Test
public void testOnFinishHook_error() throws Exception {
options.testingOptions.destination = new RecordsProcessCallDestination() {
@Override
public Writer<Revision> newWriter(WriterContext writerContext) {
return new RecordsProcessCallDestination.WriterImpl(false) {
@Override
public ImmutableList<DestinationEffect> write(TransformResult transformResult, Glob destinationFiles, Console console) throws ValidationException {
throw new ValidationException("Validation exception!");
}
};
}
};
verifyHookForException(ValidationException.class, Type.ERROR, "Validation exception!");
}
use of com.google.copybara.util.console.Console 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>.*");
}
use of com.google.copybara.util.console.Console in project copybara by google.
the class InfoTest method testInfoUpToDate.
@Test
public void testInfoUpToDate() 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());
Info<?> mockedInfo = Info.create(dummyOriginDescription, dummyDestinationDescription, ImmutableList.of(workflow));
Mockito.<Info<? extends Revision>>when(migration.getInfo()).thenReturn(mockedInfo);
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 None.*");
}
use of com.google.copybara.util.console.Console in project copybara by google.
the class ApiCheckerTest method testCheckError.
@Test
public void testCheckError() {
ApiChecker checker = new ApiChecker(new FakeChecker() {
@Override
public void doCheck(ImmutableMap<String, String> fields, Console console) throws CheckerException {
throw new CheckerException("Check failed!");
}
}, new TestingConsole());
ValidationException e = assertThrows(ValidationException.class, () -> checker.check("foo", new Object()));
assertThat(e).hasMessageThat().isEqualTo("Check failed!");
ValidationException failedCheck = assertThrows(ValidationException.class, () -> checker.check("foo", new Object(), "bar", new Object()));
assertThat(failedCheck).hasMessageThat().isEqualTo("Check failed!");
ValidationException failedCheckArgs = assertThrows(ValidationException.class, () -> checker.check("foo", new Object(), "bar", new Object(), "baz", new Object()));
assertThat(failedCheckArgs).hasMessageThat().isEqualTo("Check failed!");
}
Aggregations