Skip to content

Commit

Permalink
Merge pull request containers#7739 from zhangguanzhang/apiv2-containe…
Browse files Browse the repository at this point in the history
…rs-limit

apiv2 /containers/json limit differ from docker-api
  • Loading branch information
openshift-merge-robot authored Sep 24, 2020
2 parents c256944 + 873989f commit c3d1cef
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/api/handlers/compat/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func ListContainers(w http.ResponseWriter, r *http.Request) {
utils.InternalServerError(w, err)
return
}
if _, found := r.URL.Query()["limit"]; found && query.Limit != -1 {
if _, found := r.URL.Query()["limit"]; found && query.Limit > 0 {
last := query.Limit
if len(containers) > last {
containers = containers[len(containers)-last:]
Expand Down
25 changes: 25 additions & 0 deletions test/apiv2/20-containers.at
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,31 @@ t GET containers/$cid/json 200 \
.Config.Cmd='[]' \
.Path="echo" \
.Args[0]="param1"

# create a running container for after
t POST containers/create '"Image":"'$IMAGE'","Entrypoint":["top"]' 201 \
.Id~[0-9a-f]\\{64\\}
cid_top=$(jq -r '.Id' <<<"$output")
t GET containers/${cid_top}/json 200 \
.Config.Entrypoint[0]="top" \
.Config.Cmd='[]' \
.Path="top"
t POST containers/${cid_top}/start '' 204
# make sure the container is running
t GET containers/${cid_top}/json 200 \
.State.Status="running"

# 0 means unlimited, need same with docker
t GET containers/json?limit=0 200 \
.[0].Id~[0-9a-f]\\{64\\}

t GET 'containers/json?limit=0&all=1' 200 \
.[0].Id~[0-9a-f]\\{64\\} \
.[1].Id~[0-9a-f]\\{64\\}

t POST containers/${cid_top}/stop "" 204

t DELETE containers/$cid 204
t DELETE containers/$cid_top 204

# vim: filetype=sh

0 comments on commit c3d1cef

Please sign in to comment.