Skip to content

Commit 501d8c6

Browse files
committed
test: added tests for autoupdate
1 parent 5bf8d32 commit 501d8c6

File tree

3 files changed

+79
-18
lines changed

3 files changed

+79
-18
lines changed

installer-tests/Dockerfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ FROM ubuntu:latest
22

33
RUN set -xe \
44
&& apt-get update \
5-
&& apt-get install -y git \
6-
&& apt-get install -y curl unzip
5+
&& apt-get install -y git expect curl unzip
76

8-
COPY run_tests.sh ./
7+
COPY run_tests.sh autoupdate.exp ./
98

109
ENV TESTS_COMMANDS='installation-test'
1110

installer-tests/autoupdate.exp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/expect -f
2+
#
3+
# This Expect script was generated by autoexpect on Sun May 25 21:05:05 2025
4+
# Expect and autoexpect were both written by Don Libes, NIST.
5+
#
6+
# Note that autoexpect does not guarantee a working script. It
7+
# necessarily has to guess about certain things. Two reasons a script
8+
# might fail are:
9+
#
10+
# 1) timing - A surprising number of programs (rn, ksh, zsh, telnet,
11+
# etc.) and devices discard or ignore keystrokes that arrive "too
12+
# quickly" after prompts. If you find your new script hanging up at
13+
# one spot, try adding a short sleep just before the previous send.
14+
# Setting "force_conservative" to 1 (see below) makes Expect do this
15+
# automatically - pausing briefly before sending each character. This
16+
# pacifies every program I know of. The -c flag makes the script do
17+
# this in the first place. The -C flag allows you to define a
18+
# character to toggle this mode off and on.
19+
20+
set force_conservative 0 ;# set to 1 to force conservative mode even if
21+
;# script wasn't run conservatively originally
22+
if {$force_conservative} {
23+
set send_slow {1 .1}
24+
proc send {ignore arg} {
25+
sleep .1
26+
exp_send -s -- $arg
27+
}
28+
}
29+
30+
#
31+
# 2) differing output - Some programs produce different output each time
32+
# they run. The "date" command is an obvious example. Another is
33+
# ftp, if it produces throughput statistics at the end of a file
34+
# transfer. If this causes a problem, delete these patterns or replace
35+
# them with wildcards. An alternative is to use the -p flag (for
36+
# "prompt") which makes Expect only look for the last line of output
37+
# (i.e., the prompt). The -P flag allows you to define a character to
38+
# toggle this mode off and on.
39+
#
40+
# Read the man page for more info.
41+
#
42+
# -Don
43+
44+
45+
set timeout -1
46+
spawn vuh lv
47+
match_max 100000
48+
expect -exact "\[0;33m(vuh : INPUT) Do you want to get update? (Y/N): \[0m"
49+
send -- "y\r"
50+
expect eof

installer-tests/run_tests.sh

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,16 @@ function installation_test() {
146146
function autoupdate_test() {
147147
_show_function_title "Running autoupdate test ..."
148148

149+
_show_updated_message "Creating temporary vuh src analog ..."
149150
tmp_vuh_src_dir='/opt/old_vuh_simulation'
150151
mkdir -p "$tmp_vuh_src_dir" || exit 1
151-
ls -la "$VUH_SRC_VOLUME"
152152
cp -r "$VUH_SRC_VOLUME/." "$tmp_vuh_src_dir" || exit 1
153-
ls -la "$tmp_vuh_src_dir"
154-
# TODO downgrade versions
153+
154+
_show_updated_message "Creating downgraded version of repository ..."
155+
change_line="VUH_VERSION='"
156+
line_with_downgraded_version="VUH_VERSION='1.0.0'"
157+
downgraded_vuh_file="$(sed "s/VUH_VERSION=.*/VUH_VERSION=\'1\.0\.0\'/" "$tmp_vuh_src_dir/vuh.sh")"
158+
echo "$downgraded_vuh_file" > "$tmp_vuh_src_dir/vuh.sh"
155159

156160
_show_updated_message "Installing vuh using installer.sh .."
157161
".$tmp_vuh_src_dir/installer.sh" -d
@@ -161,18 +165,26 @@ function autoupdate_test() {
161165
git clone "$VUH_REPO_ADDRESS" "$repo_name"
162166
cd "$repo_name" || exit 1
163167

164-
# TODO check update required
165-
166-
# TODO start update
167-
168-
_show_updated_message "Trying to update vuh manually (when update not required) ..."
169-
expecting_already_updated='you already have the latest vuh version'
170-
vuh_update_output="$(vuh --update)" || exit 1
171-
if ! [[ $vuh_update_output =~ $expecting_already_updated ]]; then
172-
_show_error_message "Update command failed!"
173-
_show_error_message "$vuh_update_output"
174-
exit 1
175-
fi
168+
_show_updated_message "Checking vuh installed correctly (downgraded version 1.0.0) ..."
169+
vuh -v || exit 1
170+
171+
_show_updated_message "Check autoupdate initialized ..."
172+
"./../autoupdate.exp" || exit 1
173+
174+
_show_updated_message "Checking vuh updated correctly (downgraded version 1.0.0) ..."
175+
vuh -v || exit 1
176+
[ "$(vuh -v)" != '1.0.0' ] || exit 1
177+
178+
# TODO uncomment in next release
179+
# _show_updated_message "Trying to update vuh manually (when update not required) ..."
180+
# expecting_already_updated='you already have the latest vuh version'
181+
# vuh_update_output="$(vuh --update)" || exit 1
182+
# echo "vuh_update_output: $vuh_update_output"
183+
# if ! [[ $vuh_update_output =~ $expecting_already_updated ]]; then
184+
# _show_error_message "Update command failed!"
185+
# _show_error_message "$vuh_update_output"
186+
# exit 1
187+
# fi
176188

177189
_show_success_message "Autoupdate tests successfully finished."
178190
}

0 commit comments

Comments
 (0)