Search in sources :

Example 1 with SkylarkTestExecutor

use of com.google.copybara.testing.SkylarkTestExecutor in project copybara by google.

the class GithubPrDestinationTest method setup.

@Before
public void setup() throws Exception {
    repoGitDir = Files.createTempDirectory("GithubPrDestinationTest-repoGitDir");
    workdir = Files.createTempDirectory("workdir");
    localHub = Files.createTempDirectory("localHub");
    git("init", "--bare", repoGitDir.toString());
    console = new TestingConsole();
    options = new OptionsBuilder().setConsole(console).setOutputRootToTmpDir();
    options.git = new TestGitOptions(localHub, () -> GithubPrDestinationTest.this.options.general);
    options.github = new GithubOptions(() -> options.general, options.git) {

        @Override
        public GithubApi getApi(String project) throws RepoException {
            assertThat(project).isEqualTo(expectedProject);
            return super.getApi(project);
        }

        @Override
        protected HttpTransport getHttpTransport() {
            return gitApiMockHttpTransport;
        }
    };
    Path credentialsFile = Files.createTempFile("credentials", "test");
    Files.write(credentialsFile, "https://user:SECRET@github.com".getBytes(UTF_8));
    options.git.credentialHelperStorePath = credentialsFile.toString();
    options.gitDestination = new GitDestinationOptions(() -> options.general, options.git);
    options.gitDestination.committerEmail = "commiter@email";
    options.gitDestination.committerName = "Bara Kopi";
    skylark = new SkylarkTestExecutor(options, GitModule.class);
}
Also used : Path(java.nio.file.Path) TestGitOptions(com.google.copybara.testing.git.GitTestUtil.TestGitOptions) GithubApi(com.google.copybara.git.github.api.GithubApi) RepoException(com.google.copybara.exception.RepoException) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) GitApiMockHttpTransport(com.google.copybara.testing.OptionsBuilder.GitApiMockHttpTransport) HttpTransport(com.google.api.client.http.HttpTransport) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) Before(org.junit.Before)

Example 2 with SkylarkTestExecutor

use of com.google.copybara.testing.SkylarkTestExecutor in project copybara by google.

the class PatchTransformationTest method setup.

@Before
public void setup() throws IOException {
    checkoutDir = Files.createTempDirectory("workdir");
    Files.createDirectories(checkoutDir);
    console = new TestingConsole();
    options = new OptionsBuilder().setConsole(console);
    general = options.build().get(GeneralOptions.class);
    skylark = new SkylarkTestExecutor(options, PatchModule.class);
    ImmutableMap<String, byte[]> configFiles = ImmutableMap.of("diff.patch", (DIFF).getBytes(UTF_8), "series", ("diff.patch\n").getBytes(UTF_8));
    patchFile = new MapConfigFile(configFiles, "diff.patch");
    seriesFile = new MapConfigFile(configFiles, "series");
    options.setEnvironment(GitTestUtil.getGitEnv());
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) GeneralOptions(com.google.copybara.GeneralOptions) MapConfigFile(com.google.copybara.config.MapConfigFile) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Before(org.junit.Before)

Example 3 with SkylarkTestExecutor

use of com.google.copybara.testing.SkylarkTestExecutor in project copybara by google.

the class ChangeMessageTest method setUp.

@Before
public void setUp() throws Exception {
    OptionsBuilder options = new OptionsBuilder();
    skylarkTestExecutor = new SkylarkTestExecutor(options);
}
Also used : OptionsBuilder(com.google.copybara.testing.OptionsBuilder) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Before(org.junit.Before)

Example 4 with SkylarkTestExecutor

use of com.google.copybara.testing.SkylarkTestExecutor 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());
}
Also used : MigrationReference(com.google.copybara.Info.MigrationReference) DummyRevision(com.google.copybara.testing.DummyRevision) ZonedDateTime(java.time.ZonedDateTime) RunWith(org.junit.runner.RunWith) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) MessageType(com.google.copybara.util.console.Message.MessageType) ImmutableList(com.google.common.collect.ImmutableList) Author(com.google.copybara.authoring.Author) ExitCode(com.google.copybara.util.ExitCode) Config(com.google.copybara.config.Config) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) Path(java.nio.file.Path) Before(org.junit.Before) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) ImmutableMap(com.google.common.collect.ImmutableMap) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) Files(java.nio.file.Files) Migration(com.google.copybara.config.Migration) ValidationException(com.google.copybara.exception.ValidationException) ConfigWithDependencies(com.google.copybara.config.SkylarkParser.ConfigWithDependencies) Console(com.google.copybara.util.console.Console) IOException(java.io.IOException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) Instant(java.time.Instant) ZoneId(java.time.ZoneId) Mockito(org.mockito.Mockito) TestingEventMonitor(com.google.copybara.testing.TestingEventMonitor) StarlarkMode(com.google.copybara.util.console.StarlarkMode) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) SUCCESS(com.google.copybara.util.ExitCode.SUCCESS) Mockito.mock(org.mockito.Mockito.mock) Migration(com.google.copybara.config.Migration) Config(com.google.copybara.config.Config) IOException(java.io.IOException) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) TestingEventMonitor(com.google.copybara.testing.TestingEventMonitor) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) DummyRevision(com.google.copybara.testing.DummyRevision) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) Console(com.google.copybara.util.console.Console) ConfigWithDependencies(com.google.copybara.config.SkylarkParser.ConfigWithDependencies) Before(org.junit.Before)

Example 5 with SkylarkTestExecutor

use of com.google.copybara.testing.SkylarkTestExecutor in project copybara by google.

the class CoreTransformTest method setup.

@Before
public void setup() throws IOException {
    FileSystem fs = Jimfs.newFileSystem();
    checkoutDir = fs.getPath("/test-checkoutDir");
    Files.createDirectories(checkoutDir);
    options = new OptionsBuilder();
    skylark = new SkylarkTestExecutor(options);
    console = new TestingConsole();
    options.setConsole(console);
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) FileSystem(java.nio.file.FileSystem) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Before(org.junit.Before)

Aggregations

SkylarkTestExecutor (com.google.copybara.testing.SkylarkTestExecutor)70 OptionsBuilder (com.google.copybara.testing.OptionsBuilder)58 Before (org.junit.Before)58 TestingConsole (com.google.copybara.util.console.testing.TestingConsole)54 Path (java.nio.file.Path)17 Test (org.junit.Test)14 GitTestUtil (com.google.copybara.testing.git.GitTestUtil)9 DummyOrigin (com.google.copybara.testing.DummyOrigin)8 ValidationException (com.google.copybara.exception.ValidationException)7 FileSystem (java.nio.file.FileSystem)7 DummyChecker (com.google.copybara.testing.DummyChecker)6 RecordsProcessCallDestination (com.google.copybara.testing.RecordsProcessCallDestination)6 MapConfigFile (com.google.copybara.config.MapConfigFile)4 RepoException (com.google.copybara.exception.RepoException)4 Console (com.google.copybara.util.console.Console)4 IOException (java.io.IOException)4 LowLevelHttpRequest (com.google.api.client.http.LowLevelHttpRequest)3 ImmutableList (com.google.common.collect.ImmutableList)3 Truth.assertThat (com.google.common.truth.Truth.assertThat)3 DummyRevision (com.google.copybara.testing.DummyRevision)3