Browse code

client: ImageImport: omit empty query-parameters

Don't set query-parameters for options that weren't set.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2024/11/19 01:39:37
Showing 2 changed files
... ...
@@ -21,10 +21,18 @@ func (cli *Client) ImageImport(ctx context.Context, source image.ImportSource, r
21 21
 	}
22 22
 
23 23
 	query := url.Values{}
24
-	query.Set("fromSrc", source.SourceName)
25
-	query.Set("repo", ref)
26
-	query.Set("tag", options.Tag)
27
-	query.Set("message", options.Message)
24
+	if source.SourceName != "" {
25
+		query.Set("fromSrc", source.SourceName)
26
+	}
27
+	if ref != "" {
28
+		query.Set("repo", ref)
29
+	}
30
+	if options.Tag != "" {
31
+		query.Set("tag", options.Tag)
32
+	}
33
+	if options.Message != "" {
34
+		query.Set("message", options.Message)
35
+	}
28 36
 	if options.Platform != "" {
29 37
 		query.Set("platform", strings.ToLower(options.Platform))
30 38
 	}
... ...
@@ -37,9 +37,7 @@ func TestImageImport(t *testing.T) {
37 37
 			doc: "no options",
38 38
 			expectedQueryParams: url.Values{
39 39
 				"fromSrc": {"image_source"},
40
-				"message": {""},
41 40
 				"repo":    {"repository_name:imported"},
42
-				"tag":     {""},
43 41
 			},
44 42
 		},
45 43
 		{
... ...
@@ -64,10 +62,8 @@ func TestImageImport(t *testing.T) {
64 64
 			},
65 65
 			expectedQueryParams: url.Values{
66 66
 				"fromSrc":  {"image_source"},
67
-				"message":  {""},
68 67
 				"platform": {"linux/amd64"},
69 68
 				"repo":     {"repository_name:imported"},
70
-				"tag":      {""},
71 69
 			},
72 70
 		},
73 71
 	}