-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathhash_md5_test.sh
More file actions
47 lines (41 loc) · 1.04 KB
/
Copy pathhash_md5_test.sh
File metadata and controls
47 lines (41 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
. ./assert.sh
. ./is_command.sh
. ./echoerr.sh
. ./log.sh
. ./hash_md5.sh
test1() {
want="14758f1afd44c09b7992073ccf00b43d"
got=$(echo foobar | hash_md5)
assertEquals "$want" "$got" "test1: md5 via stdin"
}
test2() {
want="14758f1afd44c09b7992073ccf00b43d"
got=$(hash_md5 fixtures/sample1.txt)
assertEquals "$want" "$got" "test2: md5 via file"
}
test3() {
assertFalse "hash_md5 NONEXISTANT" "test3: non-existent file returns not 0"
}
test1
test2
test3
# --- openssl fallback (was a TODO in hash_md5.sh) -------------------------
test4() {
if ! command -v openssl >/dev/null 2>&1; then
assert_skip "test4: openssl not installed"
return 0
fi
is_command() {
case "$1" in
md5sum | md5) return 1 ;;
*) command -v "$1" >/dev/null ;;
esac
}
want="14758f1afd44c09b7992073ccf00b43d"
got=$(echo foobar | hash_md5)
assertEquals "$want" "$got" "test4: openssl fallback via stdin"
got=$(hash_md5 fixtures/sample1.txt)
assertEquals "$want" "$got" "test4a: openssl fallback via file"
. ./is_command.sh
}
test4