Search in sources :

Example 66 with TestingConsole

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

the class GitDestinationTest method setup.

@Before
public void setup() throws Exception {
    repoGitDir = Files.createTempDirectory("GitDestinationTest-repoGitDir");
    workdir = Files.createTempDirectory("workdir");
    console = new TestingConsole();
    options = getOptionsBuilder(console);
    git("init", "--bare", repoGitDir.toString());
    options.gitDestination.committerEmail = "commiter@email";
    options.gitDestination.committerName = "Bara Kopi";
    destinationFiles = Glob.createGlob(ImmutableList.of("**"));
    partialClone = "False";
    checker = "None";
    url = "file://" + repoGitDir;
    skylark = new SkylarkTestExecutor(options);
    force = false;
    tagName = "test_v1";
    tagMsg = "foo_tag";
    primaryBranch = repo().getPrimaryBranch();
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Before(org.junit.Before)

Example 67 with TestingConsole

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

the class GitDestinationTest method processUserConfirms.

@Test
public void processUserConfirms() throws Exception {
    console = new TestingConsole().respondYes();
    fetch = primaryBranch;
    push = primaryBranch;
    Files.write(workdir.resolve("test.txt"), "some content".getBytes(UTF_8));
    processWithBaselineAndConfirmation(firstCommitWriter(), destinationFiles, new DummyRevision("origin_ref"), /*baseline=*/
    null, /*askForConfirmation=*/
    true);
    String change = git("--git-dir", repoGitDir.toString(), "show", "HEAD");
    // Validate that we really have pushed the commit.
    assertThat(change).contains("test summary");
    console.assertThat().matchesNext(MessageType.PROGRESS, "Git Destination: Fetching: file:.* refs/heads/.*").matchesNext(MessageType.WARNING, "Git Destination: 'refs/heads/.*' doesn't exist in 'file://.*").matchesNext(MessageType.PROGRESS, "Git Destination: Checking out .*").matchesNext(MessageType.PROGRESS, "Git Destination: Adding all files").matchesNext(MessageType.PROGRESS, "Git Destination: Excluding files").matchesNext(MessageType.PROGRESS, "Git Destination: Creating a local commit").matchesNext(MessageType.VERBOSE, "Integrates for.*").matchesNext(MessageType.INFO, "(?m)(\n|.)*test summary(\n|.)+" + "diff --git a/test.txt b/test.txt\n" + "new file mode 100644\n" + "index 0000000\\.\\.f0eec86\n" + "--- /dev/null\n" + "\\+\\+\\+ b/test.txt\n" + "@@ -0,0 \\+1 @@\n" + "\\+some content\n" + "\\\\ No newline at end of file\n").matchesNext(MessageType.WARNING, "Proceed with push to.*[?]").matchesNext(MessageType.PROGRESS, "Git Destination: Pushing to .*").containsNoMoreMessages();
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Example 68 with TestingConsole

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

the class GitHubDestinationTest method setup.

@Before
public void setup() throws Exception {
    console = new TestingConsole();
    options = new OptionsBuilder().setConsole(console).setOutputRootToTmpDir();
    options.testingOptions.checker = new DummyChecker(ImmutableSet.of("bad_word"));
    workdir = Files.createTempDirectory("workdir");
    destinationFiles = Glob.createGlob(ImmutableList.of("**"));
    gitUtil = new GitTestUtil(options);
    gitUtil.mockRemoteGitRepos(new CompleteRefValidator());
    remote = gitUtil.mockRemoteRepo("github.com/foo");
    primaryBranch = remote.getPrimaryBranch();
    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";
    url = "https://github.com/foo";
    force = false;
    fetch = primaryBranch;
    push = primaryBranch;
    skylark = new SkylarkTestExecutor(options);
}
Also used : Path(java.nio.file.Path) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) GitTestUtil(com.google.copybara.testing.git.GitTestUtil) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) DummyChecker(com.google.copybara.testing.DummyChecker) CompleteRefValidator(com.google.copybara.testing.git.GitTestUtil.CompleteRefValidator) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Before(org.junit.Before)

Example 69 with TestingConsole

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

the class GitHubPrOriginTest method setup.

@Before
public void setup() throws Exception {
    repoGitDir = Files.createTempDirectory("GitHubPrDestinationTest-repoGitDir");
    workdir = Files.createTempDirectory("workdir");
    git("init", "--bare", repoGitDir.toString());
    console = new TestingConsole();
    options = new OptionsBuilder().setConsole(console).setOutputRootToTmpDir();
    gitUtil = new GitTestUtil(options);
    gitUtil.mockRemoteGitRepos(new CompleteRefValidator());
    Path credentialsFile = Files.createTempFile("credentials", "test");
    Files.write(credentialsFile, "https://user:SECRET@github.com".getBytes(UTF_8));
    options.git.credentialHelperStorePath = credentialsFile.toString();
    skylark = new SkylarkTestExecutor(options);
}
Also used : Path(java.nio.file.Path) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) GitTestUtil(com.google.copybara.testing.git.GitTestUtil) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) CompleteRefValidator(com.google.copybara.testing.git.GitTestUtil.CompleteRefValidator) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Before(org.junit.Before)

Example 70 with TestingConsole

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

the class GitMirrorTest method setup.

@Before
public void setup() throws Exception {
    workdir = Files.createTempDirectory("workdir");
    console = new TestingConsole();
    options = new OptionsBuilder().setEnvironment(GitTestUtil.getGitEnv().getEnvironment()).setOutputRootToTmpDir().setWorkdirToRealTempDir().setConsole(console);
    originRepo = newBareRepo(Files.createTempDirectory("gitdir"), getGitEnv(), /*verbose=*/
    true, DEFAULT_TIMEOUT, /*noVerify=*/
    false).withWorkTree(Files.createTempDirectory("worktree"));
    originRepo.init();
    destRepo = bareRepo(Files.createTempDirectory("destinationFolder"));
    destRepo.init();
    skylark = new SkylarkTestExecutor(options);
    Files.write(originRepo.getWorkTree().resolve("test.txt"), "some content".getBytes(UTF_8));
    originRepo.add().files("test.txt").run();
    originRepo.simpleCommand("commit", "-m", "first file");
    originRepo.simpleCommand("branch", "other");
    primaryBranch = originRepo.getPrimaryBranch();
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Before(org.junit.Before)

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