mirror of
https://gitlab.alpinelinux.org/alpine/cloud/tiny-cloud.git
synced 2026-02-04 04:22:43 +03:00
Refactor aws tests' fake meta-data
Refactor fake wget to use a yaml so we can set aws fake meta-data similar to how we set nocloud fake meta-data. Also move fake netcat to tests/bin/nc so its always there and we don't need to remember to call fake_netcat when needed.
This commit is contained in:
parent
a90bf444d3
commit
0f40c146f2
6
tests/bin/nc
Executable file
6
tests/bin/nc
Executable file
@ -0,0 +1,6 @@
|
||||
#!/bin/sh
|
||||
input="$(cat)"
|
||||
case "$input" in
|
||||
-*) echo "nc: bad input: \$input" >&2; exit 1;;
|
||||
esac
|
||||
echo "token-foo"
|
||||
@ -78,8 +78,17 @@ for url; do
|
||||
esac
|
||||
done
|
||||
|
||||
host="${url#http*://}"
|
||||
host="${host%%/*}"
|
||||
path="${url#http*://$host}"
|
||||
path="${path#${WGET_STRIP_PREFIX:-/}}"
|
||||
|
||||
if [ -z "$WGETCONTENT" ]; then
|
||||
WGETCONTENT=$( cat "$(echo ${url#http*://} | tr '/' '_')" 2>/dev/null)
|
||||
(
|
||||
IFS=/
|
||||
set -- ${path#/}
|
||||
yx -f "${WGET_YAML:-$host.yaml}" "$@" 2>/dev/null
|
||||
)
|
||||
fi
|
||||
|
||||
: "${outfile:=index.html}"
|
||||
|
||||
@ -14,7 +14,8 @@ init_tests \
|
||||
fake_wget_missing_url \
|
||||
fake_wget_empty_url \
|
||||
fake_wget_header \
|
||||
fake_wget_content_from_path
|
||||
fake_wget_content_from_path \
|
||||
fake_wget_content_from_path_strip_prefix
|
||||
|
||||
fake_wget_usage_body() {
|
||||
atf_check -s exit:0 \
|
||||
@ -70,7 +71,9 @@ fake_wget_stdout_body() {
|
||||
-o match:"hello world" \
|
||||
-e match:"writing to stdout" \
|
||||
wget -O - https://example.com
|
||||
! test -f - || atf_fail "- was created"
|
||||
if [ -f - ]; then
|
||||
atf_fail "- was created"
|
||||
fi
|
||||
}
|
||||
|
||||
fake_wget_fail_body() {
|
||||
@ -104,9 +107,22 @@ fake_wget_header_body() {
|
||||
}
|
||||
|
||||
fake_wget_content_from_path_body() {
|
||||
mkdir -p example.com/foo
|
||||
echo value > example.com_foo_key
|
||||
cat > example.com.yaml <<-EOF
|
||||
foo:
|
||||
key: value
|
||||
EOF
|
||||
atf_check -s exit:0 \
|
||||
-o match:"^value$" \
|
||||
wget --quiet -O - https://example.com/foo/key
|
||||
}
|
||||
|
||||
fake_wget_content_from_path_strip_prefix_body() {
|
||||
cat > 169.254.169.254.yaml <<-EOF
|
||||
foo:
|
||||
key: value
|
||||
EOF
|
||||
export WGET_STRIP_PREFIX="/latest/meta-data"
|
||||
atf_check -s exit:0 \
|
||||
-o match:"^value$" \
|
||||
wget --quiet -O - https://169.254.169.254/latest/meta-data/foo/key
|
||||
}
|
||||
|
||||
@ -25,29 +25,27 @@ imds_space_body() {
|
||||
CLOUD=nocloud atf_check -o match:'^$' imds +n
|
||||
}
|
||||
|
||||
aws_set_fake_meta() {
|
||||
local key="$1" value="$2"
|
||||
echo "$value" > $(echo 169.254.169.254/latest/meta-data/"$key" \
|
||||
| tr '/' '_')
|
||||
}
|
||||
|
||||
imds_aws_hostname_body() {
|
||||
fake_netcat
|
||||
aws_set_fake_meta hostname myhostname
|
||||
fake_metadata_aws <<-EOF
|
||||
hostname: myhostname
|
||||
EOF
|
||||
CLOUD=aws atf_check -o match:"myhostname" imds @hostname
|
||||
}
|
||||
|
||||
imds_aws_local_hostname_body() {
|
||||
fake_netcat
|
||||
aws_set_fake_meta local-hostname myhostname
|
||||
fake_metadata_aws <<-EOF
|
||||
local-hostname: myhostname
|
||||
EOF
|
||||
CLOUD=aws atf_check -o match:"myhostname" imds @local-hostname
|
||||
}
|
||||
|
||||
imds_aws_ssh_keys_body() {
|
||||
fake_netcat
|
||||
aws_set_fake_meta public-keys 0=testuser
|
||||
aws_set_fake_meta public-keys/0/openssh-key "ssh-ed25519 keydata"
|
||||
|
||||
fake_metadata_aws <<-EOF
|
||||
public-keys:
|
||||
0=testuser:
|
||||
0:
|
||||
openssh-key: ssh-ed25519 keydata
|
||||
EOF
|
||||
CLOUD=aws atf_check -o match:"ssh-ed25519 keydata" imds @ssh-keys
|
||||
}
|
||||
|
||||
|
||||
@ -63,6 +63,11 @@ fake_userdata_nocloud() {
|
||||
fake_data_nocloud user-data
|
||||
}
|
||||
|
||||
fake_metadata_aws() {
|
||||
cat > "169.254.169.254.yaml"
|
||||
export WGET_STRIP_PREFIX="/latest/meta-data"
|
||||
}
|
||||
|
||||
fake_interfaces() {
|
||||
local n=1
|
||||
for i; do
|
||||
@ -72,14 +77,3 @@ fake_interfaces() {
|
||||
n=$((n+1))
|
||||
done
|
||||
}
|
||||
|
||||
fake_netcat() {
|
||||
fake_bin nc <<-EOF
|
||||
#!/bin/sh
|
||||
input="\$(cat)"
|
||||
case "\$input" in
|
||||
-*) echo "nc: bad input: \$input" >&2; exit 1;;
|
||||
esac
|
||||
echo "token-foo"
|
||||
EOF
|
||||
}
|
||||
|
||||
@ -27,7 +27,6 @@ tiny_cloud_help_body() {
|
||||
}
|
||||
|
||||
no_metadata_early_body() {
|
||||
fake_netcat
|
||||
for provider in $PROVIDERS; do
|
||||
CLOUD="$provider" atf_check \
|
||||
-e not-match:"unknown" \
|
||||
@ -39,7 +38,6 @@ no_metadata_early_body() {
|
||||
}
|
||||
|
||||
no_userdata_net_body() {
|
||||
fake_netcat
|
||||
for provider in $PROVIDERS; do
|
||||
CLOUD="$provider" atf_check \
|
||||
-e not-match:"unknown" \
|
||||
@ -49,7 +47,6 @@ no_userdata_net_body() {
|
||||
}
|
||||
|
||||
no_userdata_main_body() {
|
||||
fake_netcat
|
||||
for provider in $PROVIDERS; do
|
||||
# we should not set empty hostname
|
||||
# we should not create .ssh dir for non-existing user
|
||||
@ -68,7 +65,6 @@ no_userdata_main_body() {
|
||||
}
|
||||
|
||||
no_userdata_final_body() {
|
||||
fake_netcat
|
||||
for provider in $PROVIDERS; do
|
||||
CLOUD="$provider" atf_check \
|
||||
-e not-match:"unknown" \
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user