use of com.google.copybara.util.console.Console in project copybara by google.
the class WorkflowTest method testOnFinishHook_temporaryError.
// Validates that the hook is executed when the workflow throws an exception != VE, and that
// the correct effect is populated
@Test
public void testOnFinishHook_temporaryError() 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 RepoException {
throw new RepoException("Repo exception!");
}
};
}
};
verifyHookForException(RepoException.class, Type.TEMPORARY_ERROR, "Repo exception!");
}
use of com.google.copybara.util.console.Console in project copybara by google.
the class InfoTest method setUp.
@Before
public void setUp() throws IOException {
dummyOriginDescription = ImmutableMultimap.of("origin", "foo");
dummyDestinationDescription = ImmutableMultimap.of("dest", "bar");
console = new TestingConsole();
temp = Files.createTempDirectory("temp");
optionsBuilder = new OptionsBuilder();
optionsBuilder.setConsole(console);
optionsBuilder.setWorkdirToRealTempDir();
skylark = new SkylarkTestExecutor(optionsBuilder);
eventMonitor = new TestingEventMonitor();
optionsBuilder.general.enableEventMonitor("just testing", eventMonitor);
optionsBuilder.general.starlarkMode = StarlarkMode.STRICT.name();
migration = mock(Migration.class);
config = new Config(ImmutableMap.of("workflow", migration), temp.resolve("copy.bara.sky").toString(), ImmutableMap.of());
configWithDeps = mock(ConfigWithDependencies.class);
when(configWithDeps.getConfig()).thenAnswer(i -> config);
configInfo = "" + "core.workflow(" + " name = 'workflow'," + " origin = git.origin(url = 'https://example.com/orig', ref = 'master')," + " destination = git.destination(url = 'https://example.com/dest')," + " authoring = authoring.overwrite('Foo <foo@example.com>')" + ")\n\n" + "";
info = new InfoCmd((configPath, sourceRef) -> new ConfigLoader(skylark.createModuleSet(), skylark.createConfigFile("copy.bara.sky", configInfo), optionsBuilder.general.getStarlarkMode()) {
@Override
protected Config doLoadForRevision(Console console, Revision revision) throws ValidationException {
try {
return skylark.loadConfig(configPath);
} catch (IOException e) {
throw new AssertionError("Should not fail", e);
}
}
}, getFakeContextProvider());
}
use of com.google.copybara.util.console.Console in project copybara by google.
the class ReadConfigFromChangeWorkflowTest method testWriterStateMaintained.
/**
* A test that check that we can mutate the glob in iterative mode
*/
@SuppressWarnings("unchecked")
@Test
public void testWriterStateMaintained() throws Exception {
options.workflowOptions.lastRevision = "0";
String configCode = mutatingWorkflow("*");
Config cfg = skylark.loadConfig(configCode);
ConfigLoader constantConfigLoader = new ConfigLoader(skylark.createModuleSet(), skylark.createConfigFile("copy.bara.sky", configCode), options.general.getStarlarkMode()) {
@Override
protected Config doLoadForRevision(Console console, Revision revision) throws ValidationException {
try {
return skylark.loadConfig(mutatingWorkflow(revision.asString()));
} catch (IOException e) {
throw new AssertionError("Should not fail", e);
}
}
};
ReadConfigFromChangeWorkflow<?, ?> wf = new ReadConfigFromChangeWorkflow<>((Workflow) cfg.getMigration("default"), options.build(), constantConfigLoader, new ConfigValidator() {
@Override
public ValidationResult validate(Config config, String migrationName) {
return ValidationResult.EMPTY;
}
});
origin.singleFileChange(0, "base", "fileB", "b");
origin.singleFileChange(1, "one", "file1", "b");
origin.singleFileChange(2, "two", "file2", "b");
origin.singleFileChange(3, "three", "file3", "b");
wf.run(Files.createTempDirectory("workdir"), ImmutableList.of("3"));
assertThat(destination.processed).hasSize(3);
assertThat(destination.processed.get(0).getDestinationFiles().toString()).contains("file1");
assertThat(destination.processed.get(0).getWorkdir()).containsExactly("file1", "b");
assertThat(destination.processed.get(1).getDestinationFiles().toString()).contains("file2");
assertThat(destination.processed.get(1).getWorkdir()).containsExactly("file2", "b");
assertThat(destination.processed.get(2).getDestinationFiles().toString()).contains("file3");
assertThat(destination.processed.get(2).getWorkdir()).containsExactly("file3", "b");
}
use of com.google.copybara.util.console.Console in project copybara by google.
the class ApiCheckerTest method testCheckInternalError.
@Test
public void testCheckInternalError() throws CheckerException {
ApiChecker checker = new ApiChecker(new FakeChecker() {
@Override
public void doCheck(ImmutableMap<String, String> fields, Console console) throws IOException {
throw new IOException("Tool error!");
}
}, new TestingConsole());
RuntimeException e1 = assertThrows(RuntimeException.class, () -> checker.check("foo", new Object()));
assertThat(e1).hasMessageThat().isEqualTo("Error running checker");
RuntimeException e2 = assertThrows(RuntimeException.class, () -> checker.check("foo", new Object(), "bar", new Object()));
assertThat(e2).hasMessageThat().isEqualTo("Error running checker");
RuntimeException e3 = assertThrows(RuntimeException.class, () -> checker.check("foo", new Object(), "bar", new Object(), "baz", new Object()));
assertThat(e3).hasMessageThat().isEqualTo("Error running checker");
}
use of com.google.copybara.util.console.Console in project copybara by google.
the class ApiCheckerTest method testCheck.
@Test
public void testCheck() throws CheckerException {
ApiChecker checker = new ApiChecker(new FakeChecker() {
@Override
public void doCheck(ImmutableMap<String, String> fields, Console console) {
}
}, new TestingConsole());
checker.check("foo", new Object());
checker.check("foo", new Object(), "bar", new Object());
checker.check("foo", new Object(), "bar", new Object(), "baz", new Object());
}
Aggregations