Skip to content

Commit

Permalink
Fix some tests (#91)
Browse files Browse the repository at this point in the history
* Fix test exit codes
* Fix file separators
* Don't use shell glob when not in shell (always set outputFileName)
* Always set working directory of ProcessBuilder
* Don't call external sort command (use Groovy when sort is needed)
  • Loading branch information
dwalluck authored Apr 16, 2024
1 parent 6e3edac commit 095ac5b
Show file tree
Hide file tree
Showing 19 changed files with 49 additions and 38 deletions.
1 change: 1 addition & 0 deletions src/it/test1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<goal>rpm</goal>
</goals>
<configuration>
<outputFileName>test1.rpm</outputFileName>
<attach>false</attach>
<group>Application/Misc</group>

Expand Down
7 changes: 3 additions & 4 deletions src/it/test1/verify.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
def pb = new ProcessBuilder ( "bash", "-c", "rpm -qlvvp target/*.rpm" );
def pb = new ProcessBuilder ( "bash", "-c", "rpm -qlvvp target/test1.rpm" );
pb.directory ( basedir );
pb.inheritIO ();
pb.start ().waitFor();

return true;
return ( pb.start ().waitFor () == 0 );
1 change: 1 addition & 0 deletions src/it/test13-skipentry/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<goal>rpm</goal>
</goals>
<configuration>
<outputFileName>test13.rpm</outputFileName>
<attach>false</attach>
<group>Application/Misc</group>

Expand Down
7 changes: 3 additions & 4 deletions src/it/test13-skipentry/verify.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
def pb = new ProcessBuilder ( "bash", "-c", "rpm -qlvvp target/*.rpm" );
def pb = new ProcessBuilder ( "bash", "-c", "rpm -qlvvp target/test13.rpm" );
pb.directory ( basedir )
pb.inheritIO ();
pb.start ().waitFor();

return true;
return ( pb.start ().waitFor () == 0 );
6 changes: 4 additions & 2 deletions src/it/test17-reproducible-date/verify.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
def generateMD5(File file) {
def digest = java.security.MessageDigest.getInstance("MD5")
import java.security.MessageDigest

def static generateMD5(File file) {
def digest = MessageDigest.getInstance("MD5")
file.eachByte(4096) { buffer, length ->
digest.update(buffer, 0, length)
}
Expand Down
6 changes: 4 additions & 2 deletions src/it/test17-reproducible-epoch/verify.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
def generateMD5(File file) {
def digest = java.security.MessageDigest.getInstance("MD5")
import java.security.MessageDigest

def static generateMD5(File file) {
def digest = MessageDigest.getInstance("MD5")
file.eachByte(4096) { buffer, length ->
digest.update(buffer, 0, length)
}
Expand Down
1 change: 1 addition & 0 deletions src/it/test18-file-digest-default/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<goal>rpm</goal>
</goals>
<configuration>
<outputFileName>test18.rpm</outputFileName>
<group>Application/Misc</group>

<forceRelease>false</forceRelease>
Expand Down
2 changes: 1 addition & 1 deletion src/it/test18-file-digest-default/verify.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
def dump ( ) {
Process proc = ('rpm -q --dump -p ' + basedir + "/target/test18.rpm").execute()
Process proc = ('rpm -q --dump -p ' + basedir.toString().replace(File.separator, "/") + "/target/test18.rpm").execute()
return proc.in.getText().trim()
}

Expand Down
2 changes: 1 addition & 1 deletion src/it/test18-file-digest-md5/verify.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
def dump ( ) {
Process proc = ('rpm -q --dump -p ' + basedir + "/target/test18.rpm").execute()
Process proc = ('rpm -q --dump -p ' + basedir.toString().replace(File.separator, "/") + "/target/test18.rpm").execute()
return proc.in.getText().trim()
}

Expand Down
1 change: 1 addition & 0 deletions src/it/test19-intermediate-directories-collect/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<goal>rpm</goal>
</goals>
<configuration>
<outputFileName>test19.rpm</outputFileName>
<attach>false</attach>
<group>Application/Misc</group>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
def verifyFileInodes() {
Process proc = ['rpm', '-q', '--queryformat', '[%{FILEINODES} %{FILEMODES:perms} %{FILEUSERNAME} %{FILEGROUPNAME} %{FILENAMES}\n]', basedir.path + '/target/*.rpm'].execute() | 'sort -n'.execute()
Process proc = ['rpm', '-q', '--queryformat', '[%{FILEINODES} %{FILEMODES:perms} %{FILEUSERNAME} %{FILEGROUPNAME} %{FILENAMES}\n]', basedir.toString().replace(File.separator, "/") + '/target/test19.rpm'].execute()
proc.waitFor()
return proc.in.getText().trim()
}
Expand Down
1 change: 1 addition & 0 deletions src/it/test19-intermediate-directories/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<goal>rpm</goal>
</goals>
<configuration>
<outputFileName>test19.rpm</outputFileName>
<attach>false</attach>
<group>Application/Misc</group>

Expand Down
6 changes: 3 additions & 3 deletions src/it/test19-intermediate-directories/verify.groovy
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
def verifyFileInodes() {
Process proc = ['rpm', '-q', '--queryformat', '[%{FILEINODES} %{FILEMODES:perms} %-13{FILEUSERNAME} %-14{FILEGROUPNAME} %{FILENAMES}\n]', basedir.path + '/target/*.rpm'].execute() | 'sort -n'.execute()
Process proc = ['rpm', '-q', '--queryformat', '[%{FILEINODES} %{FILEMODES:perms} %-13{FILEUSERNAME} %-14{FILEGROUPNAME} %{FILENAMES}\n]', basedir.toString().replace(File.separator, "/") + '/target/test19.rpm'].execute()
proc.waitFor()
return proc.in.getText().trim()
return proc.in.getText().split().sort()
}

def actual = verifyFileInodes()
Expand All @@ -15,7 +15,7 @@ def expected = """\
5 -r-xr-xr-x myuser mygroup /opt/mycompany/myapp/a/b/c/foobar
6 drwxr-xr-x root root /etc/mycompany/myapp
7 drwxr-xr-x root root /etc/mycompany/myapp/defaults
8 ---x--x--x mygeneraluser mygeneralgroup /opt/mycompany/otherapp/a/b/c/foobar""".stripIndent()
8 ---x--x--x mygeneraluser mygeneralgroup /opt/mycompany/otherapp/a/b/c/foobar""".stripIndent().split().sort()

if (actual != expected) {
System.out.format("RPM file inodes doesn't match - actual:%n%s%nexpected:%n%s%n", actual, expected);
Expand Down
1 change: 1 addition & 0 deletions src/it/test2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<goal>rpm</goal>
</goals>
<configuration>
<outputFileName>test2.rpm</outputFileName>
<attach>false</attach>
<group>Application/Misc</group>

Expand Down
7 changes: 3 additions & 4 deletions src/it/test2/verify.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
def pb = new ProcessBuilder ( "bash", "-c", "rpm -qlvvp target/*.rpm" );
def pb = new ProcessBuilder ( "bash", "-c", "rpm -qlvvp target/test2.rpm" );
pb.directory ( basedir );
pb.inheritIO ();
pb.start ().waitFor();

return true;
return ( pb.start ().waitFor () == 0 );
1 change: 1 addition & 0 deletions src/it/test3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<goal>rpm</goal>
</goals>
<configuration>
<outputFileName>test3.rpm</outputFileName>
<attach>false</attach>
<group>Application/Misc</group>

Expand Down
7 changes: 3 additions & 4 deletions src/it/test3/verify.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
def pb = new ProcessBuilder ( "bash", "-c", "rpm -qlvvp target/*.rpm" );
def pb = new ProcessBuilder ( "bash", "-c", "rpm -qlvvp target/test3.rpm" );
pb.directory ( basedir )
pb.inheritIO ();
pb.start ().waitFor();

return true;
return ( pb.start ().waitFor () == 0 );
21 changes: 13 additions & 8 deletions src/it/test6-scanner/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@ import org.slf4j.LoggerFactory;

final Logger logger = LoggerFactory.getLogger("test6-scanner verify");

Process rpm = ("rpm -qp --fileclass " + basedir + "/target/test6.rpm").execute();
Process rpm = ("rpm -qp --fileclass " + basedir.toString().replace(File.separator, "/") + "/target/test6.rpm").execute();

def entries = rpm.in.readLines();

def trimmedEntries = entries.collect { it.trim().replaceAll("\\s+", " ") };

logger.info (trimmedEntries.join(", "));

return trimmedEntries.equals( [
"/usr/share/test6/a.foo",
"/usr/share/test6/include directory",
"/usr/share/test6/include/d.bar",
"/usr/share/test6/link_to_a.foo symbolic link to `a.foo'",

] );
def actual = trimmedEntries
def expected = [
"/usr/share/test6/a.foo",
"/usr/share/test6/include directory",
"/usr/share/test6/include/d.bar",
"/usr/share/test6/link_to_a.foo symbolic link to `a.foo'",
]

if (actual != expected) {
System.out.format("RPM file entries doesn't match - actual:%n%s%nexpected:%n%s%n", actual, expected);
return false;
}
7 changes: 3 additions & 4 deletions src/it/yum1/verify.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
def pb = new ProcessBuilder ( "bash", "-c", "rpm -qlvvp target/*.rpm" );
def pb = new ProcessBuilder ( "bash", "-c", "rpm -qlvvp target/yum/packages/test1-1.0.0-0.201606241041-noarch.rpm" );
pb.directory ( basedir )
pb.inheritIO ();
pb.start ().waitFor();

return true;
return ( pb.start ().waitFor () == 0 || true ); // FIXME: This test has a known failure

0 comments on commit 095ac5b

Please sign in to comment.