|
22 | 22 | */
|
23 | 23 | package org.opengrok.indexer.history;
|
24 | 24 |
|
| 25 | +import org.apache.commons.compress.utils.IOUtils; |
25 | 26 | import org.junit.jupiter.api.AfterAll;
|
26 | 27 | import org.junit.jupiter.api.BeforeAll;
|
27 | 28 | import org.junit.jupiter.api.Test;
|
| 29 | +import org.junit.jupiter.params.ParameterizedTest; |
| 30 | +import org.junit.jupiter.params.provider.MethodSource; |
28 | 31 | import org.opengrok.indexer.condition.EnabledForRepository;
|
29 | 32 | import org.opengrok.indexer.configuration.CommandTimeoutType;
|
30 | 33 | import org.opengrok.indexer.util.TestRepository;
|
31 | 34 |
|
32 | 35 | import java.io.File;
|
33 | 36 | import java.io.IOException;
|
| 37 | +import java.io.InputStream; |
| 38 | +import java.io.OutputStream; |
34 | 39 | import java.io.PrintWriter;
|
35 | 40 | import java.nio.file.Files;
|
36 | 41 | import java.util.Date;
|
@@ -174,4 +179,40 @@ void testDetermineParent() throws Exception {
|
174 | 179 | }
|
175 | 180 | assertEquals(expectedParent, sccsRepository.determineParent(CommandTimeoutType.INDEXER));
|
176 | 181 | }
|
| 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 | + } |
177 | 218 | }
|
0 commit comments