File: package-tarball.bats

package info (click to toggle)
bats 1.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,016 kB
  • sloc: sh: 4,351; makefile: 33; python: 28; xml: 3
file content (51 lines) | stat: -rwxr-xr-x 992 bytes parent folder | download | duplicates (4)
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
48
49
50
51
#!/usr/bin/env bats

setup() {
  export dst_tarball="${BATS_TMPDIR}/dst.tar.gz"
  export src_dir="${BATS_TMPDIR}/src_dir"

  rm -rf "${dst_tarball}" "${src_dir}"
  mkdir "${src_dir}"
  touch "${src_dir}"/{a,b,c}
}

main() {
  bash "${BATS_TEST_DIRNAME}"/package-tarball
}

@test "fail when \$src_dir and \$dst_tarball are unbound" {
  unset src_dir dst_tarball

  run main
  [ "${status}" -ne 0 ]
}

@test "fail when \$src_dir is a non-existent directory" {
  # shellcheck disable=SC2030
  src_dir='not-a-dir'

  run main
  [ "${status}" -ne 0 ]
}

# shellcheck disable=SC2016
@test "pass when \$src_dir directory is empty" {
  # shellcheck disable=SC2031,SC2030
  rm -rf "${src_dir:?}/*"

  run main
  echo "$output"
  [ "${status}" -eq 0 ]
}

# shellcheck disable=SC2016
@test "files in \$src_dir are added to tar archive" {
  run main
  [ "${status}" -eq 0 ]

  run tar tf "$dst_tarball"
  [ "${status}" -eq 0 ]
  [[ "${output}" =~ a ]]
  [[ "${output}" =~ b ]]
  [[ "${output}" =~ c ]]
}