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 12 import static org.junit.Assert.assertEquals; 13 import static org.junit.Assert.assertFalse; 14 import static org.junit.Assert.assertTrue; 15 16 import java.io.File; 17 18 import org.eclipse.jgit.api.Git; 19 import org.junit.Test; 20 21 /** 22 * Some minimal cloning and fetching tests. Concrete subclasses can implement 23 * the abstract operations from {@link SshTestHarness} to run with different SSH 24 * implementations. 25 */ 26 public abstract class SshBasicTestBase extends SshTestHarness { 27 28 protected File defaultCloneDir; 29 30 @Override setUp()31 public void setUp() throws Exception { 32 super.setUp(); 33 defaultCloneDir = new File(getTemporaryDirectory(), "cloned"); 34 } 35 36 @Test testSshCloneWithConfig()37 public void testSshCloneWithConfig() throws Exception { 38 cloneWith("ssh://localhost/doesntmatter", defaultCloneDir, null, // 39 "Host localhost", // 40 "HostName localhost", // 41 "Port " + testPort, // 42 "User " + TEST_USER, // 43 "IdentityFile " + privateKey1.getAbsolutePath()); 44 } 45 46 @Test testSshFetchWithConfig()47 public void testSshFetchWithConfig() throws Exception { 48 File localClone = cloneWith("ssh://localhost/doesntmatter", 49 defaultCloneDir, null, // 50 "Host localhost", // 51 "HostName localhost", // 52 "Port " + testPort, // 53 "User " + TEST_USER, // 54 "IdentityFile " + privateKey1.getAbsolutePath()); 55 // Do a commit in the upstream repo 56 try (Git git = new Git(db)) { 57 writeTrashFile("SomeOtherFile.txt", "Other commit"); 58 git.add().addFilepattern("SomeOtherFile.txt").call(); 59 git.commit().setMessage("New commit").call(); 60 } 61 // Pull in the clone 62 try (Git git = Git.open(localClone)) { 63 File f = new File(git.getRepository().getWorkTree(), 64 "SomeOtherFile.txt"); 65 assertFalse(f.exists()); 66 git.pull().setRemote("origin").call(); 67 assertTrue(f.exists()); 68 assertEquals("Other commit", read(f)); 69 } 70 } 71 } 72