Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ee54c64

Browse filesBrowse files
vvolandthaJeztah
authored andcommitted
client/image_tag: Wrap options and result
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
1 parent 6da02f8 commit ee54c64
Copy full SHA for ee54c64

13 files changed

+72-49Lines changed: 72 additions & 49 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎client/client_interfaces.go‎

Copy file name to clipboardExpand all lines: client/client_interfaces.go
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ type ImageAPIClient interface {
115115
ImagePush(ctx context.Context, ref string, options ImagePushOptions) (ImagePushResponse, error)
116116
ImageRemove(ctx context.Context, image string, options ImageRemoveOptions) (ImageRemoveResult, error)
117117
ImageSearch(ctx context.Context, term string, options ImageSearchOptions) (ImageSearchResult, error)
118-
ImageTag(ctx context.Context, image, ref string) error
118+
ImageTag(ctx context.Context, options ImageTagOptions) (ImageTagResult, error)
119119
ImagesPrune(ctx context.Context, opts ImagePruneOptions) (ImagePruneResult, error)
120120

121121
ImageInspect(ctx context.Context, image string, _ ...ImageInspectOption) (ImageInspectResult, error)
Collapse file

‎client/image_tag.go‎

Copy file name to clipboardExpand all lines: client/image_tag.go
+15-5Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,29 @@ import (
99
"github.com/distribution/reference"
1010
)
1111

12+
type ImageTagOptions struct {
13+
Source string
14+
Target string
15+
}
16+
17+
type ImageTagResult struct{}
18+
1219
// ImageTag tags an image in the docker host
13-
func (cli *Client) ImageTag(ctx context.Context, source, target string) error {
20+
func (cli *Client) ImageTag(ctx context.Context, options ImageTagOptions) (ImageTagResult, error) {
21+
source := options.Source
22+
target := options.Target
23+
1424
if _, err := reference.ParseAnyReference(source); err != nil {
15-
return fmt.Errorf("error parsing reference: %q is not a valid repository/tag: %w", source, err)
25+
return ImageTagResult{}, fmt.Errorf("error parsing reference: %q is not a valid repository/tag: %w", source, err)
1626
}
1727

1828
ref, err := reference.ParseNormalizedNamed(target)
1929
if err != nil {
20-
return fmt.Errorf("error parsing reference: %q is not a valid repository/tag: %w", target, err)
30+
return ImageTagResult{}, fmt.Errorf("error parsing reference: %q is not a valid repository/tag: %w", target, err)
2131
}
2232

2333
if _, ok := ref.(reference.Digested); ok {
24-
return errors.New("refusing to create a tag with a digest reference")
34+
return ImageTagResult{}, errors.New("refusing to create a tag with a digest reference")
2535
}
2636

2737
ref = reference.TagNameOnly(ref)
@@ -34,5 +44,5 @@ func (cli *Client) ImageTag(ctx context.Context, source, target string) error {
3444

3545
resp, err := cli.post(ctx, "/images/"+source+"/tag", query, nil, nil)
3646
defer ensureReaderClosed(resp)
37-
return err
47+
return ImageTagResult{}, err
3848
}
Collapse file

‎client/image_tag_test.go‎

Copy file name to clipboardExpand all lines: client/image_tag_test.go
+9-9Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func TestImageTagError(t *testing.T) {
1818
client, err := NewClientWithOpts(WithMockClient(errorMock(http.StatusInternalServerError, "Server error")))
1919
assert.NilError(t, err)
2020

21-
err = client.ImageTag(context.Background(), "image_id", "repo:tag")
21+
_, err = client.ImageTag(context.Background(), ImageTagOptions{Source: "image_id", Target: "repo:tag"})
2222
assert.Check(t, is.ErrorType(err, cerrdefs.IsInternal))
2323
}
2424

@@ -28,7 +28,7 @@ func TestImageTagInvalidReference(t *testing.T) {
2828
client, err := NewClientWithOpts(WithMockClient(errorMock(http.StatusInternalServerError, "Server error")))
2929
assert.NilError(t, err)
3030

31-
err = client.ImageTag(context.Background(), "image_id", "aa/asdf$$^/aa")
31+
_, err = client.ImageTag(context.Background(), ImageTagOptions{Source: "image_id", Target: "aa/asdf$$^/aa"})
3232
assert.Check(t, is.Error(err, `error parsing reference: "aa/asdf$$^/aa" is not a valid repository/tag: invalid reference format`))
3333
}
3434

@@ -43,7 +43,7 @@ func TestImageTagInvalidSourceImageName(t *testing.T) {
4343
for _, repo := range invalidRepos {
4444
t.Run("invalidRepo/"+repo, func(t *testing.T) {
4545
t.Parallel()
46-
err := client.ImageTag(ctx, "busybox", repo)
46+
_, err := client.ImageTag(ctx, ImageTagOptions{Source: "busybox", Target: repo})
4747
assert.Check(t, is.ErrorContains(err, "not a valid repository/tag"))
4848
})
4949
}
@@ -53,26 +53,26 @@ func TestImageTagInvalidSourceImageName(t *testing.T) {
5353
for _, repotag := range invalidTags {
5454
t.Run("invalidTag/"+repotag, func(t *testing.T) {
5555
t.Parallel()
56-
err := client.ImageTag(ctx, "busybox", repotag)
56+
_, err := client.ImageTag(ctx, ImageTagOptions{Source: "busybox", Target: repotag})
5757
assert.Check(t, is.ErrorContains(err, "not a valid repository/tag"))
5858
})
5959
}
6060

6161
t.Run("test repository name begin with '-'", func(t *testing.T) {
6262
t.Parallel()
63-
err := client.ImageTag(ctx, "busybox:latest", "-busybox:test")
63+
_, err := client.ImageTag(ctx, ImageTagOptions{Source: "busybox:latest", Target: "-busybox:test"})
6464
assert.Check(t, is.ErrorContains(err, "error parsing reference"))
6565
})
6666

6767
t.Run("test namespace name begin with '-'", func(t *testing.T) {
6868
t.Parallel()
69-
err := client.ImageTag(ctx, "busybox:latest", "-test/busybox:test")
69+
_, err := client.ImageTag(ctx, ImageTagOptions{Source: "busybox:latest", Target: "-test/busybox:test"})
7070
assert.Check(t, is.ErrorContains(err, "error parsing reference"))
7171
})
7272

7373
t.Run("test index name begin with '-'", func(t *testing.T) {
7474
t.Parallel()
75-
err := client.ImageTag(ctx, "busybox:latest", "-index:5000/busybox:test")
75+
_, err := client.ImageTag(ctx, ImageTagOptions{Source: "busybox:latest", Target: "-index:5000/busybox:test"})
7676
assert.Check(t, is.ErrorContains(err, "error parsing reference"))
7777
})
7878
}
@@ -91,7 +91,7 @@ func TestImageTagHexSource(t *testing.T) {
9191
client, err := NewClientWithOpts(WithMockClient(errorMock(http.StatusOK, "OK")))
9292
assert.NilError(t, err)
9393

94-
err = client.ImageTag(context.Background(), "0d409d33b27e47423b049f7f863faa08655a8c901749c2b25b93ca67d01a470d", "repo:tag")
94+
_, err = client.ImageTag(context.Background(), ImageTagOptions{Source: "0d409d33b27e47423b049f7f863faa08655a8c901749c2b25b93ca67d01a470d", Target: "repo:tag"})
9595
assert.NilError(t, err)
9696
}
9797

@@ -169,7 +169,7 @@ func TestImageTag(t *testing.T) {
169169
}, nil
170170
}))
171171
assert.NilError(t, err)
172-
err = client.ImageTag(context.Background(), "image_id", tagCase.reference)
172+
_, err = client.ImageTag(context.Background(), ImageTagOptions{Source: "image_id", Target: tagCase.reference})
173173
assert.NilError(t, err)
174174
}
175175
}
Collapse file

‎integration-cli/docker_api_build_test.go‎

Copy file name to clipboardExpand all lines: integration-cli/docker_api_build_test.go
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ func (s *DockerRegistrySuite) TestBuildCopyFromForcePull(c *testing.T) {
344344
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
345345
// tag the image to upload it to the private registry
346346
ctx := testutil.GetContext(c)
347-
err := apiClient.ImageTag(ctx, "busybox", repoName)
347+
_, err := apiClient.ImageTag(ctx, client.ImageTagOptions{Source: "busybox", Target: repoName})
348348
assert.Check(c, err)
349349
// push the image to the registry
350350
rc, err := apiClient.ImagePush(ctx, repoName, client.ImagePushOptions{RegistryAuth: "{}"})
Collapse file

‎integration/image/inspect_test.go‎

Copy file name to clipboardExpand all lines: integration/image/inspect_test.go
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestImageInspectUniqueRepoDigests(t *testing.T) {
5151

5252
for _, tag := range []string{"master", "newest"} {
5353
imgName := "busybox:" + tag
54-
err := apiClient.ImageTag(ctx, "busybox", imgName)
54+
_, err := apiClient.ImageTag(ctx, client.ImageTagOptions{Source: "busybox", Target: imgName})
5555
assert.NilError(t, err)
5656
defer func() {
5757
_, _ = apiClient.ImageRemove(ctx, imgName, client.ImageRemoveOptions{Force: true})
Collapse file

‎integration/image/list_test.go‎

Copy file name to clipboardExpand all lines: integration/image/list_test.go
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestImagesFilterMultiReference(t *testing.T) {
3636
}
3737

3838
for _, repoTag := range repoTags {
39-
err := apiClient.ImageTag(ctx, "busybox:latest", repoTag)
39+
_, err := apiClient.ImageTag(ctx, client.ImageTagOptions{Source: "busybox:latest", Target: repoTag})
4040
assert.NilError(t, err)
4141
}
4242

@@ -140,7 +140,7 @@ func TestAPIImagesFilters(t *testing.T) {
140140
apiClient := testEnv.APIClient()
141141

142142
for _, n := range []string{"utest:tag1", "utest/docker:tag2", "utest:5000/docker:tag3"} {
143-
err := apiClient.ImageTag(ctx, "busybox:latest", n)
143+
_, err := apiClient.ImageTag(ctx, client.ImageTagOptions{Source: "busybox:latest", Target: n})
144144
assert.NilError(t, err)
145145
}
146146

Collapse file

‎integration/image/prune_test.go‎

Copy file name to clipboardExpand all lines: integration/image/prune_test.go
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ func TestPruneLexographicalOrder(t *testing.T) {
7474

7575
tags := []string{"h", "a", "j", "o", "s", "q", "w", "e", "r", "t"}
7676
for _, tag := range tags {
77-
err = apiClient.ImageTag(ctx, id, "busybox:"+tag)
77+
_, err = apiClient.ImageTag(ctx, client.ImageTagOptions{Source: id, Target: "busybox:" + tag})
7878
assert.NilError(t, err)
7979
}
80-
err = apiClient.ImageTag(ctx, id, "busybox:z")
80+
_, err = apiClient.ImageTag(ctx, client.ImageTagOptions{Source: id, Target: "busybox:z"})
8181
assert.NilError(t, err)
8282

8383
_, err = apiClient.ImageRemove(ctx, "busybox:latest", client.ImageRemoveOptions{Force: true})
@@ -127,7 +127,8 @@ func TestPruneDontDeleteUsedImage(t *testing.T) {
127127
// busybox:other tag pointing to the same image.
128128
name: "two tags",
129129
prepare: func(t *testing.T, d *daemon.Daemon, apiClient *client.Client) error {
130-
return apiClient.ImageTag(ctx, "busybox:latest", "busybox:a")
130+
_, err := apiClient.ImageTag(ctx, client.ImageTagOptions{Source: "busybox:latest", Target: "busybox:a"})
131+
return err
131132
},
132133
check: func(t *testing.T, apiClient *client.Client, pruned image.PruneReport) {
133134
if assert.Check(t, is.Len(pruned.ImagesDeleted, 1)) {
Collapse file

‎integration/image/pull_test.go‎

Copy file name to clipboardExpand all lines: integration/image/pull_test.go
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ func TestImagePullKeepOldAsDangling(t *testing.T) {
216216

217217
t.Log(inspect1)
218218

219-
assert.NilError(t, apiClient.ImageTag(ctx, "busybox:latest", "alpine:latest"))
219+
_, err = apiClient.ImageTag(ctx, client.ImageTagOptions{Source: "busybox:latest", Target: "alpine:latest"})
220+
assert.NilError(t, err)
220221

221222
_, err = apiClient.ImageRemove(ctx, "busybox:latest", client.ImageRemoveOptions{})
222223
assert.NilError(t, err)
Collapse file

‎integration/image/remove_test.go‎

Copy file name to clipboardExpand all lines: integration/image/remove_test.go
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func TestRemoveByDigest(t *testing.T) {
7171
ctx := setupTest(t)
7272
apiClient := testEnv.APIClient()
7373

74-
err := apiClient.ImageTag(ctx, "busybox", "test-remove-by-digest:latest")
74+
_, err := apiClient.ImageTag(ctx, client.ImageTagOptions{Source: "busybox", Target: "test-remove-by-digest:latest"})
7575
assert.NilError(t, err)
7676

7777
inspect, err := apiClient.ImageInspect(ctx, "test-remove-by-digest")
Collapse file

‎integration/image/tag_test.go‎

Copy file name to clipboardExpand all lines: integration/image/tag_test.go
+18-17Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"testing"
66

7+
"github.com/moby/moby/client"
78
"gotest.tools/v3/assert"
89
is "gotest.tools/v3/assert/cmp"
910
)
@@ -12,38 +13,38 @@ import (
1213
func TestTagUnprefixedRepoByNameOrName(t *testing.T) {
1314
ctx := setupTest(t)
1415

15-
client := testEnv.APIClient()
16+
apiClient := testEnv.APIClient()
1617

1718
// By name
18-
err := client.ImageTag(ctx, "busybox:latest", "testfoobarbaz")
19+
_, err := apiClient.ImageTag(ctx, client.ImageTagOptions{Source: "busybox:latest", Target: "testfoobarbaz"})
1920
assert.NilError(t, err)
2021

2122
// By ID
22-
insp, err := client.ImageInspect(ctx, "busybox")
23+
insp, err := apiClient.ImageInspect(ctx, "busybox")
2324
assert.NilError(t, err)
24-
err = client.ImageTag(ctx, insp.ID, "testfoobarbaz")
25+
_, err = apiClient.ImageTag(ctx, client.ImageTagOptions{Source: insp.ID, Target: "testfoobarbaz"})
2526
assert.NilError(t, err)
2627
}
2728

2829
func TestTagUsingDigestAlgorithmAsName(t *testing.T) {
2930
ctx := setupTest(t)
30-
client := testEnv.APIClient()
31-
err := client.ImageTag(ctx, "busybox:latest", "sha256:sometag")
31+
apiClient := testEnv.APIClient()
32+
_, err := apiClient.ImageTag(ctx, client.ImageTagOptions{Source: "busybox:latest", Target: "sha256:sometag"})
3233
assert.Check(t, is.ErrorContains(err, "refusing to create an ambiguous tag using digest algorithm as name"))
3334
}
3435

3536
// ensure we allow the use of valid tags
3637
func TestTagValidPrefixedRepo(t *testing.T) {
3738
ctx := setupTest(t)
3839

39-
client := testEnv.APIClient()
40+
apiClient := testEnv.APIClient()
4041

4142
validRepos := []string{"fooo/bar", "fooaa/test", "foooo:t", "HOSTNAME.DOMAIN.COM:443/foo/bar"}
4243

4344
for _, repo := range validRepos {
4445
t.Run(repo, func(t *testing.T) {
4546
t.Parallel()
46-
err := client.ImageTag(ctx, "busybox", repo)
47+
_, err := apiClient.ImageTag(ctx, client.ImageTagOptions{Source: "busybox", Target: repo})
4748
assert.NilError(t, err)
4849
})
4950
}
@@ -52,17 +53,17 @@ func TestTagValidPrefixedRepo(t *testing.T) {
5253
// tag an image with an existed tag name without -f option should work
5354
func TestTagExistedNameWithoutForce(t *testing.T) {
5455
ctx := setupTest(t)
55-
client := testEnv.APIClient()
56+
apiClient := testEnv.APIClient()
5657

57-
err := client.ImageTag(ctx, "busybox:latest", "busybox:test")
58+
_, err := apiClient.ImageTag(ctx, client.ImageTagOptions{Source: "busybox:latest", Target: "busybox:test"})
5859
assert.NilError(t, err)
5960
}
6061

6162
// ensure tagging using official names works
6263
// ensure all tags result in the same name
6364
func TestTagOfficialNames(t *testing.T) {
6465
ctx := setupTest(t)
65-
client := testEnv.APIClient()
66+
apiClient := testEnv.APIClient()
6667

6768
names := []string{
6869
"docker.io/busybox",
@@ -74,16 +75,16 @@ func TestTagOfficialNames(t *testing.T) {
7475

7576
for _, name := range names {
7677
t.Run("tag from busybox to "+name, func(t *testing.T) {
77-
err := client.ImageTag(ctx, "busybox", name+":latest")
78+
_, err := apiClient.ImageTag(ctx, client.ImageTagOptions{Source: "busybox", Target: name + ":latest"})
7879
assert.NilError(t, err)
7980

8081
// ensure we don't have multiple tag names.
81-
insp, err := client.ImageInspect(ctx, "busybox")
82+
insp, err := apiClient.ImageInspect(ctx, "busybox")
8283
assert.NilError(t, err)
8384
// TODO(vvoland): Not sure what's actually being tested here. Is is still doing anything useful?
8485
assert.Assert(t, !is.Contains(insp.RepoTags, name)().Success())
8586

86-
err = client.ImageTag(ctx, name+":latest", "test-tag-official-names/foobar:latest")
87+
_, err = apiClient.ImageTag(ctx, client.ImageTagOptions{Source: name + ":latest", Target: "test-tag-official-names/foobar:latest"})
8788
assert.NilError(t, err)
8889
})
8990
}
@@ -92,14 +93,14 @@ func TestTagOfficialNames(t *testing.T) {
9293
// ensure tags can not match digests
9394
func TestTagMatchesDigest(t *testing.T) {
9495
ctx := setupTest(t)
95-
client := testEnv.APIClient()
96+
apiClient := testEnv.APIClient()
9697

9798
digest := "busybox@sha256:abcdef76720241213f5303bda7704ec4c2ef75613173910a56fb1b6e20251507"
9899
// test setting tag fails
99-
err := client.ImageTag(ctx, "busybox:latest", digest)
100+
_, err := apiClient.ImageTag(ctx, client.ImageTagOptions{Source: "busybox:latest", Target: digest})
100101
assert.Check(t, is.ErrorContains(err, "refusing to create a tag with a digest reference"))
101102

102103
// check that no new image matches the digest
103-
_, err = client.ImageInspect(ctx, digest)
104+
_, err = apiClient.ImageInspect(ctx, digest)
104105
assert.Check(t, is.ErrorContains(err, fmt.Sprintf("No such image: %s", digest)))
105106
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.