Skip to content

Commit a3f9b4f

Browse files
committed
Fix SshKeysDispatcher test failing on Windows
The `SshKeysDispatcher` tests that use the keys list command are failing on Windows because they assume a Unix line ending after each key. But the command will use a system line ending. So this fix uses system line endings in the reference string for the assert, too. In addition, two `assertTrue(false)´ are replaced with a proper `fail`.
1 parent cb89090 commit a3f9b4f

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/test/java/com/gitblit/tests/SshKeysDispatcherTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void testKeysListCommand() throws Exception {
3737
String result = testSshCommand("keys ls -L");
3838
List<SshKey> keys = getKeyManager().getKeys(username);
3939
assertEquals(String.format("There are %d keys!", keys.size()), 2, keys.size());
40-
assertEquals(keys.get(0).getRawData() + "\n" + keys.get(1).getRawData(), result);
40+
assertEquals(String.format("%s%n%s", keys.get(0).getRawData(), keys.get(1).getRawData()), result);
4141
}
4242

4343
@Test
@@ -64,9 +64,9 @@ public void testKeysRmAllByIndexCommand() throws Exception {
6464
assertEquals(String.format("There are %d keys!", keys.size()), 0, keys.size());
6565
try {
6666
testSshCommand("keys ls -L");
67-
assertTrue("Authentication worked without a public key?!", false);
67+
fail("Authentication worked without a public key?!");
6868
} catch (AssertionError e) {
69-
assertTrue(true);
69+
// expected
7070
}
7171
}
7272

@@ -77,9 +77,9 @@ public void testKeysRmAllCommand() throws Exception {
7777
assertEquals(String.format("There are %d keys!", keys.size()), 0, keys.size());
7878
try {
7979
testSshCommand("keys ls -L");
80-
assertTrue("Authentication worked without a public key?!", false);
80+
fail("Authentication worked without a public key?!");
8181
} catch (AssertionError e) {
82-
assertTrue(true);
82+
// expected
8383
}
8484
}
8585

@@ -96,9 +96,9 @@ public void testKeysAddCommand() throws Exception {
9696
StringBuilder sb = new StringBuilder();
9797
for (SshKey sk : keys) {
9898
sb.append(sk.getRawData());
99-
sb.append('\n');
99+
sb.append(System.getProperty("line.separator", "\n"));
100100
}
101-
sb.setLength(sb.length() - 1);
101+
sb.setLength(sb.length() - System.getProperty("line.separator", "\n").length());
102102
assertEquals(sb.toString(), result);
103103
}
104104

0 commit comments

Comments
 (0)