Skip to content

Commit b8fe2a6

Browse files
committed
Add integration test for limactl snapshot
Signed-off-by: Anders F Björklund <anders.f.bjorklund@gmail.com>
1 parent e8e518d commit b8fe2a6

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

hack/test-example.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ declare -A CHECKS=(
2222
["mount-home"]="1"
2323
["containerd-user"]="1"
2424
["restart"]="1"
25+
["snapshot-online"]="1"
26+
["snapshot-offline"]="1"
2527
["port-forwards"]="1"
2628
["vmnet"]=""
2729
["disk"]=""
@@ -43,6 +45,9 @@ case "$NAME" in
4345
# ● run-r2b459797f5b04262bfa79984077a65c7.service loaded failed failed /usr/bin/systemctl start man-db-cache-update
4446
CHECKS["systemd-strict"]=
4547
;;
48+
"9p")
49+
CHECKS["snapshot-online"]=""
50+
;;
4651
"vmnet")
4752
CHECKS["vmnet"]=1
4853
;;
@@ -299,6 +304,46 @@ if [[ -n ${CHECKS["restart"]} ]]; then
299304
fi
300305
fi
301306

307+
if [[ -n ${CHECKS["snapshot-online"]} ]]; then
308+
INFO "Testing online snapshots"
309+
limactl shell "$NAME" sh -c 'echo foo > /tmp/test'
310+
limactl snapshot create "$NAME" --tag snap1
311+
got=$(limactl snapshot list "$NAME" --quiet)
312+
expected="snap1"
313+
INFO "snapshot list: expected=${expected} got=${got}"
314+
if [ "$got" != "$expected" ]; then
315+
ERROR "snapshot list did not return expected value"
316+
exit 1
317+
fi
318+
limactl shell "$NAME" sh -c 'echo bar > /tmp/test'
319+
limactl snapshot apply "$NAME" --tag snap1
320+
got=$(limactl shell "$NAME" cat /tmp/test)
321+
expected="foo"
322+
INFO "snapshot apply: expected=${expected} got=${got}"
323+
if [ "$got" != "$expected" ]; then
324+
ERROR "snapshot apply did not restore snapshot"
325+
exit 1
326+
fi
327+
limactl snapshot delete "$NAME" --tag snap1
328+
limactl shell "$NAME" rm /tmp/test
329+
fi
330+
if [[ -n ${CHECKS["snapshot-offline"]} ]]; then
331+
INFO "Testing offline snapshots"
332+
limactl stop "$NAME"
333+
sleep 3
334+
limactl snapshot create "$NAME" --tag snap2
335+
got=$(limactl snapshot list "$NAME" --quiet)
336+
expected="snap2"
337+
INFO "snapshot list: expected=${expected} got=${got}"
338+
if [ "$got" != "$expected" ]; then
339+
ERROR "snapshot list did not return expected value"
340+
exit 1
341+
fi
342+
limactl snapshot apply "$NAME" --tag snap2
343+
limactl snapshot delete "$NAME" --tag snap2
344+
limactl start "$NAME"
345+
fi
346+
302347
INFO "Stopping \"$NAME\""
303348
limactl stop "$NAME"
304349
sleep 3

0 commit comments

Comments
 (0)