You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SshBasicTestBase.java 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright (C) 2020 Thomas Wolf <thomas.wolf@paranor.ch> and others
  3. *
  4. * This program and the accompanying materials are made available under the
  5. * terms of the Eclipse Distribution License v. 1.0 which is available at
  6. * https://www.eclipse.org/org/documents/edl-v10.php.
  7. *
  8. * SPDX-License-Identifier: BSD-3-Clause
  9. */
  10. package org.eclipse.jgit.junit.ssh;
  11. import static org.junit.Assert.assertEquals;
  12. import static org.junit.Assert.assertFalse;
  13. import static org.junit.Assert.assertTrue;
  14. import java.io.File;
  15. import org.eclipse.jgit.api.Git;
  16. import org.junit.Test;
  17. /**
  18. * Some minimal cloning and fetching tests. Concrete subclasses can implement
  19. * the abstract operations from {@link SshTestHarness} to run with different SSH
  20. * implementations.
  21. */
  22. public abstract class SshBasicTestBase extends SshTestHarness {
  23. protected File defaultCloneDir;
  24. @Override
  25. public void setUp() throws Exception {
  26. super.setUp();
  27. defaultCloneDir = new File(getTemporaryDirectory(), "cloned");
  28. }
  29. @Test
  30. public void testSshCloneWithConfig() throws Exception {
  31. cloneWith("ssh://localhost/doesntmatter", defaultCloneDir, null, //
  32. "Host localhost", //
  33. "HostName localhost", //
  34. "Port " + testPort, //
  35. "User " + TEST_USER, //
  36. "IdentityFile " + privateKey1.getAbsolutePath());
  37. }
  38. @Test
  39. public void testSshFetchWithConfig() throws Exception {
  40. File localClone = cloneWith("ssh://localhost/doesntmatter",
  41. defaultCloneDir, null, //
  42. "Host localhost", //
  43. "HostName localhost", //
  44. "Port " + testPort, //
  45. "User " + TEST_USER, //
  46. "IdentityFile " + privateKey1.getAbsolutePath());
  47. // Do a commit in the upstream repo
  48. try (Git git = new Git(db)) {
  49. writeTrashFile("SomeOtherFile.txt", "Other commit");
  50. git.add().addFilepattern("SomeOtherFile.txt").call();
  51. git.commit().setMessage("New commit").call();
  52. }
  53. // Pull in the clone
  54. try (Git git = Git.open(localClone)) {
  55. File f = new File(git.getRepository().getWorkTree(),
  56. "SomeOtherFile.txt");
  57. assertFalse(f.exists());
  58. git.pull().setRemote("origin").call();
  59. assertTrue(f.exists());
  60. assertEquals("Other commit", read(f));
  61. }
  62. }
  63. }