Skip to content

Commit

Permalink
Fixed off-by-one error, test-coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
lukashinsch committed Mar 28, 2015
1 parent 4fa1052 commit f5e66c1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void tailContent(Path folder, String filename, OutputStream stream, int l
int i = 0;
String line;
List<String> content = new ArrayList<>();
while ((line = reader.readLine()) != null && i++ <= lines) {
while ((line = reader.readLine()) != null && i++ < lines) {
content.add(line);
}
Collections.reverse(content);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,17 @@ private void createZipArchive(String archiveFileName, String contentFileName, St
}
}

@Test(expected = UnsupportedOperationException.class)
public void shouldThrowExceptionWhenCallingTailForZip() throws Exception {
// given
createZipArchive("file.zip", "A.log", "content");

// when
logViewEndpoint.view("A.log", "file.zip", 1, response);

// then -> exception
}

@Test
public void shouldListTarGzContent() throws Exception {
// given
Expand Down Expand Up @@ -264,6 +275,17 @@ public void shouldViewTarGzFileContent() throws Exception {
assertThat(new String(outputStream.toByteArray()), is("content"));
}

@Test(expected = UnsupportedOperationException.class)
public void shouldThrowExceptionWhenCallingTailForTarGz() throws Exception {
// given
createTarGzArchive("file.tar.gz", "A.log", "content");

// when
logViewEndpoint.view("A.log", "file.tar.gz", 1, response);

// then -> exception
}

private void createTarGzArchive(String archiveFileName, String contentFileName, String content) throws Exception {

try(TarArchiveOutputStream tos = new TarArchiveOutputStream(new GZIPOutputStream(
Expand Down Expand Up @@ -326,6 +348,20 @@ public void shouldViewFile() throws Exception {
assertThat(new String(outputStream.toByteArray()), is("abc"));
}

@Test
public void shouldTailViewOnlyLastLine() throws Exception {
// given
createFile("file.log", "line1" + System.lineSeparator() + "line2" + System.lineSeparator(), now);
ByteArrayServletOutputStream outputStream = mockResponseOutputStream();

// when
logViewEndpoint.view("file.log", null, 1, response);

// then
assertThat(new String(outputStream.toByteArray()), not(containsString("line1")));
assertThat(new String(outputStream.toByteArray()), containsString("line2"));
}

@Test
public void shouldSearchInFiles() throws Exception {
// given
Expand Down

0 comments on commit f5e66c1

Please sign in to comment.