use of com.google.copybara.exception.ValidationException in project copybara by google.
the class ExamplesTest method checkExamples.
private ImmutableList<Result> checkExamples(SkylarkTestExecutor executor, Class<?> module, ImmutableList<Example> samples, String name) {
ImmutableList.Builder<Result> result = ImmutableList.builder();
for (Example example : samples) {
Object val;
String exampleRef = module.getName() + "#" + name + ": " + example.title();
// Quilt requires an extra file.
if (exampleRef.contains("com.google.copybara.transform.patch.PatchModule#quiltApply")) {
executor.addConfigFile("patches/series", "");
}
try {
val = Strings.isNullOrEmpty(example.testExistingVariable()) ? executor.eval("a", "a=" + example.code()) : executor.eval(example.testExistingVariable(), example.code());
assertWithMessage(exampleRef).that(val).isNotNull();
result.add(new Result(exampleRef, module, null));
} catch (ValidationException | AssertionError e) {
result.add(new Result(exampleRef, module, e));
}
}
return result.build();
}
use of com.google.copybara.exception.ValidationException 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.exception.ValidationException in project copybara by google.
the class TransformWorkTest method testSymlinks_outside.
@Test
public void testSymlinks_outside() throws IOException, ValidationException {
Path base = Files.createDirectories(workdir.resolve("foo"));
Path tempFile = Files.createTempFile("foo", "bar");
Files.write(tempFile, "THE CONTENT".getBytes(UTF_8));
Files.createSymbolicLink(base.resolve("symlink"), tempFile);
Transformation transformation = skylark.eval("transformation", "" + "def test(ctx):\n" + " ctx.new_path('foo/symlink').read_symlink()\n" + "\n" + "transformation = core.transform([test])");
ValidationException e = assertThrows(ValidationException.class, () -> transformation.transform(TransformWorks.of(workdir, "test", console)));
assertThat(e).hasMessageThat().contains("points to a file outside the checkout dir");
}
use of com.google.copybara.exception.ValidationException in project copybara by google.
the class FeedbackTest method testErrorResultThrowsValidationException.
@Test
public void testErrorResultThrowsValidationException() throws Exception {
Feedback feedback = feedback("" + "def test_action(ctx):\n" + " return ctx.error('This is an error')\n", "test_action");
ValidationException expected = assertThrows(ValidationException.class, () -> feedback.run(workdir, ImmutableList.of()));
assertThat(expected).hasMessageThat().contains("Feedback migration 'default' action 'test_action' returned error: " + "This is an error. Aborting execution.");
console.assertThat().equalsNext(MessageType.ERROR, "Action 'test_action' returned error: This is an error");
}
use of com.google.copybara.exception.ValidationException in project copybara by google.
the class FeedbackTest method testActionsMustReturnResult.
@Test
public void testActionsMustReturnResult() throws Exception {
Feedback feedback = feedback("" + "def test_action(ctx):\n" + " ctx.console.info('Bad action')\n" + "\n", "test_action");
ValidationException expected = assertThrows(ValidationException.class, () -> feedback.run(workdir, ImmutableList.of()));
assertThat(expected).hasMessageThat().contains("Actions must return a result via built-in functions: success(), " + "error(), noop() return, but 'test_action' returned: None");
}
Aggregations