Search in sources :

Example 21 with TestingConsole

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

the class GitHubTriggerTest method setup.

@Before
public void setup() throws Exception {
    TestingConsole console = new TestingConsole();
    OptionsBuilder options = new OptionsBuilder();
    options.setConsole(console).setOutputRootToTmpDir();
    options.testingOptions.checker = new DummyChecker(ImmutableSet.of("badword"));
    skylarkTestExecutor = new SkylarkTestExecutor(options);
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) DummyChecker(com.google.copybara.testing.DummyChecker) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Before(org.junit.Before)

Example 22 with TestingConsole

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

the class GitOriginSubmodulesTest method setup.

@Before
public void setup() throws Exception {
    OptionsBuilder options = new OptionsBuilder().setConsole(new TestingConsole()).setOutputRootToTmpDir();
    skylark = new SkylarkTestExecutor(options);
    // Pass custom HOME directory so that we run an hermetic test and we
    // can add custom configuration to $HOME/.gitconfig.
    Path userHomeForTest = Files.createTempDirectory("home");
    options.setHomeDir(userHomeForTest.toString());
    checkoutDir = Files.createTempDirectory("checkout");
}
Also used : Path(java.nio.file.Path) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Before(org.junit.Before)

Example 23 with TestingConsole

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

the class GitOriginTest method testGitUrlOverwrite.

/**
 * Check that we can overwrite the git url using the CLI option and that we show a message
 */
@Test
public void testGitUrlOverwrite() throws Exception {
    createTestRepo(Files.createTempDirectory("cliremote"));
    git("init");
    writeFile(remote, "cli_remote.txt", "some change");
    repo.add().files("cli_remote.txt").run();
    git("commit", "-m", "a change from somewhere");
    TestingConsole testConsole = new TestingConsole();
    options.setConsole(testConsole);
    origin = origin();
    String newUrl = "file://" + remote.toFile().getAbsolutePath();
    Reader<GitRevision> reader = newReader();
    Change<GitRevision> cliHead = reader.change(origin.resolve(newUrl));
    reader.checkout(cliHead.getRevision(), checkoutDir);
    assertThat(cliHead.firstLineMessage()).isEqualTo("a change from somewhere");
    assertThatPath(checkoutDir).containsFile("cli_remote.txt", "some change").containsNoMoreFiles();
    testConsole.assertThat().onceInLog(MessageType.WARNING, "Git origin URL overwritten in the command line as " + newUrl);
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) Test(org.junit.Test)

Example 24 with TestingConsole

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

the class GitOriginTest method setup.

@Before
public void setup() throws Exception {
    options = new OptionsBuilder();
    console = new TestingConsole();
    options = new OptionsBuilder().setConsole(console).setOutputRootToTmpDir();
    skylark = new SkylarkTestExecutor(options);
    // Pass custom HOME directory so that we run an hermetic test and we
    // can add custom configuration to $HOME/.gitconfig.
    Path userHomeForTest = Files.createTempDirectory("home");
    options.setEnvironment(GitTestUtil.getGitEnv().getEnvironment());
    options.setHomeDir(userHomeForTest.toString());
    createTestRepo(Files.createTempDirectory("remote"));
    checkoutDir = Files.createTempDirectory("checkout");
    url = "file://" + remote.toFile().getAbsolutePath();
    ref = "other";
    moreOriginArgs = "";
    origin = origin();
    writeFile(remote, "test.txt", "some content");
    defaultBranch = repo.simpleCommand("symbolic-ref", "--short", "HEAD").getStdout().trim();
    repo.add().files("test.txt").run();
    git("commit", "-m", "first file", "--date", COMMIT_TIME);
    firstCommitRef = repo.parseRef("HEAD");
    originFiles = Glob.ALL_FILES;
}
Also used : Path(java.nio.file.Path) FileSubjects.assertThatPath(com.google.copybara.testing.FileSubjects.assertThatPath) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Before(org.junit.Before)

Example 25 with TestingConsole

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

the class GitHubApiTransportImplTest method testPasswordHeaderSet.

@Test
public void testPasswordHeaderSet() throws Exception {
    Map<String, List<String>> headers = new HashMap<>();
    httpTransport = new MockHttpTransport() {

        @Override
        public LowLevelHttpRequest buildRequest(String method, String url) {
            return new MockLowLevelHttpRequest() {

                @Override
                public LowLevelHttpResponse execute() throws IOException {
                    headers.putAll(this.getHeaders());
                    MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
                    response.setContent("foo");
                    return response;
                }
            };
        }
    };
    transport = new GitHubApiTransportImpl(repo, httpTransport, "store", new TestingConsole());
    transport.get("foo/bar", String.class);
    assertThat(headers).containsEntry("authorization", ImmutableList.of("Basic dXNlcjpTRUNSRVQ="));
}
Also used : MockHttpTransport(com.google.api.client.testing.http.MockHttpTransport) MockLowLevelHttpResponse(com.google.api.client.testing.http.MockLowLevelHttpResponse) HashMap(java.util.HashMap) 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) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) MockLowLevelHttpResponse(com.google.api.client.testing.http.MockLowLevelHttpResponse) LowLevelHttpResponse(com.google.api.client.http.LowLevelHttpResponse) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Test(org.junit.Test)

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