aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.junit.ssh/src/org/eclipse/jgit/junit/ssh/SshBasicTestBase.java
blob: da84b0ea7d81eef895be5cb542547aefbc9468bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
 * Copyright (C) 2020 Thomas Wolf <thomas.wolf@paranor.ch> and others
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Distribution License v. 1.0 which is available at
 * https://www.eclipse.org/org/documents/edl-v10.php.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */
package org.eclipse.jgit.junit.ssh;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.io.File;

import org.eclipse.jgit.api.Git;
import org.junit.Test;

/**
 * Some minimal cloning and fetching tests. Concrete subclasses can implement
 * the abstract operations from {@link SshTestHarness} to run with different SSH
 * implementations.
 *
 * @since 5.11
 */
public abstract class SshBasicTestBase extends SshTestHarness {

	protected File defaultCloneDir;

	@Override
	public void setUp() throws Exception {
		super.setUp();
		defaultCloneDir = new File(getTemporaryDirectory(), "cloned");
	}

	@Test
	public void testSshCloneWithConfig() throws Exception {
		cloneWith("ssh://localhost/doesntmatter", defaultCloneDir, null, //
				"Host localhost", //
				"HostName localhost", //
				"Port " + testPort, //
				"User " + TEST_USER, //
				"IdentityFile " + privateKey1.getAbsolutePath());
	}

	@Test
	public void testSshFetchWithConfig() throws Exception {
		File localClone = cloneWith("ssh://localhost/doesntmatter",
				defaultCloneDir, null, //
				"Host localhost", //
				"HostName localhost", //
				"Port " + testPort, //
				"User " + TEST_USER, //
				"IdentityFile " + privateKey1.getAbsolutePath());
		// Do a commit in the upstream repo
		try (Git git = new Git(db)) {
			writeTrashFile("SomeOtherFile.txt", "Other commit");
			git.add().addFilepattern("SomeOtherFile.txt").call();
			git.commit().setMessage("New commit").call();
		}
		// Pull in the clone
		try (Git git = Git.open(localClone)) {
			File f = new File(git.getRepository().getWorkTree(),
					"SomeOtherFile.txt");
			assertFalse(f.exists());
			git.pull().setRemote("origin").call();
			assertTrue(f.exists());
			assertEquals("Other commit", read(f));
		}
	}
}