Skip to content

Commit

Permalink
Add some additional tests to cover custom control files.
Browse files Browse the repository at this point in the history
  • Loading branch information
alerosmile committed Jan 10, 2025
1 parent 86d2619 commit 42837f5
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 2 deletions.
48 changes: 46 additions & 2 deletions src/test/java/org/vafer/jdeb/DebMakerTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void visit(TarArchiveEntry entry, byte[] content) throws IOException {
}

@Test
public void testCreationUtf8() throws Exception {
public void testCreationEncoding() throws Exception {
DataProducer[] data = prepareData();
File deb = File.createTempFile("jdeb", ".deb");

Expand All @@ -144,7 +144,7 @@ public void testCreationUtf8() throws Exception {

DebMaker maker = new DebMaker(new NullConsole(), Arrays.asList(data), Arrays.<DataProducer>asList(conffile1, conffile2));

maker.setControl(new File(getClass().getResource("deb/controlutf8").toURI()));
maker.setControl(new File(getClass().getResource("deb/controlencoding").toURI()));
maker.setDeb(deb);

// first step: invalid encoding
Expand Down Expand Up @@ -176,6 +176,28 @@ else if (entry.getName().equals("./postinst") || entry.getName().equals("./prerm
throw new IOException(e);
}
}
else if (entry.getName().startsWith("./shell_")) {
try {
for(String line : org.apache.commons.io.IOUtils.readLines(new ByteArrayInputStream(content), StandardCharsets.UTF_8)) {
if(line.startsWith("# Custom script")) {
assertFalse("the encoding is valid but should be wrong", line.endsWith("created by ジョン"));
}
}
} catch(Exception e) {
throw new IOException(e);
}
}
else if (entry.getName().equals("./text.txt")) {
try {
for(String line : org.apache.commons.io.IOUtils.readLines(new ByteArrayInputStream(content), StandardCharsets.UTF_8)) {
if(line.startsWith("Text file")) {
assertFalse("the encoding is valid but should be wrong", line.endsWith("created by ジョン"));
}
}
} catch(Exception e) {
throw new IOException(e);
}
}
}
});

Expand Down Expand Up @@ -208,6 +230,28 @@ else if (entry.getName().equals("./postinst") || entry.getName().equals("./prerm
throw new IOException(e);
}
}
else if (entry.getName().startsWith("./shell_")) {
try {
for(String line : org.apache.commons.io.IOUtils.readLines(new ByteArrayInputStream(content), StandardCharsets.UTF_8)) {
if(line.startsWith("# Custom script")) {
assertTrue("the encoding is valid but should be wrong", line.endsWith("created by ジョン"));
}
}
} catch(Exception e) {
throw new IOException(e);
}
}
else if (entry.getName().equals("./text.txt")) {
try {
for(String line : org.apache.commons.io.IOUtils.readLines(new ByteArrayInputStream(content), StandardCharsets.UTF_8)) {
if(line.startsWith("Text file")) {
assertTrue("the encoding is valid but should be wrong", line.endsWith("created by ジョン"));
}
}
} catch(Exception e) {
throw new IOException(e);
}
}
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
#
# Custom script created by ジョン
#
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
#
# Custom script created by ジョン
#
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Text file created by ジョン

0 comments on commit 42837f5

Please sign in to comment.