Files
cozystack/hack/platform-packages_test.bats
T
Myasnikov Daniil cc942fed68 test(tests): run unit suites with Bats and retain POSIX coverage
The shell translator rewrites test bodies and loses Bats reporting.
The unit lane needs complete TAP results and JUnit reports without
changing how live-cluster suites run.

Sourced production helpers still need a dash pass, and unit test bodies
need nounset without exporting shell options into subprocesses.

Assisted-by: LLM
Signed-off-by: Myasnikov Daniil <myasnikovdaniil2001@gmail.com>
2026-10-07 11:04:00 +03:00

185 lines
8.7 KiB
Bash

#!/usr/bin/env bats
# Unit coverage for the lane-specific Package manifest emitted by
# hack/e2e-platform-packages.sh. This suite runs through hack/cozytest.sh, so it
# uses direct shell assertions rather than bats' run/status helpers.
load test_helper
@test "QEMU defaults keep the platform-managed LINSTOR package" {
manifest=$(hack/e2e-platform-packages.sh)
names=$(printf '%s\n' "$manifest" | yq -N '.metadata.name')
endpoint=$(printf '%s\n' "$manifest" | yq '.spec.components.platform.values.publishing.apiServerEndpoint')
if [ "$names" != "cozystack.cozystack-platform" ]; then
echo "default manifest unexpectedly replaces a platform package: $names" >&2
return 1
fi
if [ "$endpoint" != "https://192.168.123.10:6443" ]; then
echo "unexpected default API endpoint: $endpoint" >&2
return 1
fi
}
@test "container mode replaces LINSTOR with DRBD disabled" {
manifest=$(COZY_APISERVER_ENDPOINT=https://192.168.123.11:6443 COZY_LINSTOR_DRBD_ENABLED=false hack/e2e-platform-packages.sh)
names=$(printf '%s\n' "$manifest" | yq -N '.metadata.name')
expected_names=$(printf '%s\n' cozystack.cozystack-platform cozystack.linstor cozystack.kubevirt-cdi)
endpoint=$(printf '%s\n' "$manifest" | yq 'select(.metadata.name == "cozystack.cozystack-platform") | .spec.components.platform.values.publishing.apiServerEndpoint')
disabled=$(printf '%s\n' "$manifest" | yq 'select(.metadata.name == "cozystack.cozystack-platform") | .spec.components.platform.values.bundles.disabledPackages | join(",")')
drbd=$(printf '%s\n' "$manifest" | yq 'select(.metadata.name == "cozystack.linstor") | .spec.components.linstor.values.drbd.enabled')
if [ "$names" != "$expected_names" ]; then
echo "container manifest has unexpected packages: $names" >&2
return 1
fi
if [ "$endpoint" != "https://192.168.123.11:6443" ]; then
echo "container API endpoint was not forwarded: $endpoint" >&2
return 1
fi
if [ "$disabled" != "cozystack.linstor,cozystack.kubevirt-cdi" ]; then
echo "platform-managed LINSTOR was not disabled: $disabled" >&2
return 1
fi
if [ "$drbd" != "false" ]; then
echo "replacement LINSTOR package did not disable DRBD: $drbd" >&2
return 1
fi
}
@test "container mode raises the CDI importer memory ceiling" {
manifest=$(COZY_APISERVER_ENDPOINT=https://192.168.123.11:6443 COZY_LINSTOR_DRBD_ENABLED=false hack/e2e-platform-packages.sh)
disabled=$(printf '%s\n' "$manifest" | yq 'select(.metadata.name == "cozystack.cozystack-platform") | .spec.components.platform.values.bundles.disabledPackages | join(",")')
mem=$(printf '%s\n' "$manifest" | yq 'select(.metadata.name == "cozystack.kubevirt-cdi") | .spec.components.kubevirt-cdi.values.importerResources.limits.memory')
cpu=$(printf '%s\n' "$manifest" | yq 'select(.metadata.name == "cozystack.kubevirt-cdi") | .spec.components.kubevirt-cdi.values.importerResources.limits.cpu')
if [ "$disabled" != "cozystack.linstor,cozystack.kubevirt-cdi" ]; then
echo "container mode did not replace both packages: $disabled" >&2
return 1
fi
if [ "$mem" != "4Gi" ]; then
echo "replacement CDI package did not raise the memory ceiling: $mem" >&2
return 1
fi
# The CPU ceiling deliberately stays at CDI's own default: the failure this
# override answers was memory, and widening CPU too would be an unmeasured
# second change riding along.
if [ "$cpu" != "750m" ]; then
echo "replacement CDI package moved the CPU ceiling off CDI's default: $cpu" >&2
return 1
fi
}
@test "the CDI chart default does not move production behaviour" {
# The override above is a lane concern. The chart itself must restate CDI's
# built-in requirements, so an install that sets nothing behaves as it did
# before importerResources existed.
defaults=$(helm template packages/system/kubevirt-cdi --set _cluster.root-host=example.org \
| yq -N 'select(.kind == "CDI") | .spec.config.podResourceRequirements | [.limits.cpu, .limits.memory, .requests.cpu, .requests.memory] | join(" ")' | grep .)
if [ "$defaults" != "750m 600M 100m 60M" ]; then
echo "kubevirt-cdi default podResourceRequirements drifted from CDI's own: $defaults" >&2
return 1
fi
}
@test "invalid DRBD mode fails before emitting YAML" {
if manifest=$(COZY_LINSTOR_DRBD_ENABLED=unsupported hack/e2e-platform-packages.sh); then
echo "invalid DRBD mode unexpectedly succeeded" >&2
return 1
fi
if [ -n "$manifest" ]; then
echo "invalid DRBD mode emitted a partial manifest" >&2
return 1
fi
}
@test "both gating workflows forward the E2E-only override into the sandbox" {
workflow_value=$(yq '.jobs.e2e.steps[] | select(.name == "Install Cozystack into sandbox") | .env.COZY_LINSTOR_DRBD_ENABLED' .github/workflows/pull-requests.yaml)
fork_value=$(yq '.jobs.e2e.steps[] | select(.name == "Install Cozystack into sandbox") | .env.COZY_LINSTOR_DRBD_ENABLED' .github/workflows/e2e-fork.yaml)
make_command=$(make -n -C packages/core/testing SANDBOX_NAME=test COZY_LINSTOR_DRBD_ENABLED=false install-cozystack)
if [ "$workflow_value" != "false" ]; then
echo "container workflow does not set COZY_LINSTOR_DRBD_ENABLED=false" >&2
return 1
fi
if [ "$fork_value" != "false" ]; then
echo "fork workflow does not set COZY_LINSTOR_DRBD_ENABLED=false" >&2
return 1
fi
if ! printf '%s\n' "$make_command" | grep -Fq -- '-e COZY_LINSTOR_DRBD_ENABLED="false"'; then
echo "testing Makefile does not forward COZY_LINSTOR_DRBD_ENABLED" >&2
return 1
fi
}
@test "a selector list is emitted under one disabledPackages key, merged with the container pair" {
manifest=$(COZY_LINSTOR_DRBD_ENABLED=false COZY_DISABLED_PACKAGES="cozystack.goldpinger cozystack.linstor cozystack.keda" hack/e2e-platform-packages.sh)
disabled=$(printf '%s\n' "$manifest" | yq 'select(.metadata.name == "cozystack.cozystack-platform") | .spec.components.platform.values.bundles.disabledPackages | join(",")')
if [ "$disabled" != "cozystack.linstor,cozystack.kubevirt-cdi,cozystack.goldpinger,cozystack.keda" ]; then
echo "selector list was not merged once with the container pair: $disabled" >&2
return 1
fi
}
@test "a selector list alone leaves the platform-managed packages in place" {
manifest=$(COZY_DISABLED_PACKAGES="cozystack.goldpinger cozystack.keda" hack/e2e-platform-packages.sh)
names=$(printf '%s\n' "$manifest" | yq -N '.metadata.name')
disabled=$(printf '%s\n' "$manifest" | yq '.spec.components.platform.values.bundles.disabledPackages | join(",")')
if [ "$names" != "cozystack.cozystack-platform" ]; then
echo "a selector list unexpectedly replaced a platform package: $names" >&2
return 1
fi
if [ "$disabled" != "cozystack.goldpinger,cozystack.keda" ]; then
echo "selector list was not emitted as given: $disabled" >&2
return 1
fi
}
@test "no selector list emits no disabledPackages key" {
manifest=$(hack/e2e-platform-packages.sh)
key=$(printf '%s\n' "$manifest" | yq '.spec.components.platform.values.bundles | has("disabledPackages")')
if [ "$key" != "false" ]; then
echo "default manifest carries disabledPackages: $key" >&2
return 1
fi
}
@test "a malformed package name fails before emitting YAML" {
for bad in "goldpinger" "cozystack." "cozystack.Gold" "cozystack.a;b"; do
if manifest=$(COZY_DISABLED_PACKAGES="cozystack.keda $bad" hack/e2e-platform-packages.sh 2>/dev/null); then
echo "malformed package name '$bad' unexpectedly succeeded" >&2
return 1
fi
if [ -n "$manifest" ]; then
echo "malformed package name '$bad' emitted a partial manifest" >&2
return 1
fi
done
}
@test "both gating workflows select before installing and forward the list" {
make_command=$(make -n -C packages/core/testing SANDBOX_NAME=test COZY_DISABLED_PACKAGES="cozystack.keda" install-cozystack)
if ! printf '%s\n' "$make_command" | grep -Fq -- '-e COZY_DISABLED_PACKAGES="cozystack.keda"'; then
echo "testing Makefile does not forward COZY_DISABLED_PACKAGES" >&2
return 1
fi
for wf in .github/workflows/pull-requests.yaml .github/workflows/e2e-fork.yaml; do
select_at=$(yq '.jobs.e2e.steps | to_entries | .[] | select(.value.name == "Select E2E tests") | .key' "$wf")
install_at=$(yq '.jobs.e2e.steps | to_entries | .[] | select(.value.name == "Install Cozystack into sandbox") | .key' "$wf")
forwarded=$(yq '.jobs.e2e.steps[] | select(.name == "Install Cozystack into sandbox") | .env.COZY_DISABLED_PACKAGES' "$wf")
if [ -z "$select_at" ] || [ -z "$install_at" ] || [ "$select_at" -ge "$install_at" ]; then
echo "$wf: selection (step $select_at) does not precede the install (step $install_at)" >&2
return 1
fi
if [ "$forwarded" != '${{ steps.select.outputs.disabled }}' ]; then
echo "$wf: install does not take the selector list: $forwarded" >&2
return 1
fi
done
}