File: mock_file_test.sh

package info (click to toggle)
shunit2 2.1.8-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 648 kB
  • sloc: sh: 1,752; makefile: 15
file content (33 lines) | stat: -rwxr-xr-x 903 bytes parent folder | download
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.
  . './examples/mock_file.sh'
}

# Load and run shUnit2.
[ -n "${ZSH_VERSION:-}" ] && SHUNIT_PARENT=$0
. shunit2