blob: 1da8dd2a34618d4fe9fd1dd1ae692ad0a9ce3d3e (
plain)
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
|
#!/bin/sh
#
# shUnit2 example for mocking files.
MOCK_PASSWD='' # This will be overridden in oneTimeSetUp().
test_root_uid_from_passed_filename() {
result="$(root_uid_from_passed_filename "${MOCK_PASSWD}")"
assertEquals 'unexpected root uid' '0' "${result}"
}
test_root_uid_from_derived_filename() {
result="$(root_uid_from_derived_filename)"
assertEquals 'unexpected root uid' '0' "${result}"
}
oneTimeSetUp() {
# Provide a mock passwd file for testing. This will be cleaned up
# automatically by shUnit2.
MOCK_PASSWD="${SHUNIT_TMPDIR}/passwd"
cat <<EOF >"${MOCK_PASSWD}"
nobody:*:-2:-2:Unprivileged User:/var/empty:/usr/bin/false
root:*:0:0:System Administrator:/var/root:/bin/sh
daemon:*:1:1:System Services:/var/root:/usr/bin/false
EOF
# Load script under test.
. './mock_file.sh'
}
# Load and run shUnit2.
[ -n "${ZSH_VERSION:-}" ] && SHUNIT_PARENT=$0
. ../shunit2
|