From b55268a0c0eddd7557c25e929958a6282ccd9ce5 Mon Sep 17 00:00:00 2001 From: Mateusz Hawrus <48822818+nieomylnieja@users.noreply.github.com> Date: Tue, 11 Jun 2024 16:50:47 +0200 Subject: [PATCH] chore: Adjust e2e tests for createdAt and createdBy new v1alpha Project.Spec fields (#144) ## Motivation With the introduction of new server-side computed fields for v1alpha Project.Spec: `createdAt` and `createdBy` the tests started failing as the helper function `_assert_objects_existence` was comparing almost the whole object. This is too much for a simple assertion that checks if the object was actually applied, so I added additional filter to re-map the objects, extracting the basic minimum for comparison. ## Related Changes - https://github.com/nobl9/nobl9-go/pull/422 ## Testing Run `make test/e2e`, remember about supplying the right env vars OR run https://github.com/nobl9/sloctl/actions/workflows/e2e-tests-dispatch.yml with this branch as target. --- test/test_helper/load.bash | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/test_helper/load.bash b/test/test_helper/load.bash index ece8789..5bd0d7f 100644 --- a/test/test_helper/load.bash +++ b/test/test_helper/load.bash @@ -97,8 +97,11 @@ _assert_objects_existence() { case "$1" in apply) run_sloctl "${args[*]}" + refute_output --partial "No resources found" + # We can't retrieve the same object we applied so we need to compare the minimum. + filter='[.[] | {"name": .metadata.name, "project": .metadata.project, "labels": .metadata.labels, "annotations": .metadata.annotations}] | sort_by(.name, .project)' # shellcheck disable=2154 - have=$(yq --sort-keys -y '[.[] | del(.status)]' <<<"$output") + have=$(yq --sort-keys -y "$filter" <<<"$output") want=$(yq --sort-keys -y '[ .[] | select(.kind == "'"$kind"'") | select(.metadata.name == "'"$name"'") | @@ -106,7 +109,7 @@ _assert_objects_existence() { select(.metadata.project == "'"$project"'") else . - end]' <<<"$2") + end] | '"$filter"'' <<<"$2") assert_equal "$have" "$want" ;; delete)