Skip to content

Commit

Permalink
tests: add actual tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mkg20001 committed Mar 1, 2024
1 parent 7c30bd6 commit 674949d
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
result*
*qcow2
/dev/images
/test/images
File renamed without changes.
File renamed without changes.
10 changes: 6 additions & 4 deletions dev/incus-test-setup.sh → test/incus-test-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
set -euxo pipefail

SELF=$(dirname "$(readlink -f "$0")")
. "$SELF/oslist.sh"

# What is this?
# Since we will be testing within a nixos derivation
Expand All @@ -11,8 +12,8 @@ SELF=$(dirname "$(readlink -f "$0")")
# This means we need to create the image on a regular machine
# and then import it to the CI VM's incus daemon
if [ -v EXPORT_IMAGE ]; then
rm -rf "$SELF/images"
mkdir -p "$SELF/images"
rm -rf "$IMAGES"
mkdir -p "$IMAGES"
fi

for img in debian/12 ubuntu/22.04; do
Expand Down Expand Up @@ -40,7 +41,8 @@ for img in debian/12 ubuntu/22.04; do
done' | incus exec "unify-$os" bash -

if [ -v EXPORT_IMAGE ]; then
incus stop "unify-$os"
incus export --instance-only "unify-$os" "$SELF/images/$os.tar.gz"
incus image delete "unify-test-$os" || true
incus publish "unify-$os" --force --alias "unify-test-$os"
incus image export "unify-test-$os" "$IMAGES/$os"
fi
done
16 changes: 16 additions & 0 deletions test/oslist.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

IMGLIST="debian/12 ubuntu/22.04"
OSLIST="debian ubuntu"

IMAGES="$SELF/images"

for_each_os() {
for os in $IMGLIST; do
"$1" "$(dirname "$os")" "$os"
done
}

get_ip() {
incus info "$1" | grep "inet" | grep 10. | grep "[0-9.]*" -o | head -n 1
}
19 changes: 19 additions & 0 deletions test/test-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

set -euo pipefail

SELF=$(dirname "$(readlink -f "$0")")
. "$SELF/oslist.sh"

for os in $OSLIST; do
if ! incus image list -f csv -c l | grep "unify-test-$os" >/dev/null; then
incus image import "$IMAGES/$OS.tar.gz" --alias "unify-test-$OS"
fi

I="unify-$$-run-test-$os"

incus launch "unify-test-$os" "$I" -e
sleep 10s

bash "$SELF/test.sh" "$(get_ip "$I")"
done
5 changes: 3 additions & 2 deletions dev/test-deployment.sh → test/test-deployment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
set -euxo pipefail

SELF=$(dirname "$(readlink -f "$0")")
. "$SELF/oslist.sh"

if [ -v 1 ]; then
OS="$1"
else
OS="ubuntu debian"
OS="$OSLIST"
fi

for os in $OS; do
IP=$(incus info "unify-$os" | grep "inet" | grep 10. | grep "[0-9.]*" -o | head -n 1)
IP=$(get_ip "unify-$os")
NIX_SSHOPTS="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o IdentitiesOnly=yes -i $SELF/id_ed25519_dev" nixos-rebuild --flake ".#test" --target-host "root@$IP" switch --show-trace
done
11 changes: 8 additions & 3 deletions test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ set -euo pipefail
IP="$1"

SELF=$(dirname "$(readlink -f "$0")")
KEY="$SELF/../dev/id_ed25519_dev"
KEY="$SELF/id_ed25519_dev"
KNOWN_HOSTS=$(mktemp)
DEST="root@$IP"

export NIX_SSHOPTS="-o UserKnownHostsFile=$KNOWN_HOSTS -o StrictHostKeyChecking=no -o IdentitiesOnly=yes -i $KEY"
export NIX_SSHOPTS="-o VisualHostKey=no -o UserKnownHostsFile=$KNOWN_HOSTS -o StrictHostKeyChecking=no -o IdentitiesOnly=yes -i $KEY"

m() {
echo "$*" >&2
Expand Down Expand Up @@ -47,14 +47,19 @@ deploy() {
s "deploying $SRC"

F="/tmp/nix-unify-$SRC"
nix-build --arg conf "$SELF/tests/$SRC.nix" buildos.nix -o "$F"
nix-build --arg conf "$SELF/tests/$SRC.nix" "$SELF/buildos.nix" -o "$F"
STORE=$(readlink -f "$F")

nix-copy-closure --to "$DEST" "$STORE"
ssh nix-env -p /nix/var/nix/profiles/system --set "$STORE"
ssh "$STORE/bin/switch-to-configuration" switch
}

s "prepare"

t "make sure no nixdeploy exists"
ssh test ! -e /etc/systemd/system-generators/nix-unify-generator

deploy initial

s "basics"
Expand Down

0 comments on commit 674949d

Please sign in to comment.