-
Notifications
You must be signed in to change notification settings - Fork 79
/
Copy pathhooks.bats
executable file
·88 lines (75 loc) · 1.96 KB
/
hooks.bats
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env bats
load test_helper
setup() {
export NODENV_ROOT="${BATS_TMPDIR}/nodenv"
export HOOK_PATH="${BATS_TMPDIR}/i has hooks"
mkdir -p "$HOOK_PATH"
}
@test "nodenv-install hooks" {
cat > "${HOOK_PATH}/install.bash" <<OUT
before_install 'echo before: \$PREFIX'
after_install 'echo after: \$STATUS'
OUT
stub nodenv-hooks "install : echo '$HOOK_PATH'/install.bash"
stub nodenv-rehash "echo rehashed"
stub nodenv-version-file "echo .node-version"
definition="${BATS_TMPDIR}/4.0.0"
cat > "$definition" <<<"echo node-build"
run nodenv-install "$definition"
assert_success
assert_output - <<-OUT
before: ${NODENV_ROOT}/versions/4.0.0
node-build
after: 0
rehashed
OUT
}
@test "nodenv-uninstall hooks" {
cat > "${HOOK_PATH}/uninstall.bash" <<OUT
before_uninstall 'echo before: \$PREFIX'
after_uninstall 'echo after.'
rm() {
echo "rm \$@"
command rm "\$@"
}
OUT
stub nodenv-hooks "uninstall : echo '$HOOK_PATH'/uninstall.bash"
stub nodenv-rehash "echo rehashed"
mkdir -p "${NODENV_ROOT}/versions/4.0.0"
run nodenv-uninstall -f 4.0.0
assert_success
assert_output - <<-OUT
before: ${NODENV_ROOT}/versions/4.0.0
rm -rf ${NODENV_ROOT}/versions/4.0.0
rehashed
after.
OUT
refute [ -d "${NODENV_ROOT}/versions/4.0.0" ]
}
@test "nodenv-uninstall hooks are invoked for _each_ uninstalled node" {
cat > "${HOOK_PATH}/uninstall.bash" <<OUT
before_uninstall 'echo before: \$PREFIX'
after_uninstall 'echo after.'
rm() {
echo "rm \$@"
command rm "\$@"
}
OUT
stub nodenv-hooks "uninstall : echo '$HOOK_PATH'/uninstall.bash"
stub nodenv-rehash "echo rehashed"
stub nodenv-rehash "echo rehashed"
mkdir -p "${NODENV_ROOT}/versions/4.1.1"
mkdir -p "${NODENV_ROOT}/versions/4.2.2"
run nodenv-uninstall -f 4.1.1 4.2.2
assert_success
assert_output - <<-OUT
before: ${NODENV_ROOT}/versions/4.1.1
rm -rf ${NODENV_ROOT}/versions/4.1.1
rehashed
after.
before: ${NODENV_ROOT}/versions/4.2.2
rm -rf ${NODENV_ROOT}/versions/4.2.2
rehashed
after.
OUT
}