瀏覽代碼

client: container ps: don't set "limit" if none was set

both -1 and 0 are accepted as "no limit", so don't send the
limit option if no limit was set. For simplicity, we're ignoring
values <= 0.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 3 年之前
父節點
當前提交
890231f46b
共有 2 個文件被更改,包括 4 次插入4 次删除
  1. 1 1
      client/container_list.go
  2. 3 3
      client/container_list_test.go

+ 1 - 1
client/container_list.go

@@ -18,7 +18,7 @@ func (cli *Client) ContainerList(ctx context.Context, options types.ContainerLis
 		query.Set("all", "1")
 		query.Set("all", "1")
 	}
 	}
 
 
-	if options.Limit != -1 {
+	if options.Limit > 0 {
 		query.Set("limit", strconv.Itoa(options.Limit))
 		query.Set("limit", strconv.Itoa(options.Limit))
 	}
 	}
 
 

+ 3 - 3
client/container_list_test.go

@@ -39,8 +39,8 @@ func TestContainerList(t *testing.T) {
 				return nil, fmt.Errorf("all not set in URL query properly. Expected '1', got %s", all)
 				return nil, fmt.Errorf("all not set in URL query properly. Expected '1', got %s", all)
 			}
 			}
 			limit := query.Get("limit")
 			limit := query.Get("limit")
-			if limit != "0" {
-				return nil, fmt.Errorf("limit should have not be present in query. Expected '0', got %s", limit)
+			if limit != "" {
+				return nil, fmt.Errorf("limit should have not be present in query, got %s", limit)
 			}
 			}
 			since := query.Get("since")
 			since := query.Get("since")
 			if since != "container" {
 			if since != "container" {
@@ -48,7 +48,7 @@ func TestContainerList(t *testing.T) {
 			}
 			}
 			before := query.Get("before")
 			before := query.Get("before")
 			if before != "" {
 			if before != "" {
-				return nil, fmt.Errorf("before should have not be present in query, go %s", before)
+				return nil, fmt.Errorf("before should have not be present in query, got %s", before)
 			}
 			}
 			size := query.Get("size")
 			size := query.Get("size")
 			if size != "1" {
 			if size != "1" {