-
Notifications
You must be signed in to change notification settings - Fork 79
/
Copy pathfetch.bats
executable file
·78 lines (66 loc) · 2.24 KB
/
fetch.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
#!/usr/bin/env bats
load test_helper
export NODE_BUILD_SKIP_MIRROR=1
export NODE_BUILD_CACHE_PATH=
setup() {
export NODE_BUILD_BUILD_PATH="${BATS_TMPDIR}/source"
mkdir -p "${NODE_BUILD_BUILD_PATH}"
}
@test "failed download displays error message" {
stub curl false
install_fixture definitions/without-checksum
assert_failure
assert_output --partial "> http://example.com/packages/package-1.0.0.tar.gz"
assert_output --partial "error: failed to download package-1.0.0.tar.gz"
}
@test "no download tool" {
skip "This test fails on ubuntu-20 for some reason"
export -n NODE_BUILD_HTTP_CLIENT
clean_path="$(remove_commands_from_path curl wget aria2c)"
PATH="$clean_path" install_fixture definitions/without-checksum
assert_failure
assert_output --partial 'error: install `curl`, `wget`, or `aria2c` to download packages'
}
@test "using aria2c if available" {
export NODE_BUILD_ARIA2_OPTS=
export -n NODE_BUILD_HTTP_CLIENT
stub aria2c "--allow-overwrite=true --no-conf=true -o * http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$4"
install_fixture definitions/without-checksum
assert_success
assert_output - <<OUT
Downloading package-1.0.0.tar.gz...
-> http://example.com/packages/package-1.0.0.tar.gz
Installing package-1.0.0...
Installed package-1.0.0 to ${BATS_TMPDIR}/install
OUT
unstub aria2c
}
@test "fetching from git repository" {
stub git "clone --depth 1 --branch main http://example.com/packages/package.git package-dev : mkdir package-dev"
run_inline_definition <<DEF
install_git "package-dev" "http://example.com/packages/package.git" main copy
DEF
assert_success
assert_output - <<OUT
Cloning http://example.com/packages/package.git...
Installing package-dev...
Installed package-dev to ${BATS_TMPDIR}/install
OUT
unstub git
}
@test "updating existing git repository" {
mkdir -p "${NODE_BUILD_BUILD_PATH}/package-dev"
stub git \
"fetch --depth 1 origin +main : true" \
"checkout -q -B main origin/main : true"
run_inline_definition <<DEF
install_git "package-dev" "http://example.com/packages/package.git" main copy
DEF
assert_success
assert_output - <<OUT
Cloning http://example.com/packages/package.git...
Installing package-dev...
Installed package-dev to ${BATS_TMPDIR}/install
OUT
unstub git
}