fix(api): Fix 'last' query param for <repo>/tags/list to work without param 'n' (#1777)

Also fix additional issues:
- sorting of tags on calls without pagination parameters ('n' or 'last')
- if 'n' is 0 we should return an empty list and not error

Added tests accordingly

Signed-off-by: Andrei Aaron <aaaron@luxoft.com>
This commit is contained in:
Andrei Aaron
2023-09-08 19:46:17 +03:00
committed by GitHub
parent 7b1e24c99e
commit 24e37eb68b
3 changed files with 282 additions and 40 deletions
+39
View File
@@ -154,6 +154,45 @@ function teardown_file() {
[ $(echo "$output" | jq -r ".manifests | length") -eq 2 ]
}
@test "add and list tags using oras" {
run skopeo --insecure-policy copy --dest-tls-verify=false \
oci:${TEST_DATA_DIR}/golang:1.20 \
docker://127.0.0.1:8080/oras-tags:1.20
[ "$status" -eq 0 ]
run oras tag --plain-http 127.0.0.1:8080/oras-tags:1.20 1 new latest
[ "$status" -eq 0 ]
run oras repo tags --plain-http 127.0.0.1:8080/oras-tags
[ "$status" -eq 0 ]
echo "$output"
[ $(echo "$output" | wc -l) -eq 4 ]
[ "${lines[-1]}" == "new" ]
[ "${lines[-2]}" == "latest" ]
[ "${lines[-3]}" == "1.20" ]
[ "${lines[-4]}" == "1" ]
run oras repo tags --plain-http --last new 127.0.0.1:8080/oras-tags
[ "$status" -eq 0 ]
echo "$output"
[ -z $output ]
run oras repo tags --plain-http --last latest 127.0.0.1:8080/oras-tags
[ "$status" -eq 0 ]
echo "$output"
[ $(echo "$output" | wc -l) -eq 1 ]
[ "${lines[-1]}" == "new" ]
run oras repo tags --plain-http --last "1.20" 127.0.0.1:8080/oras-tags
[ "$status" -eq 0 ]
echo "$output"
[ $(echo "$output" | wc -l) -eq 2 ]
[ "${lines[-2]}" == "latest" ]
[ "${lines[-1]}" == "new" ]
run oras repo tags --plain-http --last "1" 127.0.0.1:8080/oras-tags
[ "$status" -eq 0 ]
echo "$output"
[ $(echo "$output" | wc -l) -eq 3 ]
[ "${lines[-3]}" == "1.20" ]
[ "${lines[-2]}" == "latest" ]
[ "${lines[-1]}" == "new" ]
}
@test "push helm chart" {
run helm package ${BATS_FILE_TMPDIR}/helm-charts/charts/zot -d ${BATS_FILE_TMPDIR}
[ "$status" -eq 0 ]