Search in sources :

Example 56 with SkylarkTestExecutor

use of com.google.copybara.testing.SkylarkTestExecutor 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 57 with SkylarkTestExecutor

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

the class GitHubPrOriginTest method testCheckout_noMergeRef_withForce.

@Test
public void testCheckout_noMergeRef_withForce() throws Exception {
    GitRepository remote = withTmpWorktree(gitUtil.mockRemoteRepo("github.com/google/example"));
    String baseRef = addFiles(remote, "base", ImmutableMap.of("test.txt", "a"));
    remote.simpleCommand("branch", "feature");
    String featureRef = addFiles(remote, "commit to feature branch", ImmutableMap.of("test.txt", "c"));
    remote.forceCheckout(baseRef);
    String mainRef = addFiles(remote, "commit to main branch", ImmutableMap.of("test.txt", "b"));
    remote.simpleCommand("merge", "feature");
    String mergeRef = remote.parseRef("HEAD");
    remote.forceCheckout(mainRef);
    remote.simpleCommand("update-ref", GitHubUtil.asHeadRef(123), featureRef);
    remote.simpleCommand("update-ref", GitHubUtil.asMergeRef(123), mergeRef);
    // Using --force should respect "use_merge = True" when a merge commit does exist
    options.setForce(true);
    skylark = new SkylarkTestExecutor(options);
    MockPullRequest.create(gitUtil).setState("open").setPrimaryBranch("main").setPrNumber(123).setMergeable(true).mock();
    GitHubPrOrigin origin = githubPrOrigin("url = 'https://github.com/google/example'", "use_merge = True");
    assertThat(origin.resolve("123").getSha1()).isEqualTo(remote.resolveReference(GitHubUtil.asMergeRef(123)).getSha1());
    assertThat(origin.resolve("123").associatedLabel(GITHUB_PR_USE_MERGE)).containsExactly("true");
    // Using --force should override "use_merge = True", since no merge commit exists
    options.setForce(true);
    skylark = new SkylarkTestExecutor(options);
    // delete the merge commit
    remote.simpleCommand("reset", "--hard", "HEAD~1");
    MockPullRequest.create(gitUtil).setState("open").setPrimaryBranch("main").setPrNumber(123).setMergeable(false).mock();
    origin = githubPrOrigin("url = 'https://github.com/google/example'", "use_merge = True");
    assertThat(origin.resolve("123").getSha1()).isEqualTo(remote.resolveReference(GitHubUtil.asHeadRef(123)).getSha1());
    assertThat(origin.resolve("123").associatedLabel(GITHUB_PR_USE_MERGE)).containsExactly("false");
}
Also used : SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Test(org.junit.Test)

Example 58 with SkylarkTestExecutor

use of com.google.copybara.testing.SkylarkTestExecutor 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 59 with SkylarkTestExecutor

use of com.google.copybara.testing.SkylarkTestExecutor 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)

Example 60 with SkylarkTestExecutor

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

the class GitOriginSubmodulesTest method testRewriteUrl.

@Test
public void testRewriteUrl() throws Exception {
    Path base = Files.createTempDirectory("testRewriteUrl");
    GitRepository r1 = createRepoWithFoo(base, "r1");
    GitRepository r2 = createRepoWithFoo(base, "r2");
    GitRepository r3 = GitRepository.newBareRepo(base.resolve("testRewriteUrl").resolve("r3"), getGitEnv(), false, Duration.ofMinutes(1), false).init();
    r3.fetch("file://" + r1.getGitDir(), false, true, ImmutableList.of("refs/heads/*:refs/heads/*"), false);
    String primaryBranch = r2.getPrimaryBranch();
    OptionsBuilder options = new OptionsBuilder().setConsole(new TestingConsole()).setOutputRootToTmpDir();
    options.git = new GitOptions(options.general) {

        @Override
        public String rewriteSubmoduleUrl(String url) {
            return r3.getGitDir().toString();
        }
    };
    skylark = new SkylarkTestExecutor(options);
    r2.simpleCommand("submodule", "add", "-f", "--name", "r1", "file://" + r1.getWorkTree(), "r1");
    commit(r2, "adding r3->r1 submodule");
    // Nuke r1 to verify r3 is read
    MoreFiles.deleteRecursively(r1.getGitDir());
    GitOrigin origin = origin("file://" + r2.getGitDir(), primaryBranch);
    GitRevision main = origin.resolve(primaryBranch);
    origin.newReader(Glob.ALL_FILES, authoring).checkout(main, checkoutDir);
    FileSubjects.assertThatPath(checkoutDir).containsFiles(GITMODULES).containsFile("r1/foo", "1");
}
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) Test(org.junit.Test)

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