mirror of
https://gitlab.alpinelinux.org/alpine/cloud/tiny-cloud.git
synced 2025-12-16 11:52:43 +03:00
tests: refactor fake userdata for nocloud
- move it so it can be shared - remove mentions of #cloud-config to avoid confusion
This commit is contained in:
parent
7ea8f69a06
commit
e51051c7ca
@ -35,19 +35,6 @@ set_nocloud_meta() {
|
|||||||
mkdir -p mnt
|
mkdir -p mnt
|
||||||
}
|
}
|
||||||
|
|
||||||
set_nocloud_userdata_from_file() {
|
|
||||||
local file="$1"
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
set_hostname_body() {
|
set_hostname_body() {
|
||||||
set_nocloud_meta <<-EOF
|
set_nocloud_meta <<-EOF
|
||||||
hostname: myhostname
|
hostname: myhostname
|
||||||
@ -86,20 +73,24 @@ set_ssh_keys_body() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
save_userdata_plain_body() {
|
save_userdata_plain_body() {
|
||||||
printf "%s\n" "#cloud-config" > tmpfile
|
fake_userdata_nocloud <<-EOF
|
||||||
set_nocloud_userdata_from_file tmpfile
|
#userdata
|
||||||
|
EOF
|
||||||
CLOUD="nocloud" atf_check \
|
CLOUD="nocloud" atf_check \
|
||||||
sh -c ". \"$lib\"; save_userdata"
|
sh -c ". \"$lib\"; save_userdata"
|
||||||
atf_check -o match:"^#cloud-config" cat var/lib/cloud/user-data
|
atf_check -o match:"^#userdata" cat var/lib/cloud/user-data
|
||||||
}
|
}
|
||||||
|
|
||||||
save_userdata_compressed_body() {
|
save_userdata_compressed_body() {
|
||||||
for comp in gzip bzip2 xz lzma lzop lz4 zstd; do
|
for comp in gzip bzip2 xz lzma lzop lz4 zstd; do
|
||||||
printf "%s\n" "#cloud-config" | $comp -c > tmpfile
|
# fake_userdata_nocloud will set PATH so dont run it in a subshell
|
||||||
set_nocloud_userdata_from_file tmpfile
|
printf "%s\n" "#userdata" | $comp -c > tmpfile
|
||||||
|
fake_userdata_nocloud < tmpfile
|
||||||
|
|
||||||
CLOUD="nocloud" atf_check \
|
CLOUD="nocloud" atf_check \
|
||||||
sh -c ". \"$lib\"; save_userdata"
|
sh -c ". \"$lib\"; save_userdata"
|
||||||
if ! grep "^#cloud-config" var/lib/cloud/user-data; then
|
|
||||||
|
if ! grep "^#userdata" var/lib/cloud/user-data; then
|
||||||
atf_fail "$comp failed"
|
atf_fail "$comp failed"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|||||||
@ -29,3 +29,17 @@ fake_bin() {
|
|||||||
PATH="$PWD/bin:$PATH"
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user