1
0
mirror of https://gitlab.alpinelinux.org/alpine/cloud/tiny-cloud.git synced 2025-12-15 11:22:43 +03:00

tests: add initial tests for init-main

This commit is contained in:
Natanael Copa 2023-03-27 17:30:19 +02:00
parent fda9a350a1
commit 0f53f14399
2 changed files with 57 additions and 3 deletions

View File

@ -14,9 +14,10 @@ set_hostname() {
local fqdn=$(imds @hostname) local fqdn=$(imds @hostname)
local host="${fqdn%%\.*}" local host="${fqdn%%\.*}"
echo "$host" > /etc/hostname mkdir -p "$ROOT"/etc
hostname -F /etc/hostname echo "$host" > "$ROOT"/etc/hostname
echo -e "127.0.1.1\t$fqdn $host" >> /etc/hosts $MOCK hostname -F "$ROOT"/etc/hostname
echo -e "127.0.1.1\t$fqdn $host" >> "$ROOT"/etc/hosts
} }
set_ssh_keys() { set_ssh_keys() {

53
tests/init-main.test Executable file
View File

@ -0,0 +1,53 @@
#!/usr/bin/env atf-sh
. $(atf_get_srcdir)/test_env.sh
export PREFIX="$srcdir"
export MOCK=echo
lib="$srcdir"/lib/tiny-cloud/init-main
init_tests \
set_hostname
set_nocloud_meta() {
local metadata="$(cat)"
fake_bin mount <<-EOF
#!/bin/sh
# find last arg which is the mount dir
while ! [ -d "\$1" ]; do
shift
done
printf "%s" "$metadata" \
> "\$1"/meta-data
EOF
fake_bin umount <<-EOF
#!/bin/sh
while ! [ -d "\$1" ]; do
shift
done
rm -f "\$1"/meta-data
EOF
mkdir -p mnt
}
set_hostname_body() {
set_nocloud_meta <<-EOF
hostname: myhostname
EOF
CLOUD="nocloud" atf_check \
-o match:"hostname.*-F $PWD/etc/hostname" \
sh -c ". \"$lib\"; set_hostname"
atf_check -o match:"^myhostname$" cat etc/hostname
rm etc/hostname
CLOUD="nocloud" atf_check \
-o not-match:"hostname.*-F $PWD/etc/hostname" \
sh -c "SKIP_INIT_ACTIONS=set_hostname ; . \"$lib\"; set_hostname"
if test -f etc/hostname; then
atf_fail "etc/hostname should not exist"
fi
}