Skip to content

Commit 0241b5b

Browse files
idodeclareVladimir Kotal
authored andcommitted
Fix tests for Windows
1 parent 6a2061f commit 0241b5b

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/web/Util.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -842,10 +842,15 @@ public static String uid2url(String uid) {
842842
return url.substring(0, url.lastIndexOf(PATH_SEPARATOR)); // remove date from end
843843
}
844844

845+
/**
846+
* Sanitizes Windows path delimiters (if {@link PlatformUtils#isWindows()}
847+
* is {@code true}) as
848+
* {@link org.opengrok.indexer.index.Indexer#PATH_SEPARATOR} in order not
849+
* to conflict with the Lucene escape character and also so {@code path}
850+
* appears as a correctly formed URI in search results.
851+
*/
845852
public static String fixPathIfWindows(String path) {
846-
if (PlatformUtils.isWindows()) {
847-
// Sanitize Windows path delimiters in order not to conflict with Lucene escape character
848-
// and also so the path appears as correctly formed URI in the search results.
853+
if (path != null && PlatformUtils.isWindows()) {
849854
return path.replace(File.separatorChar, PATH_SEPARATOR);
850855
}
851856
return path;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
/*
2121
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
22-
* Portions Copyright (c) 2019, Chris Fraire <cfraire@me.com>.
22+
* Portions Copyright (c) 2019-2020, Chris Fraire <cfraire@me.com>.
2323
*/
2424
package org.opengrok.indexer.history;
2525

@@ -41,6 +41,7 @@
4141
import org.junit.BeforeClass;
4242
import org.junit.Test;
4343
import org.opengrok.indexer.util.TestRepository;
44+
import org.opengrok.indexer.web.Util;
4445

4546
/**
4647
* @author austvik
@@ -114,7 +115,7 @@ public void shouldHandleMergeCommits() throws Exception {
114115

115116
SortedSet<String> f0 = e0.getFiles();
116117
assertEquals("e[0] files size", 1, f0.size());
117-
assertEquals("e[0] files[0]", "/contrib/serf/STATUS", f0.first());
118+
assertEquals("e[0] files[0]", "/contrib/serf/STATUS", Util.fixPathIfWindows(f0.first()));
118119
}
119120

120121
/**

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
/*
2121
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
22-
* Portions Copyright (c) 2019, Chris Fraire <cfraire@me.com>.
22+
* Portions Copyright (c) 2019-2020, Chris Fraire <cfraire@me.com>.
2323
*/
2424
package org.opengrok.indexer.history;
2525

@@ -35,11 +35,13 @@
3535
import org.opengrok.indexer.condition.ConditionalRunRule;
3636
import org.opengrok.indexer.condition.RepositoryInstalled;
3737
import org.opengrok.indexer.util.TestRepository;
38+
import org.opengrok.indexer.web.Util;
3839

3940
import java.io.File;
4041
import java.util.List;
4142
import java.util.SortedSet;
4243
import java.util.TreeSet;
44+
import java.util.stream.Collectors;
4345

4446
/**
4547
* @author austvik
@@ -178,20 +180,21 @@ public void testOctopusHistory() throws Exception {
178180

179181
SortedSet<String> allFiles = new TreeSet<>();
180182
for (HistoryEntry entry : entries) {
181-
allFiles.addAll(entry.getFiles());
183+
allFiles.addAll(entry.getFiles().stream().map(Util::fixPathIfWindows).
184+
collect(Collectors.toList()));
182185
}
183186

184-
assertTrue("contains /git-octopus/d", allFiles.contains("/git-octopus/d"));
185-
assertTrue("contains /git-octopus/c", allFiles.contains("/git-octopus/c"));
186-
assertTrue("contains /git-octopus/b", allFiles.contains("/git-octopus/b"));
187-
assertTrue("contains /git-octopus/a", allFiles.contains("/git-octopus/a"));
188-
assertEquals("git-octopus four files from log", 4, allFiles.size());
187+
assertTrue("should contain /git-octopus/d", allFiles.contains("/git-octopus/d"));
188+
assertTrue("should contain /git-octopus/c", allFiles.contains("/git-octopus/c"));
189+
assertTrue("should contain /git-octopus/b", allFiles.contains("/git-octopus/b"));
190+
assertTrue("should contain /git-octopus/a", allFiles.contains("/git-octopus/a"));
191+
assertEquals("git-octopus files from log", 4, allFiles.size());
189192

190193
HistoryEntry first = entries.get(0);
191194
assertEquals("should be merge commit hash", "206f862b", first.getRevision());
192195
assertEquals("should be merge commit message",
193196
"Merge branches 'file_a', 'file_b' and 'file_c' into master, and add d",
194197
first.getMessage());
195-
assertEquals("git-octopus four files for merge", 4, first.getFiles().size());
198+
assertEquals("git-octopus files for merge", 4, first.getFiles().size());
196199
}
197200
}

0 commit comments

Comments
 (0)