Search in sources :

Example 1 with ConfigValidator

use of com.google.copybara.config.ConfigValidator in project copybara by google.

the class CopybaraTest method testInfoUpToDate.

@Test
public void testInfoUpToDate() throws Exception {
    MigrationReference<DummyRevision> workflow = MigrationReference.create("workflow", new DummyRevision("1111"), ImmutableList.of());
    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 None.*");
}
Also used : ConfigValidator(com.google.copybara.config.ConfigValidator) DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Example 2 with ConfigValidator

use of com.google.copybara.config.ConfigValidator in project copybara by google.

the class Main method getCommands.

public ImmutableSet<CopybaraCmd> getCommands(ModuleSet moduleSet, ConfigLoaderProvider configLoaderProvider, JCommander jcommander) throws CommandLineException {
    ConfigValidator validator = getConfigValidator(moduleSet.getOptions());
    Consumer<Migration> consumer = getMigrationRanConsumer();
    return ImmutableSet.of(new MigrateCmd(validator, consumer, configLoaderProvider, moduleSet), new InfoCmd(configLoaderProvider, newInfoContextProvider()), new ValidateCmd(validator, consumer, configLoaderProvider), new HelpCmd(jcommander), new OnboardCmd(), new VersionCmd());
}
Also used : OnboardCmd(com.google.copybara.onboard.OnboardCmd) ConfigValidator(com.google.copybara.config.ConfigValidator) Migration(com.google.copybara.config.Migration)

Example 3 with ConfigValidator

use of com.google.copybara.config.ConfigValidator 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");
}
Also used : ConfigValidator(com.google.copybara.config.ConfigValidator) Config(com.google.copybara.config.Config) Console(com.google.copybara.util.console.Console) IOException(java.io.IOException) ValidationResult(com.google.copybara.config.ValidationResult) Test(org.junit.Test)

Example 4 with ConfigValidator

use of com.google.copybara.config.ConfigValidator 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.*");
}
Also used : ConfigValidator(com.google.copybara.config.ConfigValidator) DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Aggregations

ConfigValidator (com.google.copybara.config.ConfigValidator)4 Test (org.junit.Test)3 DummyRevision (com.google.copybara.testing.DummyRevision)2 Config (com.google.copybara.config.Config)1 Migration (com.google.copybara.config.Migration)1 ValidationResult (com.google.copybara.config.ValidationResult)1 OnboardCmd (com.google.copybara.onboard.OnboardCmd)1 Console (com.google.copybara.util.console.Console)1 IOException (java.io.IOException)1