Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
fleet_version:
- "v0.13.8"
- "latest"
- "latest-prerelease"

steps:
-
Expand All @@ -29,8 +30,10 @@ jobs:
VERSION="${{ matrix.fleet_version }}"
if [ "$VERSION" = "latest" ]; then
VERSION=$(curl -s https://api.github.com/repos/rancher/fleet/releases/latest | jq -r '.tag_name')
elif [ "$VERSION" = "latest-prerelease" ]; then
VERSION=$(curl -s https://api.github.com/repos/rancher/fleet/releases | jq -r '.[0].tag_name')
fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
-
uses: actions/cache@v4
id: fleet-cli-cache
Expand Down
52 changes: 48 additions & 4 deletions tests/test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/usr/bin/env bash
set -e
set -euo pipefail

# Ensure yq is available for YAML normalization
if ! command -v yq &>/dev/null; then
echo "❌ Error: yq is required but not found in PATH"
exit 1
fi

export COMMIT=fake

Expand Down Expand Up @@ -27,6 +33,11 @@ split_and_deploy() {
done < <(awk 'BEGIN{RS="---\n"; ORS="\0"} NF' "$target_yaml")
}

# normalize_yaml FILE: sort list items by kind and name for comparison
normalize_yaml() {
yq 'sort_by(.kind, .metadata.name)' "$1"
}

fleet -v

# run_fixture CASE [NS_ARG]
Expand All @@ -40,7 +51,7 @@ run_fixture() {
local outdir="$SCRIPT_DIR/output/$case"
mkdir -p "$outdir"

pushd "../$case"
pushd "../$case" > /dev/null

# shellcheck disable=SC2086
fleet apply $ns_arg -o - test > "$outdir/bundle.yaml"
Expand All @@ -52,7 +63,7 @@ run_fixture() {

rm "$outdir/target.yaml"

popd
popd > /dev/null
}

for fixture in ./expected/single-cluster/*; do
Expand All @@ -65,7 +76,40 @@ for fixture in ./expected/multi-cluster/*; do
run_fixture "$case" "-n fleet-default"
done

diff -iwqr output expected
# Compare output files, ignoring resource ordering
test_failed=0
shopt -s nullglob
for expected_file in expected/*/*; do
[[ ! -f "$expected_file" ]] && continue

output_file="output/${expected_file#expected/}"

if [[ ! -f "$output_file" ]]; then
echo "❌ Missing: $output_file"
test_failed=1
continue
fi

# Normalize and compare
expected_norm=$(normalize_yaml "$expected_file")
output_norm=$(normalize_yaml "$output_file")

if ! diff -q <(echo "$expected_norm") <(echo "$output_norm") > /dev/null 2>&1; then
if [[ $test_failed -eq 0 ]]; then
echo "❌ Test failed: output differs from expected (ignoring resource order)"
echo ""
echo "=== DIFFERENCES (normalized) ==="
fi
echo "File: $expected_file"
diff -u <(echo "$expected_norm" | head -30) <(echo "$output_norm" | head -30) || true
test_failed=1
fi
done

if [[ $test_failed -eq 1 ]]; then
exit 1
fi

echo All is OK
rm -rf output

Loading