Skip to content

Commit 41b330c

Browse files
committed
CI: more tests
Signed-off-by: Akihiro Suda <[email protected]>
1 parent ec20714 commit 41b330c

File tree

3 files changed

+140
-19
lines changed

3 files changed

+140
-19
lines changed

.github/workflows/test.yml

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ jobs:
2121
version: v1.35
2222
args: --verbose
2323

24-
unit:
25-
name: Unit tests
24+
basic:
25+
name: Basic tests
2626
runs-on: ${{ matrix.os }}
2727
strategy:
2828
matrix:
@@ -35,15 +35,24 @@ jobs:
3535
- uses: actions/checkout@v2
3636
with:
3737
fetch-depth: 1
38-
- name: Make
39-
run: make
4038
- name: Unit tests
4139
run: go test -v ./...
40+
- name: Make
41+
run: make
42+
- name: Install
43+
run: sudo make install
44+
- name: Validate examples
45+
run: limactl validate ./examples/*.yaml
46+
- name: Uninstall
47+
run: sudo make uninstall
4248

4349
integration:
4450
name: Integration tests
4551
runs-on: macos-10.15
4652
timeout-minutes: 40
53+
strategy:
54+
matrix:
55+
example: [examples/default.yaml, examples/debian.yaml, examples/fedora.yaml]
4756
steps:
4857
- uses: actions/setup-go@v2
4958
with:
@@ -55,8 +64,11 @@ jobs:
5564
run: make
5665
- name: Install
5766
run: make install
58-
- name: Install QEMU
59-
run: brew install qemu
67+
- name: Install test dependencies
68+
# QEMU: required by Lima itself
69+
# bash: required by test-example.sh (OS version of bash is too old)
70+
# coreutils: required by test-example.sh for the "timeout" command
71+
run: brew install qemu bash coreutils
6072
- name: Prepare ssh
6173
run: |
6274
if [ -e ~/.ssh/id_rsa ]; then
@@ -65,15 +77,15 @@ jobs:
6577
echo "Generating ~/.ssh/id_rsa"
6678
ssh-keygen -b 2048 -t rsa -f ~/.ssh/id_rsa -q -N ""
6779
fi
68-
- name: Smoke tests
69-
run: |
70-
limactl start --tty=false default
71-
lima uname -a
72-
echo "this file was created on macOS" > ~/foo
73-
lima cat ~/foo
74-
limactl stop default
75-
- name: Validate examples
76-
run: limactl validate examples/*.yaml
80+
- name: Cache ~/Library/Caches/lima/download
81+
uses: actions/cache@v2
82+
with:
83+
path: ~/Library/Caches/lima/download
84+
key: ${{ runner.os }}-${{ matrix.example }}
85+
- name: Test
86+
env:
87+
EXAMPLE: ${{ matrix.example }}
88+
run: ./hack/test-example.sh $EXAMPLE
7789

7890
artifacts:
7991
name: Artifacts

hack/test-example.sh

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#!/usr/bin/env bash
2+
set -eu -o pipefail
3+
4+
function INFO() {
5+
echo "TEST| [INFO] $*"
6+
}
7+
8+
function WARNING() {
9+
echo >&2 "TEST| [WARNING] $*"
10+
}
11+
12+
function ERROR() {
13+
echo >&2 "TEST| [ERROR] $*"
14+
}
15+
16+
if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then
17+
ERROR "Bash version is too old: ${BASH_VERSION}"
18+
exit 1
19+
fi
20+
21+
if [ "$#" -ne 1 ]; then
22+
ERROR "Usage: $0 FILE.yaml"
23+
exit 1
24+
fi
25+
26+
FILE="$1"
27+
NAME="$(basename -s .yaml "$FILE")"
28+
29+
INFO "Validating \"$FILE\""
30+
limactl validate "$FILE"
31+
32+
declare -A CHECKS=(["systemd"]="1" ["systemd-strict"]="1" ["mount-home"]="1" ["containerd-user"]="1")
33+
34+
case "$NAME" in
35+
"k3s")
36+
ERROR "File \"$FILE\" is not testable with this script"
37+
exit 1
38+
;;
39+
"fedora")
40+
WARNING "Relaxing systemd tests for fedora (For avoiding CI faillure)"
41+
# CI failure:
42+
# ● run-r2b459797f5b04262bfa79984077a65c7.service loaded failed failed /usr/bin/systemctl start man-db-cache-update
43+
CHECKS["systemd-strict"]=
44+
;;
45+
esac
46+
47+
if limactl ls -q | grep -q "$NAME"; then
48+
ERROR "Instance $NAME already exists"
49+
exit 1
50+
fi
51+
52+
INFO "Starting \"$NAME\" from \"$FILE\""
53+
trap 'limactl delete -f $NAME' EXIT
54+
set -x
55+
if ! limactl start --tty=false "$FILE"; then
56+
ERROR "Failed to start \"$NAME\""
57+
tail "$HOME/.lima/${NAME}"/*.log
58+
exit 1
59+
fi
60+
61+
limactl shell "$NAME" uname -a
62+
63+
limactl shell "$NAME" cat /etc/os-release
64+
set +x
65+
66+
if [[ -n "${CHECKS["systemd"]}" ]]; then
67+
set -x
68+
if ! limactl shell "$NAME" systemctl is-system-running --wait; then
69+
ERROR "\"systemctl is-system-running\" failed"
70+
limactl shell "$NAME" systemctl
71+
if [[ -z "${CHECKS["systemd-strict"]}" ]]; then
72+
INFO "Ignoring \"systemctl is-system-running\" failure"
73+
else
74+
exit 1
75+
fi
76+
fi
77+
set +x
78+
fi
79+
80+
if [[ -n "${CHECKS["mount-home"]}" ]]; then
81+
hometmp="$HOME/lima-test-tmp"
82+
INFO "Testing home access (\"$hometmp\")"
83+
rm -rf "$hometmp"
84+
mkdir -p "$hometmp"
85+
trap 'rm -rf $hometmp' EXIT
86+
echo "random-content-${RANDOM}" >"$hometmp/random"
87+
expected="$(cat "$hometmp/random")"
88+
got="$(limactl shell "$NAME" cat "$hometmp/random")"
89+
INFO "$hometmp/random: expected=${expected}, got=${got}"
90+
if [ "$got" != "$expected" ]; then
91+
ERROR"Home directory is not shared?"
92+
exit 1
93+
fi
94+
fi
95+
96+
if [[ -n "${CHECKS["containerd-user"]}" ]]; then
97+
INFO "Run a nginx container with port forwarding 127.0.0.1:8080"
98+
set -x
99+
limactl shell "$NAME" nerdctl info
100+
limactl shell "$NAME" sh -ec "nerdctl pull nginx:alpine >/dev/null"
101+
limactl shell "$NAME" nerdctl run -d --name nginx -p 127.0.0.1:8080:80 nginx:alpine
102+
103+
timeout 3m bash -euxc "until curl -f --retry 30 --retry-connrefused http://127.0.0.1:8080; do sleep 3; done"
104+
105+
limactl shell "$NAME" nerdctl rm -f nginx
106+
set +x
107+
fi
108+
109+
INFO "Stopping \"$NAME\""
110+
limactl stop "$NAME"
111+
112+
INFO "Deleting \"$NAME\""
113+
limactl delete "$NAME"

hack/validate-dco.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)