File: 65-assert-10-assert_symlink_to.bats

package info (click to toggle)
bats-file 0.3.0%2Bgit20230131-gbba751f-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 408 kB
  • sloc: sh: 566; makefile: 2
file content (31 lines) | stat: -rw-r--r-- 1,072 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
#!/usr/bin/env bats
load 'test_helper'
fixtures 'symlink'

setup () {
 touch ${TEST_FIXTURE_ROOT}/file ${TEST_FIXTURE_ROOT}/notasymlink
 ln -s ${TEST_FIXTURE_ROOT}/file ${TEST_FIXTURE_ROOT}/symlink
 
}
teardown () {
    rm -f ${TEST_FIXTURE_ROOT}/file ${TEST_FIXTURE_ROOT}/notasymlink ${TEST_FIXTURE_ROOT}/symlink
}

# Correctness
@test 'assert_symlink_to() <file> <link>: returns 0 if <link> exists and is a symbolic link to <file>' {
  local -r file="${TEST_FIXTURE_ROOT}/file"
  local -r link="${TEST_FIXTURE_ROOT}/symlink"
  run assert_symlink_to $file $link
  [ "$status" -eq 0 ]
  [ "${#lines[@]}" -eq 0 ]
}
@test 'assert_symlink_to() <file> <link>: returns 1 and displays path if <link> is not a symbolic link to <file>' {
  local -r file="${TEST_FIXTURE_ROOT}/dir/file.does_not_exists"
  local -r link="${TEST_FIXTURE_ROOT}/symlink"
  run assert_symlink_to $file $link
  [ "$status" -eq 1 ]
  [ "${#lines[@]}" -eq 3 ]
  [ "${lines[0]}" == '-- symbolic link does not have the correct target --' ]
  [ "${lines[1]}" == "path : $link" ]
  [ "${lines[2]}" == '--' ]
}