use of com.google.copybara.util.console.testing.TestingConsole in project copybara by google.
the class GitDestinationIntegrateTest method setup.
@Before
public void setup() throws Exception {
repoGitDir = Files.createTempDirectory("GitDestinationTest-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();
options.gitDestination = new GitDestinationOptions(options.general, options.git);
options.gitDestination.committerEmail = "commiter@email";
options.gitDestination.committerName = "Bara Kopi";
destinationFiles = Glob.createGlob(ImmutableList.of("**"), ImmutableList.of("ignore*"));
options.setForce(true);
url = "file://" + repoGitDir;
skylark = new SkylarkTestExecutor(options);
primaryBranch = repo().getPrimaryBranch();
}
use of com.google.copybara.util.console.testing.TestingConsole in project copybara by google.
the class GitDestinationTest method processUserAborts.
@Test
public void processUserAborts() throws Exception {
console = new TestingConsole().respondNo();
fetch = primaryBranch;
push = primaryBranch;
Files.write(workdir.resolve("test.txt"), "some content".getBytes(UTF_8));
ValidationException thrown = assertThrows(ValidationException.class, () -> processWithBaselineAndConfirmation(firstCommitWriter(), destinationFiles, new DummyRevision("origin_ref"), /*baseline=*/
null, /*askForConfirmation=*/
true));
assertThat(thrown).hasMessageThat().contains("User aborted execution: did not confirm diff changes");
}
use of com.google.copybara.util.console.testing.TestingConsole in project copybara by google.
the class GitDestinationTest method processEmptyDiff.
@Test
public void processEmptyDiff() 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_ref1"), /*baseline=*/
null, /*askForConfirmation=*/
true);
// process empty change. Shouldn't ask anything.
assertThrows(EmptyChangeException.class, () -> processWithBaselineAndConfirmation(newWriter(), destinationFiles, new DummyRevision("origin_ref2"), /*baseline=*/
null, /*askForConfirmation=*/
true));
}
use of com.google.copybara.util.console.testing.TestingConsole 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");
git("init", "--bare", repoGitDir.toString());
console = new TestingConsole();
options = new OptionsBuilder().setConsole(console).setForce(true).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();
options.gitDestination = new GitDestinationOptions(options.general, options.git);
options.gitDestination.committerEmail = "commiter@email";
options.gitDestination.committerName = "Bara Kopi";
skylark = new SkylarkTestExecutor(options);
primaryBranchMigration = "False";
}
use of com.google.copybara.util.console.testing.TestingConsole in project copybara by google.
the class GitHubEndpointTest method setup.
@Before
public void setup() throws Exception {
workdir = Jimfs.newFileSystem().getPath("/");
console = new TestingConsole();
OptionsBuilder options = new OptionsBuilder();
options.setConsole(console).setOutputRootToTmpDir();
gitUtil = new GitTestUtil(options);
gitUtil.mockRemoteGitRepos();
dummyTrigger = new DummyTrigger();
options.testingOptions.feedbackTrigger = dummyTrigger;
options.testingOptions.checker = new DummyChecker(ImmutableSet.of("badword"));
gitUtil.mockApi(eq("GET"), contains("master/status"), mockResponse("{\n" + " state : 'failure',\n" + " total_count : 2,\n" + " sha : 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',\n" + " statuses : [\n" + " { state : 'failure', context: 'some/context'},\n" + " { state : 'success', context: 'other/context'}\n" + " ]\n" + "}"));
gitUtil.mockApi(eq("GET"), contains("/commits/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), mockResponse("{\n" + " sha : 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',\n" + " commit : {\n" + " author: { name : 'theauthor', email: 'author@example.com'},\n" + " committer: { name : 'thecommitter', email: 'committer@example.com'},\n" + " message: \"This is a message\\n\\nWith body\\n\"\n" + " },\n" + " committer : { login : 'github_committer'},\n" + " author : { login : 'github_author'}\n" + "}"));
gitUtil.mockApi(eq("POST"), contains("/statuses/e59774"), mockResponse("{\n" + " state : 'success',\n" + " target_url : 'https://github.com/google/example',\n" + " description : 'Observed foo',\n" + " context : 'test'\n" + "}"));
gitUtil.mockApi(anyString(), contains("/git/refs/heads/test"), mockResponse("{\n" + " ref : 'refs/heads/test',\n" + " url : 'https://github.com/google/example/git/refs/heads/test',\n" + " object : { \n" + " type : 'commit',\n" + " sha : 'e597746de9c1704e648ddc3ffa0d2096b146d600', \n" + " url :" + " 'https://github.com/google/example/git/commits/e597746de9c1704e648ddc3ffa0d2096b146d600'\n" + " } \n" + "}"));
gitUtil.mockApi(eq("GET"), contains("git/refs?per_page=100"), mockResponse("[{\n" + " ref : 'refs/heads/test',\n" + " url : 'https://github.com/google/example/git/refs/heads/test',\n" + " object : { \n" + " type : 'commit',\n" + " sha : 'e597746de9c1704e648ddc3ffa0d2096b146d600', \n" + " url :" + " 'https://github.com/google/example/git/commits/e597746de9c1704e648ddc3ffa0d2096b146d600'\n" + " } \n" + "}]"));
gitUtil.mockApi(eq("GET"), contains("commits/e597746de9c1704e648ddc3ffa0d2096b146d610/check-runs"), mockResponse("{\n" + " total_count: 1,\n" + " check_runs: [\n" + " {\n" + " id: 4,\n" + " details_url: 'https://example.com',\n" + " status: 'completed',\n" + " conclusion: 'neutral',\n" + " name: 'mighty_readme',\n" + " output: {\n" + " title: 'Mighty Readme report',\n" + " summary: 'test_summary',\n" + " text: 'test_text'\n" + " },\n" + " app: {\n" + " id: 1,\n" + " slug: 'octoapp',\n" + " name: 'Octocat App'\n" + " }\n" + " }\n" + " ]\n" + "}"));
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);
}
Aggregations