This repository was archived by the owner on Sep 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtest.sh
executable file
·106 lines (84 loc) · 2.99 KB
/
test.sh
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!./node_modules/.bin/bats
# Remember where we started
BASE_DIR=$(dirname $BATS_TEST_DIRNAME)
# Set up a directory to mess around with
TMP_DIRECTORY=$(mktemp -d)
teardown() {
if [ $BATS_TEST_COMPLETED ]; then
echo "Deleting $TMP_DIRECTORY"
rm -rf $TMP_DIRECTORY
else
echo "** Did not delete $TMP_DIRECTORY, as test failed **"
fi
cd $BATS_TEST_DIRNAME
}
assert_output_matches() {
expected="$1"
if [[ ! $output =~ $expected ]]; then
echo $output
false
fi
}
assert_output_doesnt_match() {
expected="$1"
if [[ $output =~ $expected ]]; then
echo $output
false
fi
}
assert_output_contains() {
expected="$1"
if [[ $output != *$expected* ]]; then
echo $output
false
fi
}
assert_output_doesnt_contain() {
expected="$1"
if [[ $output = *$expected$ ]]; then
echo $output
false
fi
}
@test "Should install the Git binary to /tmp/git by default" {
run node -e "require('./index.js')()"
[ "$status" -eq 0 ]
[ -e "/tmp/git/usr/bin/git" ]
rm -rf /tmp/git
}
@test "Should install the Git binary to a given directory" {
run node -e "require('./index.js')({ targetDirectory: '$TMP_DIRECTORY' })"
[ "$status" -eq 0 ]
[ -e "$TMP_DIRECTORY/usr/bin/git" ]
}
@test "Should set the process env by default" {
run node -e "require('./index.js')({ targetDirectory: '$TMP_DIRECTORY' }).then(() => console.log(process.env))"
[ "$status" -eq 0 ]
assert_output_matches ".* PATH: '[^']+$TMP_DIRECTORY/usr/bin'.*"
assert_output_contains " GIT_TEMPLATE_DIR: '$TMP_DIRECTORY/usr/share/git-core/templates'"
assert_output_contains " GIT_EXEC_PATH: '$TMP_DIRECTORY/usr/libexec/git-core'"
}
@test "Should return a promise" {
run node -e "console.log(require('./index.js')({ targetDirectory: '$TMP_DIRECTORY' }))"
[ "$status" -eq 0 ]
assert_output_contains "Promise { <pending> }"
}
@test "Should not change the env, if explicitly asked" {
run node -e "require('./index.js')({ targetDirectory: '$TMP_DIRECTORY', updateEnv: false }).then(() => console.log(process.env))"
[ "$status" -eq 0 ]
assert_output_doesnt_match ".* PATH: '[^']+$TMP_DIRECTORY/usr/bin'.*"
assert_output_doesnt_contain " GIT_TEMPLATE_DIR: '$TMP_DIRECTORY/usr/share/git-core/templates'"
assert_output_doesnt_contain " GIT_EXEC_PATH: '$TMP_DIRECTORY/usr/libexec/git-core'"
}
@test "Should return a promise, if not updating the env" {
run node -e "console.log(require('./index.js')({ targetDirectory: '$TMP_DIRECTORY', updateEnv: false }))"
[ "$status" -eq 0 ]
assert_output_contains "Promise { <pending> }"
}
@test "Should return a promise resolving with the relevant env vars, if not updating the env" {
run node -e "require('./index.js')({ targetDirectory: '$TMP_DIRECTORY', updateEnv: false }).then((result) => console.log(result))"
[ "$status" -eq 0 ]
assert_output_contains " binPath: '$TMP_DIRECTORY/usr/bin'"
assert_output_contains " GIT_TEMPLATE_DIR: '$TMP_DIRECTORY/usr/share/git-core/templates'"
assert_output_contains " GIT_EXEC_PATH: '$TMP_DIRECTORY/usr/libexec/git-core'"
}