use of com.google.copybara.testing.SkylarkTestExecutor in project copybara by google.
the class ExamplesTest method testExamples.
@Test
public void testExamples() {
SkylarkTestExecutor executor = getExecutor();
ImmutableList.Builder<Result> resBuilder = ImmutableList.builder();
for (Class<?> module : executor.getModules()) {
for (Method method : module.getMethods()) {
Examples examples = method.getAnnotation(Examples.class);
ImmutableList<Example> samples;
if (examples == null) {
Example singleSample = method.getAnnotation(Example.class);
if (singleSample != null) {
samples = ImmutableList.of(singleSample);
} else {
continue;
}
} else {
samples = ImmutableList.copyOf(examples.value());
}
resBuilder.addAll(checkExamples(executor, module, samples, method.getName()));
}
}
ImmutableList<Result> result = resBuilder.build();
// Normally we won't remove examples or modules. This checks that we don't go down. This
// is the number of modules in Apr 2019. We can update this from time to time. It is not
// critical to have an accurate number, but that we don't lose at least these.
assertWithMessage("Less examples than expected").that(result.size()).isAtLeast(48);
Set<? extends Class<?>> modules = result.stream().map(e -> e.cls).collect(Collectors.toSet());
assertWithMessage("Less classes than expected: " + modules).that(modules.size()).isAtLeast(5);
List<Result> errors = result.stream().filter(Result::isError).collect(Collectors.toList());
assertWithMessage("Errors in examples(" + errors.size() + "):\n\n" + Joiner.on("\n-----------------------------\n").join(errors)).that(errors).isEmpty();
}
use of com.google.copybara.testing.SkylarkTestExecutor in project copybara by google.
the class MigrateCmdTest method setUp.
@Before
public void setUp() throws Exception {
console = new TestingConsole();
temp = Files.createTempDirectory("temp");
optionsBuilder = new OptionsBuilder();
optionsBuilder.setConsole(console).setOutputRootToTmpDir();
optionsBuilder.setForce(true);
Path userHomeForTest = Files.createTempDirectory("home");
optionsBuilder.setEnvironment(GitTestUtil.getGitEnv().getEnvironment());
optionsBuilder.setHomeDir(userHomeForTest.toString());
eventMonitor = new TestingEventMonitor();
optionsBuilder.general.enableEventMonitor("just testing", eventMonitor);
outPut = optionsBuilder.general.getOutputRoot();
optionsBuilder.general.starlarkMode = StarlarkMode.STRICT.name();
remote = Files.createTempDirectory("remote");
repo = GitRepository.newRepo(/*verbose*/
true, remote, new GitEnvironment(optionsBuilder.general.getEnvironment())).init();
primaryBranch = repo.getPrimaryBranch();
Files.createDirectories(remote.resolve("include"));
Files.write(remote.resolve("include/fileA.txt"), new byte[0]);
git(remote, "add", "include/fileA.txt");
git(remote, "commit", "-m", "not include");
optionsBuilder.setLastRevision(repo.parseRef("HEAD"));
git(remote, "checkout", primaryBranch);
Files.write(remote.resolve("include/mainline-file.txt"), new byte[0]);
git(remote, "add", "include/mainline-file.txt");
git(remote, "commit", "-m", "message_a!");
optionsBuilder.general.dryRunMode = true;
url = "file://" + remote.toFile().getAbsolutePath();
writeFile(remote, "test.txt", "some content");
writeFile(remote, "testA.txt", "some content");
repo.add().files("test.txt", "testA.txt").run();
git(remote, "commit", "-m", "first file", "--date", COMMIT_TIME);
optionsBuilder.setForce(true);
RecordsProcessCallDestination destination = new RecordsProcessCallDestination();
optionsBuilder.testingOptions.destination = destination;
skylark = new SkylarkTestExecutor(optionsBuilder);
}
use of com.google.copybara.testing.SkylarkTestExecutor in project copybara by google.
the class TransformWorkTest method setup.
@Before
public void setup() throws IOException {
origin = new DummyOrigin().setAuthor(ORIGINAL_AUTHOR);
destination = new RecordsProcessCallDestination();
OptionsBuilder options = new OptionsBuilder();
console = new TestingConsole();
options.setConsole(console);
options.testingOptions.origin = origin;
options.testingOptions.destination = destination;
// We don't care about force for this test
options.setForce(true);
skylark = new SkylarkTestExecutor(options);
workdir = Files.createTempDirectory("workdir");
}
use of com.google.copybara.testing.SkylarkTestExecutor in project copybara by google.
the class FeedbackTest method setup.
@Before
public void setup() throws Exception {
workdir = Jimfs.newFileSystem().getPath("/");
console = new TestingConsole(/*verbose=*/
false);
eventMonitor = new TestingEventMonitor();
options = new OptionsBuilder();
options.setConsole(console);
options.general.enableEventMonitor("justTesting", eventMonitor);
dummyTrigger = new DummyTrigger();
options.testingOptions.feedbackTrigger = dummyTrigger;
skylark = new SkylarkTestExecutor(options);
}
use of com.google.copybara.testing.SkylarkTestExecutor in project copybara by google.
the class WorkflowTest method testEmptyDescriptionForFolderDestination.
@Test
public void testEmptyDescriptionForFolderDestination() throws Exception {
origin.singleFileChange(/*timestamp=*/
44, "commit 1", "bar.txt", "1");
options.setWorkdirToRealTempDir().setHomeDir(StandardSystemProperty.USER_HOME.value());
new SkylarkTestExecutor(options).loadConfig("core.workflow(\n" + " name = 'foo',\n" + " origin = testing.origin(),\n" + " destination = folder.destination(),\n" + " authoring = " + authoring + ",\n" + " transformations = [metadata.replace_message(''),],\n" + ")\n").getMigration("foo").run(workdir, ImmutableList.of());
}
Aggregations