Skip to content

Commit 0720cb8

Browse files
committed
add tests for determineParent()
1 parent 45b9e72 commit 0720cb8

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/history/SCCSRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public class SCCSRepository extends Repository {
5858
*/
5959
public static final String CMD_FALLBACK = "sccs";
6060

61-
private static final String CODEMGR_WSDATA = "Codemgr_wsdata";
61+
static final String CODEMGR_WSDATA = "Codemgr_wsdata";
6262

6363
public SCCSRepository() {
6464
type = "SCCS";

opengrok-indexer/src/test/java/org/opengrok/indexer/history/SCCSRepositoryTest.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@
2626
import org.junit.jupiter.api.BeforeAll;
2727
import org.junit.jupiter.api.Test;
2828
import org.opengrok.indexer.condition.EnabledForRepository;
29+
import org.opengrok.indexer.configuration.CommandTimeoutType;
2930
import org.opengrok.indexer.util.TestRepository;
3031

3132
import java.io.File;
3233
import java.io.IOException;
34+
import java.io.PrintWriter;
3335
import java.nio.file.Files;
3436
import java.util.Date;
3537
import java.util.List;
@@ -38,6 +40,7 @@
3840
import static org.junit.jupiter.api.Assertions.assertEquals;
3941
import static org.junit.jupiter.api.Assertions.assertFalse;
4042
import static org.junit.jupiter.api.Assertions.assertNotNull;
43+
import static org.junit.jupiter.api.Assertions.assertNull;
4144
import static org.junit.jupiter.api.Assertions.assertTrue;
4245
import static org.opengrok.indexer.condition.RepositoryInstalled.Type.SCCS;
4346

@@ -139,4 +142,36 @@ void testGetHistory() throws Exception {
139142
History expectedHistory = new History(entries);
140143
assertEquals(expectedHistory, history);
141144
}
145+
146+
/**
147+
* Negative test of {@link SCCSRepository#determineParent(CommandTimeoutType)}.
148+
*/
149+
@Test
150+
void testDetermineParentInvalid() throws Exception {
151+
File codemgrDir = new File(repositoryRoot, SCCSRepository.CODEMGR_WSDATA);
152+
assertTrue(codemgrDir.mkdirs());
153+
File parentFile = new File(codemgrDir, "parent");
154+
assertTrue(parentFile.createNewFile());
155+
try (PrintWriter out = new PrintWriter(parentFile.toString())) {
156+
out.println("foo");
157+
}
158+
assertNull(sccsRepository.determineParent(CommandTimeoutType.INDEXER));
159+
}
160+
161+
/**
162+
* Test of {@link SCCSRepository#determineParent(CommandTimeoutType)}.
163+
*/
164+
@Test
165+
void testDetermineParent() throws Exception {
166+
File codemgrDir = new File(repositoryRoot, SCCSRepository.CODEMGR_WSDATA);
167+
assertTrue(codemgrDir.mkdirs());
168+
File parentFile = new File(codemgrDir, "parent");
169+
assertTrue(parentFile.createNewFile());
170+
final String expectedParent = "/foo";
171+
try (PrintWriter out = new PrintWriter(parentFile.toString())) {
172+
out.println("VERSION 1");
173+
out.println(expectedParent);
174+
}
175+
assertEquals(expectedParent, sccsRepository.determineParent(CommandTimeoutType.INDEXER));
176+
}
142177
}

0 commit comments

Comments
 (0)