1
0
mirror of https://gitlab.alpinelinux.org/alpine/cloud/tiny-cloud.git synced 2025-12-15 11:22:43 +03:00
tiny-cloud/tests/test_env.sh
Natanael Copa e51051c7ca tests: refactor fake userdata for nocloud
- move it so it can be shared
- remove mentions of #cloud-config to avoid confusion
2023-04-06 22:07:58 +02:00

46 lines
699 B
Bash

# shellcheck shell=sh
atf_srcdir="$(atf_get_srcdir)"
srcdir="$atf_srcdir/.."
PATH="$atf_srcdir/bin:$srcdir/bin:$srcdir/sbin:$PATH"
export TINY_CLOUD_BASEDIR="$srcdir"
export ROOT="$PWD"
init_tests() {
TESTS=
for t; do
TESTS="$TESTS $t"
atf_test_case "$t"
done
export TESTS
}
atf_init_test_cases() {
for t in $TESTS; do
atf_add_test_case "$t"
done
}
fake_bin() {
mkdir -p bin
cat > bin/"$1"
chmod +x bin/"$1"
PATH="$PWD/bin:$PATH"
}
fake_userdata_nocloud() {
local file="$(mktemp -p "$PWD")"
cat > "$file"
fake_bin mount <<-EOF
#!/bin/sh
# find last arg which is the mount dir
while ! [ -d "\$1" ]; do
shift
done
cp "$file" "\$1"/user-data
EOF
mkdir -p mnt
}