Skip to content

Commit c0fa79c

Browse files
committed
add test for getHistoryGet()
1 parent 0720cb8 commit c0fa79c

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,20 @@
2222
*/
2323
package org.opengrok.indexer.history;
2424

25+
import org.apache.commons.compress.utils.IOUtils;
2526
import org.junit.jupiter.api.AfterAll;
2627
import org.junit.jupiter.api.BeforeAll;
2728
import org.junit.jupiter.api.Test;
29+
import org.junit.jupiter.params.ParameterizedTest;
30+
import org.junit.jupiter.params.provider.MethodSource;
2831
import org.opengrok.indexer.condition.EnabledForRepository;
2932
import org.opengrok.indexer.configuration.CommandTimeoutType;
3033
import org.opengrok.indexer.util.TestRepository;
3134

3235
import java.io.File;
3336
import java.io.IOException;
37+
import java.io.InputStream;
38+
import java.io.OutputStream;
3439
import java.io.PrintWriter;
3540
import java.nio.file.Files;
3641
import java.util.Date;
@@ -174,4 +179,40 @@ void testDetermineParent() throws Exception {
174179
}
175180
assertEquals(expectedParent, sccsRepository.determineParent(CommandTimeoutType.INDEXER));
176181
}
182+
183+
private static class GetHistoryTestParams {
184+
private final String revision;
185+
private final boolean shouldContain;
186+
187+
GetHistoryTestParams(String revision, boolean shouldContain) {
188+
this.revision = revision;
189+
this.shouldContain = shouldContain;
190+
}
191+
}
192+
193+
private static List<GetHistoryTestParams> getHistoryGetParams() {
194+
return List.of(new GetHistoryTestParams("1.1", false),
195+
new GetHistoryTestParams("1.2", true));
196+
}
197+
198+
/**
199+
* Test of {@link SCCSRepository#getHistoryGet(OutputStream, String, String, String)}.
200+
*/
201+
@ParameterizedTest
202+
@MethodSource("getHistoryGetParams")
203+
void testGetHistoryGet(final GetHistoryTestParams testParams) throws Exception {
204+
try (InputStream inputStream = sccsRepository.getHistoryGet(repositoryRoot.toString(),
205+
"main.c", testParams.revision)) {
206+
assertNotNull(inputStream);
207+
byte[] buffer = new byte[1024];
208+
IOUtils.readFully(inputStream, buffer);
209+
String fileContents = new String(buffer);
210+
final String castedPrintf = "(void)printf";
211+
if (testParams.shouldContain) {
212+
assertTrue(fileContents.contains(castedPrintf));
213+
} else {
214+
assertFalse(fileContents.contains(castedPrintf));
215+
}
216+
}
217+
}
177218
}

0 commit comments

Comments
 (0)