aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/test/tst-linux-home.sh
blob: 83c70f405c9d90bc942ec861a12723edcd07f6db (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
43
44
45
46
47
48
49
50
51
_test_should_fail() {
    if [ -z "${CI+y}" ]; then
        fail "Don't run this test locally, it'll mess up your \$HOME"
        return 0
    fi
    if ! command -v git &> /dev/null; then
        fail "git isn't available, assuming running inside a pbuilder"
        return 0
    fi
    return 1
}

_test_should_fail 2> /dev/null && test_should_fail=y

test_run() {
    _test_should_fail && return 1

    readonly src_name=linux-home
    src_url="https://github.com/egor-tensin/$src_name.git"
    readonly src_url

    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_name"

    log "Cloning $src_url to $test_src_dir..."
    git clone -q -- "$src_url" "$test_src_dir"

    test_run_update
    # Again:
    test_run_update

    log "Checking a couple of well-known files..."
    local file
    for file in .gitconfig .ssh/config; do
        local actual
        actual="$( readlink -e -- "$HOME/$file" )"

        local expected
        expected="$test_src_dir/%HOME%/$file"

        if [ "$actual" != "$expected" ]; then
            fail "There was a problem with symlink $file:"
            fail_details "Expected target: $expected"
            fail_details "Actual target: $actual"
            return 1
        fi
    done
}