Skip to content

Commit

Permalink
Make HashDigestTests portable by removing absolute prefix of test path
Browse files Browse the repository at this point in the history
Partially fixes ERDDAP#140
  • Loading branch information
srstsavage committed Apr 12, 2024
1 parent 540c170 commit 204852b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/test/java/com/cohort/util/HashDigestTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ class HashDigestTests {
void basicTest() throws Throwable {
System.out.println("*** HashDigest.basicTest");
String tName = HashDigestTests.class.getResource("LICENSE.txt").getPath();
String projectDir = File2.getCurrentDirectory();
//remove projectDir prefix from absolute tName path to make tests portable
if (tName.startsWith(projectDir)) {
tName = tName.substring(projectDir.length());
}
Test.ensureEqual(HashDigest.doIt(new String[] { "type:MD5" }),
"Neither password or filename was specified.\n" + HashDigest.usage, "");
Test.ensureEqual(HashDigest.doIt(new String[] { "password:myPassword", "type:MD-5" }),
Expand All @@ -19,13 +24,13 @@ void basicTest() throws Throwable {
Test.ensureEqual(HashDigest.doIt(new String[] { "password:myPassword", "type:SHA-256" }),
"76549b827ec46e705fd03831813fa52172338f0dfcbd711ed44b81a96dac51c6", "");
Test.ensureEqual(HashDigest.doIt(new String[] { "filename:" + tName, "type:MD5" }),
"96e9b4d974b734874a66f433b276a41a", "");
"327fbb2aa6c6297d4fdd5fdf4b14e289", "");
Test.ensureEqual(HashDigest.doIt(new String[] { "filename:" + tName, "type:SHA-256" }),
"f6afea3f5fa69c8e54b14b3fdb86a9aa261a423cea957c9c87b55b92441d56bb", "");
"e376c88953b2d56b00783fed071f1875e8ed94230f4e14eee5bce8bd608de5e6", "");
Test.ensureEqual(HashDigest.doIt(new String[] { "filename:" + tName, "type:SHA-256", "-file" }),
"Created " + tName + ".sha256", "");
Test.ensureEqual(File2.readFromFileUtf8(tName + ".sha256")[1],
"f6afea3f5fa69c8e54b14b3fdb86a9aa261a423cea957c9c87b55b92441d56bb LICENSE.txt\n", "");
"e376c88953b2d56b00783fed071f1875e8ed94230f4e14eee5bce8bd608de5e6 LICENSE.txt\n", "");
File2.delete(tName + ".sha256");
}
}

0 comments on commit 204852b

Please sign in to comment.