Browse code

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 authored on 2022/03/29 23:43:33
Showing 2 changed files
... ...
@@ -18,7 +18,7 @@ func (cli *Client) ContainerList(ctx context.Context, options types.ContainerLis
18 18
 		query.Set("all", "1")
19 19
 	}
20 20
 
21
-	if options.Limit != -1 {
21
+	if options.Limit > 0 {
22 22
 		query.Set("limit", strconv.Itoa(options.Limit))
23 23
 	}
24 24
 
... ...
@@ -39,8 +39,8 @@ func TestContainerList(t *testing.T) {
39 39
 				return nil, fmt.Errorf("all not set in URL query properly. Expected '1', got %s", all)
40 40
 			}
41 41
 			limit := query.Get("limit")
42
-			if limit != "0" {
43
-				return nil, fmt.Errorf("limit should have not be present in query. Expected '0', got %s", limit)
42
+			if limit != "" {
43
+				return nil, fmt.Errorf("limit should have not be present in query, got %s", limit)
44 44
 			}
45 45
 			since := query.Get("since")
46 46
 			if since != "container" {
... ...
@@ -48,7 +48,7 @@ func TestContainerList(t *testing.T) {
48 48
 			}
49 49
 			before := query.Get("before")
50 50
 			if before != "" {
51
-				return nil, fmt.Errorf("before should have not be present in query, go %s", before)
51
+				return nil, fmt.Errorf("before should have not be present in query, got %s", before)
52 52
 			}
53 53
 			size := query.Get("size")
54 54
 			if size != "1" {