Skip to content

Commit

Permalink
fix(CVP-4421) get_unreleased_bundles returns a jq error
Browse files Browse the repository at this point in the history
1. Fix get_unreleased_bundles returning a jq error
The variables that were passed to jq --argjson
were not valid json arrays
2. Modify get_highest_bundle_version to return
a bundle image field rather than a bundle name
Signed-off-by: Anna Rania <[email protected]>
  • Loading branch information
Anna Rania committed Feb 11, 2025
1 parent f9a0dbb commit 52dc685
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
23 changes: 20 additions & 3 deletions test/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -628,9 +628,14 @@ extract_differential_fbc_metadata() {
unique_index=$(echo "$package_result_index" | jq -s "flatten(1) | unique")
fi

# Convert multiple JSON arrays on separate lines to form a single valid JSON array
# Failure to do so will result in "jq: invalid JSON text passed to --argjson"
unique_index_json=$(echo "$unique_index" | jq -s 'add')
unique_fbc_json=$(echo "$unique_fbc" | jq -s 'add')

# Get the images that are only in the fbc fragment
local unreleased_result
unreleased_result=$(jq -n --argjson released "$unique_index" --argjson unreleased "$unique_fbc" '{"released": $released,"unreleased":$unreleased} | .unreleased-.released')
unreleased_result=$(jq -n --argjson released "$unique_index_json" --argjson unreleased "$unique_fbc_json" '{"released": $released,"unreleased":$unreleased} | .unreleased-.released')
echo "$unreleased_result"
}

Expand Down Expand Up @@ -948,5 +953,17 @@ get_highest_bundle_version() {
exit 1
fi

echo "$highest_bundle"
}
# Find the corresponding image name for the highest bundle
local bundle_image
bundle_image=$(echo "$RENDER_OUT_FBC" | jq -r --arg bundle "$highest_bundle" '
select(.schema == "olm.bundle" and .name == $bundle) | .image
')

# Check if an image was found
if [[ -z "$bundle_image" || "$bundle_image" == "null" ]]; then
echo "get_highest_bundle_version: No image found for bundle: $highest_bundle" >&2
exit 1
fi

echo "$bundle_image"
}
9 changes: 8 additions & 1 deletion unittests_bash/test_utils.bats
Original file line number Diff line number Diff line change
Expand Up @@ -674,10 +674,17 @@ EOF
}
]
}
{
"schema": "olm.bundle",
"name": "kubevirt-hyperconverged-operator.v4.17.5",
"package": "kubevirt-hyperconverged-v1",
"image": "registry.redhat.io/container-native-virtualization/hco-bundle-registry@sha256:12345",
"properties": []
}
EOF
)
run get_highest_bundle_version "${RENDER_OUT_FBC}" "${PACKAGE_NAME}" "${CHANNEL_NAME}"
EXPECTED_RESPONSE="kubevirt-hyperconverged-operator.v4.17.5"
EXPECTED_RESPONSE="registry.redhat.io/container-native-virtualization/hco-bundle-registry@sha256:12345"
echo "${output}"
[[ "${EXPECTED_RESPONSE}" = "${output}" && "$status" -eq 0 ]]
}
Expand Down

0 comments on commit 52dc685

Please sign in to comment.