summaryrefslogtreecommitdiffstatshomepage
path: root/test/tst-root.sh
blob: e31661ef02cd7a3fd2ab0ddf166bd42d3007c60b (plain) (blame)
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
if [ -z "${CI+y}" ] || [ "$EUID" -ne 0 ]; then
    test_should_fail=y
fi

test_run() {
    if [ -z "${CI+y}" ]; then
        fail "Don't run this test locally, it'll mess up your /"
        return 1
    fi
    if [ "$EUID" -ne 0 ]; then
        fail "This test requires root privileges"
        return 1
    fi

    test_root_dir="$( mktemp -d )"
    # mktemp returns /var/..., which is actually in /private/var/... on macOS.
    test_root_dir="$( readlink -e -- "$test_root_dir" )"

    test_src_dir="$test_root_dir/src"

    mkdir -p -- "$test_src_dir/%CONFIG_LINKS_ROOT%/foo"
    mkdir /foo
    chmod 0777 /foo
    touch -- "$test_src_dir/%CONFIG_LINKS_ROOT%/foo/bar.txt"

    test_run_update

    log "Checking /foo/bar.txt..."

    local actual
    actual="$( readlink -e -- "/foo/bar.txt" )"

    local expected
    expected="$test_src_dir/%CONFIG_LINKS_ROOT%/foo/bar.txt"

    if [ "$actual" != "$expected" ]; then
        fail "There was a problem with symlink /foo/bar.txt:"
        fail_details "Expected target: $expected"
        fail_details "Actual target: $actual"
        return 1
    fi
}