forked from KonishchevDmitry/binup
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest
More file actions
executable file
·177 lines (140 loc) · 4.4 KB
/
test
File metadata and controls
executable file
·177 lines (140 loc) · 4.4 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/usr/bin/env bash
#
# Runs tests
#
set -eu
cleanup() {
[ -z "$temp_dir" ] || rm -rf "$temp_dir"
}
cargo test
temp_dir=""
trap cleanup EXIT
trap "exit 1" INT TERM QUIT
temp_dir="$(mktemp -d "/var/tmp/binup-test.XXXXXX")"
os="$(uname | tr '[:upper:]' '[:lower:]')"
if [ "$os" = darwin ]; then
os="macos"
fi
arch="$(arch)"
if [ "$arch" = "x86_64" ]; then
arch="x64"
elif [ "$arch" = "aarch64" ]; then
arch="arm64"
fi
tool=binup
project="KonishchevDmitry/$tool"
release_matcher="$tool-*-$os-$arch.*"
binary_matcher="$tool"
changelog="https://github.com/$project/releases"
install_path="$temp_dir/bin"
custom_install_path="$temp_dir/custom-bin"
post_install_marker_path="$temp_dir/post-install-marker"
post_command="touch '$post_install_marker_path' && echo 'Post-install script stdout' && echo 'Post-install script stderr' >&2"
github_config=""
if [ -n "${GITHUB_TOKEN-}" ]; then
github_config="github: {token: $GITHUB_TOKEN}"
fi
(
cd "$temp_dir"
mkdir bin custom-bin
cat > old-release-mock <<EOF
#!/bin/bash
echo "$tool 0.1.0"
EOF
cat > new-release-mock <<EOF
#!/bin/bash
echo "$tool 100.0.0"
EOF
chmod a+x old-release-mock new-release-mock
touch -c -d 2024-08-01T00:00:00 old-release-mock
cat > "config.yaml" <<EOF
path: $install_path
tools:
$tool:
project: $project
up-to-date:
project: $project
upgradable:
project: $project
prerelease: true
changelog: $changelog
release_matcher: $release_matcher
binary_matcher: $binary_matcher
force_executable: true
version_source: flag
path: $custom_install_path
post: $post_command
$github_config
EOF
)
config_path="$temp_dir/config.yaml"
shasum "$config_path" > "$config_path.checksum"
run() {
cargo run --quiet -- --config "$config_path" "$@"
}
ensure_exists_rm() {
rm "$@"
}
ensure_missing() {
local path
for path in "$@"; do
if [ -e "$path" ]; then
echo "$path exists when not expected to be." >&2
return 1
fi
done
}
# Test work with missing default config
cargo run --quiet -- list
# List with no installed tools
run list
# Should install the tool, but not change the config (fully matches)
for pass in ensure_exists_rm ensure_missing; do
run install upgradable --project "$project" --prerelease \
--release-matcher "$release_matcher" --binary-matcher "$binary_matcher" --force-executable \
--version-source flag --changelog "$changelog" --path "$custom_install_path" --post "$post_command" < /dev/null
"$custom_install_path/upgradable" --help > /dev/null
"$pass" "$post_install_marker_path"
shasum -c "$config_path.checksum" > /dev/null
done
for command in install "install --force" upgrade; do
cp -a "$temp_dir/new-release-mock" "$install_path/up-to-date"
cp -a "$temp_dir/old-release-mock" "$custom_install_path/upgradable"
run $command
(
cd "$temp_dir"
"bin/$tool" --help > /dev/null
if [ "$command" = "install --force" ]; then
cmp bin/up-to-date "bin/$tool"
else
cmp bin/up-to-date new-release-mock
fi
if [ "$command" = install ]; then
shasum "bin/$tool" > checksum
cmp custom-bin/upgradable old-release-mock
ensure_missing "$post_install_marker_path"
else
shasum -c checksum > /dev/null
cmp custom-bin/upgradable "bin/$tool"
ensure_exists_rm "$post_install_marker_path"
fi
)
done
# Should update existing entry, but not reinstall
updated_post_install_marker="$temp_dir/updated-post-install-marker"
yes | run install --project "$project" --post "touch '$updated_post_install_marker'"
ensure_missing "$updated_post_install_marker"
# Should add a new entry and install
new_post_install_marker="$temp_dir/new-post-install-marker"
run install new --project "$project" --force-executable --version-source command --post "touch '$new_post_install_marker'"
ensure_exists_rm "$new_post_install_marker"
# Ensure persistence of the changes
run install --force "$tool" && ensure_exists_rm "$updated_post_install_marker"
run install --force new && ensure_exists_rm "$new_post_install_marker"
# Uninstall simple and complex configurations
cmp "$install_path/new" "$custom_install_path/upgradable"
yes | run uninstall new upgradable
ensure_missing "$install_path/new" "$custom_install_path/upgradable"
run list
run list --local --full
run list --prerelease --full