Skip to content
This repository was archived by the owner on Oct 1, 2025. It is now read-only.

Commit e72dce9

Browse files
committed
refactor(spread): create reusable test functions for experiments
Refactor the spread tests to introduce library functions which can ensure the presence/absence of particular experiments on a machine, such as `ensure_coreutils_installed`, or `ensure_sudors_absent`.
1 parent 9370753 commit e72dce9

File tree

13 files changed

+132
-147
lines changed

13 files changed

+132
-147
lines changed

spread.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ backends:
1414
lxc launch \
1515
"${SPREAD_SYSTEM/-/:}" \
1616
"${CONTAINER_NAME}" \
17-
-c user.user-data="$(sed "s|SPREAD_PASSWORD|$SPREAD_PASSWORD|g" tests/cloud-config.yaml)"
17+
-c user.user-data="$(sed "s|SPREAD_PASSWORD|$SPREAD_PASSWORD|g" tests/lib/cloud-config.yaml)"
1818
1919
# Wait for the spread user
2020
while ! lxc exec "${CONTAINER_NAME}" -- id -u spread &>/dev/null; do sleep 0.5; done
@@ -60,5 +60,3 @@ prepare: |
6060
fi
6161
6262
install -Dm755 "$PWD/target/debug/oxidizr" /usr/bin/oxidizr
63-
64-
pushd "${SPREAD_PATH}/${SPREAD_TASK}"

tests/disable-all/task.yaml

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,13 @@
1-
summary: Test disabling experiments
1+
summary: Test disabling all experiments
22
execute: |
3+
source ${SPREAD_PATH}/tests/lib/uutils.sh
4+
source ${SPREAD_PATH}/tests/lib/sudo-rs.sh
5+
36
oxidizr enable --yes --all
47
oxidizr disable --yes --all
58
6-
apt list rust-coreutils | NOMATCH installed
7-
ls -la /usr/bin/date | NOMATCH "/usr/bin/date -> /usr/bin/coreutils"
8-
ls -la /usr/bin | NOMATCH ".date.oxidizr.bak"
9-
date --help | MATCH "GNU"
10-
11-
apt list rust-findutils | NOMATCH installed
12-
ls -la /usr/bin/find | NOMATCH "/usr/bin/find -> /usr/lib/cargo/bin/findutils/find"
13-
ls -la /usr/bin | NOMATCH ".find.oxidizr.bak"
14-
find --help | MATCH "GNU"
15-
16-
if [[ "$(lsb_release -rs)" != "24.04" ]]; then
17-
apt list rust-diffutils | NOMATCH installed
18-
ls -la /usr/bin/diff | NOMATCH "/usr/bin/diff -> /usr/lib/cargo/bin/diffutils/diff"
19-
ls -la /usr/bin | NOMATCH ".diff.oxidizr.bak"
20-
diff --help | MATCH "GNU"
21-
fi
22-
23-
apt list sudo-rs | NOMATCH installed
24-
25-
ls -la /usr/bin/sudo | NOMATCH "/usr/bin/sudo -> /usr/lib/cargo/bin/sudo"
26-
ls -la /usr/bin | NOMATCH ".sudo.oxidizr.bak"
27-
/usr/bin/sudo --version 2>&1 | NOMATCH "sudo-rs"
28-
29-
ls -la /usr/bin/su | NOMATCH "/usr/bin/su -> /usr/lib/cargo/bin/su"
30-
ls -la /usr/bin | NOMATCH ".su.oxidizr.bak"
31-
/usr/bin/su --version 2>&1 | NOMATCH "su-rs"
9+
ensure_coreutils_absent
10+
ensure_findutils_absent
11+
ensure_diffutils_absent
3212
33-
ls -la /usr/sbin/visudo | NOMATCH "/usr/sbin/visudo -> /usr/lib/cargo/bin/visudo"
34-
ls -la /usr/sbin | NOMATCH ".visudo.oxidizr.bak"
13+
ensure_sudors_absent

tests/disable-default/task.yaml

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
1-
summary: Test disabling experiments
1+
summary: Test disabling default experiments
22
execute: |
3+
source ${SPREAD_PATH}/tests/lib/uutils.sh
4+
source ${SPREAD_PATH}/tests/lib/sudo-rs.sh
5+
36
oxidizr enable --yes
47
oxidizr disable --yes
58
6-
apt list rust-coreutils | NOMATCH installed
7-
ls -la /usr/bin/date | NOMATCH "/usr/bin/date -> /usr/bin/coreutils"
8-
ls -la /usr/bin | NOMATCH ".date.oxidizr.bak"
9-
date --help | MATCH "GNU"
10-
11-
apt list sudo-rs | NOMATCH installed
12-
13-
ls -la /usr/bin/sudo | NOMATCH "/usr/bin/sudo -> /usr/lib/cargo/bin/sudo"
14-
ls -la /usr/bin | NOMATCH ".sudo.oxidizr.bak"
15-
/usr/bin/sudo --version 2>&1 | NOMATCH "sudo-rs"
16-
17-
ls -la /usr/bin/su | NOMATCH "/usr/bin/su -> /usr/lib/cargo/bin/su"
18-
ls -la /usr/bin | NOMATCH ".su.oxidizr.bak"
19-
/usr/bin/su --version 2>&1 | NOMATCH "su-rs"
20-
21-
ls -la /usr/sbin/visudo | NOMATCH "/usr/sbin/visudo -> /usr/lib/cargo/bin/visudo"
22-
ls -la /usr/sbin | NOMATCH ".visudo.oxidizr.bak"
9+
ensure_coreutils_absent
10+
ensure_sudors_absent

tests/disable-partial/task.yaml

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
1-
summary: Test installing packages
1+
summary: Test selectively disabling experiments
2+
execute: |
3+
source ${SPREAD_PATH}/tests/lib/uutils.sh
4+
source ${SPREAD_PATH}/tests/lib/sudo-rs.sh
5+
26
oxidizr enable --yes
37
oxidizr disable --yes --experiments coreutils
48
5-
apt list rust-coreutils | MATCH installed
6-
ls -la /usr/bin/date | MATCH "/usr/bin/date -> /usr/bin/coreutils"
7-
ls -la /usr/bin | MATCH ".date.oxidizr.bak"
8-
date --help | NOMATCH "GNU"
9-
10-
apt list rust-findutils | NOMATCH installed
11-
ls -la /usr/bin/find | NOMATCH "/usr/bin/find -> /usr/lib/cargo/bin/findutils/find"
12-
ls -la /usr/bin | NOMATCH ".find.oxidizr.bak"
13-
find --help | MATCH "GNU"
14-
15-
if [[ "$(lsb_release -rs)" != "24.04" ]]; then
16-
apt list rust-diffutils | NOMATCH installed
17-
ls -la /usr/bin/diff | NOMATCH "/usr/bin/diff -> /usr/lib/cargo/bin/diffutils/diff"
18-
ls -la /usr/bin | NOMATCH ".diff.oxidizr.bak"
19-
diff --help | MATCH "GNU"
20-
fi
9+
ensure_coreutils_absent
10+
ensure_sudors_installed

tests/enable-all/task.yaml

Lines changed: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,14 @@
1-
summary: Test enabling default experiments
1+
summary: Test enabling all experiments
22
execute: |
3-
oxidizr enable --yes --all
4-
5-
apt list rust-coreutils | MATCH installed
6-
while read p; do
7-
util_path="$(which $p)"
8-
util_dir="$(dirname "$util_path")"
9-
ls -la "$util_path"| MATCH "$util_path -> /usr/bin/coreutils"
10-
ls -la "$util_dir/.$p.oxidizr.bak" || echo "No backup file for $util_path"
11-
$util_path --help | NOMATCH "https://www.gnu.org/software/coreutils"
12-
done < ../rust-coreutils-bins.txt
13-
14-
apt list rust-findutils | MATCH installed
15-
while read p; do
16-
util_path="$(which $p)"
17-
util_dir="$(dirname "$util_path")"
18-
ls -la "$util_path"| MATCH "$util_path -> /usr/lib/cargo/bin/findutils/$p"
19-
ls -la "$util_dir/.$p.oxidizr.bak" || echo "No backup file for $util_path"
20-
$util_path --help | NOMATCH "https://www.gnu.org/software/coreutils"
21-
done < ../rust-findutils-bins.txt
22-
23-
if [[ "$(lsb_release -rs)" != "24.04" ]]; then
24-
apt list rust-diffutils | MATCH installed
25-
while read p; do
26-
util_path="$(which $p)"
27-
util_dir="$(dirname "$util_path")"
28-
ls -la "$util_path"| MATCH "$util_path -> /usr/lib/cargo/bin/diffutils/$p"
29-
ls -la "$util_dir/.$p.oxidizr.bak" || echo "No backup file for $util_path"
30-
$util_path --help | NOMATCH "https://www.gnu.org/software/coreutils"
31-
done < ../rust-diffutils-bins.txt
32-
fi
33-
34-
apt list sudo-rs | MATCH installed
3+
source ${SPREAD_PATH}/tests/lib/uutils.sh
4+
source ${SPREAD_PATH}/tests/lib/sudo-rs.sh
355
36-
ls -la /usr/bin/sudo | MATCH "/usr/bin/sudo -> /usr/lib/cargo/bin/sudo"
37-
ls -la /usr/bin | MATCH ".sudo.oxidizr.bak"
38-
/usr/bin/sudo --version 2>&1 | MATCH "sudo-rs"
39-
40-
ls -la /usr/bin/su | MATCH "/usr/bin/su -> /usr/lib/cargo/bin/su"
41-
ls -la /usr/bin | MATCH ".su.oxidizr.bak"
42-
/usr/bin/su --version 2>&1 | MATCH "su-rs"
6+
oxidizr enable --yes --all
437
44-
ls -la /usr/sbin/visudo | MATCH "/usr/sbin/visudo -> /usr/lib/cargo/bin/visudo"
45-
ls -la /usr/sbin | MATCH ".visudo.oxidizr.bak"
8+
ensure_coreutils_installed
9+
ensure_findutils_installed
10+
ensure_diffutils_installed
11+
ensure_sudors_installed
4612
4713
restore: |
4814
if [[ -z "${CI:-}" ]]; then

tests/enable-default/task.yaml

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,12 @@
11
summary: Test enabling default experiments
22
execute: |
3-
oxidizr enable --yes
4-
5-
apt list rust-coreutils | MATCH installed
6-
while read p; do
7-
util_path="$(which $p)"
8-
util_dir="$(dirname "$util_path")"
9-
ls -la "$util_path"| MATCH "$util_path -> /usr/bin/coreutils"
10-
ls -la "$util_dir/.$p.oxidizr.bak" || echo "No backup file for $util_path"
11-
$util_path --help | NOMATCH "https://www.gnu.org/software/coreutils"
12-
done < ../rust-coreutils-bins.txt
13-
14-
apt list sudo-rs | MATCH installed
3+
source ${SPREAD_PATH}/tests/lib/uutils.sh
4+
source ${SPREAD_PATH}/tests/lib/sudo-rs.sh
155
16-
ls -la /usr/bin/sudo | MATCH "/usr/bin/sudo -> /usr/lib/cargo/bin/sudo"
17-
ls -la /usr/bin | MATCH ".sudo.oxidizr.bak"
18-
/usr/bin/sudo --version 2>&1 | MATCH "sudo-rs"
19-
20-
ls -la /usr/bin/su | MATCH "/usr/bin/su -> /usr/lib/cargo/bin/su"
21-
ls -la /usr/bin | MATCH ".su.oxidizr.bak"
22-
/usr/bin/su --version 2>&1 | MATCH "su-rs"
6+
oxidizr enable --yes
237
24-
ls -la /usr/sbin/visudo | MATCH "/usr/sbin/visudo -> /usr/lib/cargo/bin/visudo"
25-
ls -la /usr/sbin | MATCH ".visudo.oxidizr.bak"
8+
ensure_coreutils_installed
9+
ensure_sudors_installed
2610
2711
restore: |
2812
if [[ -z "${CI:-}" ]]; then

tests/enable-partial/task.yaml

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
1-
summary: Test installing packages
1+
summary: Test selectively installing packages
22
execute: |
3-
oxidizr enable --yes --experiments coreutils
3+
source ${SPREAD_PATH}/tests/lib/uutils.sh
4+
source ${SPREAD_PATH}/tests/lib/sudo-rs.sh
45
5-
apt list rust-coreutils | MATCH installed
6-
while read p; do
7-
util_path="$(which $p)"
8-
util_dir="$(dirname "$util_path")"
9-
ls -la "$util_path"| MATCH "$util_path -> /usr/bin/coreutils"
10-
ls -la "$util_dir/.$p.oxidizr.bak" || echo "No backup file for $util_path"
11-
$util_path --help | NOMATCH "https://www.gnu.org/software/coreutils"
12-
done < ../rust-coreutils-bins.txt
6+
oxidizr enable --yes --experiments coreutils
137
14-
apt list rust-findutils | NOMATCH installed
15-
apt list rust-diffutils | NOMATCH installed
16-
apt list sudo-rs | NOMATCH installed
8+
ensure_coreutils_installed
9+
ensure_findutils_absent
10+
ensure_diffutils_absent
11+
ensure_sudors_absent
1712
1813
restore: |
1914
if [[ -z "${CI:-}" ]]; then
File renamed without changes.
File renamed without changes.

tests/lib/sudo-rs.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
3+
ensure_sudors_installed() {
4+
apt list sudo-rs | MATCH installed
5+
6+
ls -la /usr/bin/sudo | MATCH "/usr/bin/sudo -> /usr/lib/cargo/bin/sudo"
7+
ls -la /usr/bin | MATCH ".sudo.oxidizr.bak"
8+
/usr/bin/sudo --version 2>&1 | MATCH "sudo-rs"
9+
10+
ls -la /usr/bin/su | MATCH "/usr/bin/su -> /usr/lib/cargo/bin/su"
11+
ls -la /usr/bin | MATCH ".su.oxidizr.bak"
12+
/usr/bin/su --version 2>&1 | MATCH "su-rs"
13+
14+
ls -la /usr/sbin/visudo | MATCH "/usr/sbin/visudo -> /usr/lib/cargo/bin/visudo"
15+
ls -la /usr/sbin | MATCH ".visudo.oxidizr.bak"
16+
}
17+
18+
ensure_sudors_absent() {
19+
apt list sudo-rs | NOMATCH installed
20+
21+
ls -la /usr/bin/sudo | NOMATCH "/usr/bin/sudo -> /usr/lib/cargo/bin/sudo"
22+
ls -la /usr/bin | NOMATCH ".sudo.oxidizr.bak"
23+
/usr/bin/sudo --version 2>&1 | NOMATCH "sudo-rs"
24+
25+
ls -la /usr/bin/su | NOMATCH "/usr/bin/su -> /usr/lib/cargo/bin/su"
26+
ls -la /usr/bin | NOMATCH ".su.oxidizr.bak"
27+
/usr/bin/su --version 2>&1 | NOMATCH "su-rs"
28+
29+
ls -la /usr/sbin/visudo | NOMATCH "/usr/sbin/visudo -> /usr/lib/cargo/bin/visudo"
30+
ls -la /usr/sbin | NOMATCH ".visudo.oxidizr.bak"
31+
}

0 commit comments

Comments
 (0)