Search in sources :

Example 26 with TestingConsole

use of com.google.copybara.util.console.testing.TestingConsole in project copybara by google.

the class GlobConverterTest method parseGlob.

private PathMatcher parseGlob(String value) throws IOException {
    ImmutableMap<String, String> envWithHome = ImmutableMap.of("HOME", Files.createTempDirectory("foo").toString());
    ModuleSupplier moduleSupplier = new ModuleSupplier(envWithHome, FileSystems.getDefault(), new TestingConsole());
    Options options = moduleSupplier.create().getOptions();
    JCommander jCommander = new JCommander(options.getAll());
    jCommander.parse("--read-config-from-head-paths", value);
    return options.get(WorkflowOptions.class).readConfigFromChangePaths.relativeTo(Paths.get("/"));
}
Also used : WorkflowOptions(com.google.copybara.WorkflowOptions) Options(com.google.copybara.Options) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) JCommander(com.beust.jcommander.JCommander) ModuleSupplier(com.google.copybara.ModuleSupplier)

Example 27 with TestingConsole

use of com.google.copybara.util.console.testing.TestingConsole in project copybara by google.

the class OnboardCmdTest method testOnboardCmdTextAdventure.

@Test
public void testOnboardCmdTextAdventure() throws Exception {
    TestingConsole console = new TestingConsole();
    console.respondWithString("https://github.com/google/origin").respondWithString("https://github.com/google/destination").respondWithString("Copybara <copy@bara.com>");
    optionsBuilder.setConsole(console);
    OnboardCmd onboardCmd = new OnboardCmd();
    ExitCode exit = onboardCmd.run(new CommandEnv(temp, skylark.createModuleSet().getOptions(), ImmutableList.of("copy.bara.sky")));
    assertThat(exit).isEqualTo(ExitCode.SUCCESS);
    ConfigBuilder expectedConfig = new ConfigBuilder(new GitToGitTemplate());
    expectedConfig.setNamedStringParameter("origin_url", "https://github.com/google/origin");
    expectedConfig.setNamedStringParameter("destination_url", "https://github.com/google/destination");
    expectedConfig.setNamedStringParameter("email", "Copybara <copy@bara.com>");
    assertThat(Joiner.on('\n').join(console.getMessages().stream().map(Message::getText).collect(Collectors.toList()))).contains(expectedConfig.build());
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) Message(com.google.copybara.util.console.Message) ExitCode(com.google.copybara.util.ExitCode) CommandEnv(com.google.copybara.CommandEnv) Test(org.junit.Test)

Example 28 with TestingConsole

use of com.google.copybara.util.console.testing.TestingConsole in project copybara by google.

the class GitRepoTypeTest method setup.

@Before
public void setup() throws Exception {
    repoGitDir = Files.createTempDirectory("testRepo");
    fileRepoDir = Files.createTempDirectory("fileRepo");
    // We mock by default to avoid accidental network calls.
    testRepo = new GitRepository(repoGitDir, null, /*verbose=*/
    true, getGitEnv(), Duration.ofMinutes(1), /*noVerify=*/
    false) {

        @Override
        public GitRevision fetchSingleRefWithTags(String url, String ref, boolean fetchTags, boolean partialFetch) {
            interceptedFetches.add(new String[] { url, ref });
            return new GitRevision(this, Strings.repeat("0", 40));
        }
    };
    testRepo.init();
    prepareFileRepo();
    console = new TestingConsole();
    generalOptions = new OptionsBuilder().setConsole(console).build().get(GeneralOptions.class);
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) GeneralOptions(com.google.copybara.GeneralOptions) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) Before(org.junit.Before)

Example 29 with TestingConsole

use of com.google.copybara.util.console.testing.TestingConsole in project copybara by google.

the class SameGitTreeTest method setup.

@Before
public void setup() throws Exception {
    workdir = Files.createTempDirectory("workdir");
    gitDir = Files.createTempDirectory("gitdir");
    console = new TestingConsole();
    options = new OptionsBuilder().setConsole(console).setOutputRootToTmpDir();
    repository = GitRepository.newBareRepo(gitDir, getGitEnv(), /*verbose=*/
    true, DEFAULT_TIMEOUT, /*noVerify=*/
    false).withWorkTree(workdir);
    repository.init();
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) Before(org.junit.Before)

Example 30 with TestingConsole

use of com.google.copybara.util.console.testing.TestingConsole in project copybara by google.

the class GitHubApiTest method getTransport.

@Override
public GitHubApiTransport getTransport() throws Exception {
    credentialsFile = Files.createTempFile("credentials", "test");
    Files.write(credentialsFile, "https://user:SECRET@github.com".getBytes(UTF_8));
    GitRepository repo = newBareRepo(Files.createTempDirectory("test_repo"), getGitEnv(), /*verbose=*/
    true, DEFAULT_TIMEOUT, /*noVerify=*/
    false).init().withCredentialHelper("store --file=" + credentialsFile);
    requestToResponse = new HashMap<>();
    requestValidators = new HashMap<>();
    httpTransport = new MockHttpTransport() {

        @Override
        public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
            String requestString = method + " " + url;
            MockLowLevelHttpRequest request = new MockLowLevelHttpRequest() {

                @Override
                public LowLevelHttpResponse execute() throws IOException {
                    System.err.println(getContentAsString());
                    Predicate<String> validator = requestValidators.get(method + " " + url);
                    if (validator != null) {
                        assertWithMessage("Request content did not match expected values.").that(validator.test(getContentAsString())).isTrue();
                    }
                    return super.execute();
                }
            };
            MockLowLevelHttpResponse response = requestToResponse.get(requestString);
            if (response == null) {
                response = new MockLowLevelHttpResponse();
                response.setContent(String.format("{ 'message' : 'This is not the repo you are looking for! %s %s'," + " 'documentation_url' : 'http://github.com/some_url'}", method, url));
                response.setStatusCode(404);
            }
            request.setResponse(response);
            return request;
        }
    };
    return new GitHubApiTransportImpl(repo, httpTransport, "some_storage_file", new TestingConsole());
}
Also used : MockHttpTransport(com.google.api.client.testing.http.MockHttpTransport) MockLowLevelHttpResponse(com.google.api.client.testing.http.MockLowLevelHttpResponse) LowLevelHttpRequest(com.google.api.client.http.LowLevelHttpRequest) MockLowLevelHttpRequest(com.google.api.client.testing.http.MockLowLevelHttpRequest) IOException(java.io.IOException) MockLowLevelHttpRequest(com.google.api.client.testing.http.MockLowLevelHttpRequest) Predicate(java.util.function.Predicate) GitRepository(com.google.copybara.git.GitRepository) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) MockLowLevelHttpResponse(com.google.api.client.testing.http.MockLowLevelHttpResponse) LowLevelHttpResponse(com.google.api.client.http.LowLevelHttpResponse)

Aggregations

TestingConsole (com.google.copybara.util.console.testing.TestingConsole)96 Before (org.junit.Before)57 OptionsBuilder (com.google.copybara.testing.OptionsBuilder)55 SkylarkTestExecutor (com.google.copybara.testing.SkylarkTestExecutor)54 Test (org.junit.Test)34 Path (java.nio.file.Path)15 GitTestUtil (com.google.copybara.testing.git.GitTestUtil)8 FileSystem (java.nio.file.FileSystem)8 IOException (java.io.IOException)7 LowLevelHttpRequest (com.google.api.client.http.LowLevelHttpRequest)6 DummyChecker (com.google.copybara.testing.DummyChecker)6 DummyOrigin (com.google.copybara.testing.DummyOrigin)6 Console (com.google.copybara.util.console.Console)6 MockHttpTransport (com.google.api.client.testing.http.MockHttpTransport)5 MockLowLevelHttpRequest (com.google.api.client.testing.http.MockLowLevelHttpRequest)5 MockLowLevelHttpResponse (com.google.api.client.testing.http.MockLowLevelHttpResponse)5 Truth.assertWithMessage (com.google.common.truth.Truth.assertWithMessage)5 GitRepository (com.google.copybara.git.GitRepository)5 LowLevelHttpResponse (com.google.api.client.http.LowLevelHttpResponse)4 RepoException (com.google.copybara.exception.RepoException)4