Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
| ... | ... |
@@ -2,7 +2,6 @@ package main |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"context" |
| 5 |
- "fmt" |
|
| 6 | 5 |
"regexp" |
| 7 | 6 |
"strings" |
| 8 | 7 |
"testing" |
| ... | ... |
@@ -50,43 +49,6 @@ func (s *DockerHubPullSuite) TestPullFromCentralRegistry(c *testing.T) {
|
| 50 | 50 |
assert.Assert(c, match, "invalid output for `docker images` (expected image and tag name)") |
| 51 | 51 |
} |
| 52 | 52 |
|
| 53 |
-// TestPullNonExistingImage pulls non-existing images from the central registry, with different |
|
| 54 |
-// combinations of implicit tag and library prefix. |
|
| 55 |
-func (s *DockerHubPullSuite) TestPullNonExistingImage(c *testing.T) {
|
|
| 56 |
- testRequires(c, DaemonIsLinux) |
|
| 57 |
- |
|
| 58 |
- for _, ref := range []string{
|
|
| 59 |
- "asdfasdf:foobar", |
|
| 60 |
- "library/asdfasdf:foobar", |
|
| 61 |
- "asdfasdf", |
|
| 62 |
- "asdfasdf:latest", |
|
| 63 |
- "library/asdfasdf", |
|
| 64 |
- "library/asdfasdf:latest", |
|
| 65 |
- } {
|
|
| 66 |
- ref := ref |
|
| 67 |
- all := strings.Contains(ref, ":") |
|
| 68 |
- c.Run(ref, func(t *testing.T) {
|
|
| 69 |
- t.Parallel() |
|
| 70 |
- |
|
| 71 |
- var out string |
|
| 72 |
- var err error |
|
| 73 |
- if all {
|
|
| 74 |
- out, err = s.CmdWithError("pull", "-a", repoName)
|
|
| 75 |
- } else {
|
|
| 76 |
- out, err = s.CmdWithError("pull", repoName)
|
|
| 77 |
- } |
|
| 78 |
- |
|
| 79 |
- expectedRepo := "asdfasdf" |
|
| 80 |
- assert.Check(t, is.ErrorContains(err, ""), "expected non-zero exit status when pulling non-existing image: %s", out) |
|
| 81 |
- assert.Check(t, is.Contains(out, fmt.Sprintf("pull access denied for %s, repository does not exist or may require 'docker login'", expectedRepo)))
|
|
| 82 |
- if all {
|
|
| 83 |
- // pull -a on a nonexistent registry should fall back as well |
|
| 84 |
- assert.Check(t, !strings.Contains(out, "unauthorized"), `message should not contain "unauthorized"`) |
|
| 85 |
- } |
|
| 86 |
- }) |
|
| 87 |
- } |
|
| 88 |
-} |
|
| 89 |
- |
|
| 90 | 53 |
// TestPullFromCentralRegistryImplicitRefParts pulls an image from the central registry and verifies |
| 91 | 54 |
// that pulling the same image with different combinations of implicit elements of the image |
| 92 | 55 |
// reference (tag, repository, central registry url, ...) doesn't trigger a new pull nor leads to |
| ... | ... |
@@ -3,9 +3,11 @@ package image |
| 3 | 3 |
import ( |
| 4 | 4 |
"context" |
| 5 | 5 |
"encoding/json" |
| 6 |
+ "fmt" |
|
| 6 | 7 |
"io" |
| 7 | 8 |
"os" |
| 8 | 9 |
"path" |
| 10 |
+ "strings" |
|
| 9 | 11 |
"testing" |
| 10 | 12 |
|
| 11 | 13 |
"github.com/containerd/containerd" |
| ... | ... |
@@ -21,6 +23,7 @@ import ( |
| 21 | 21 |
"github.com/opencontainers/image-spec/specs-go" |
| 22 | 22 |
ocispec "github.com/opencontainers/image-spec/specs-go/v1" |
| 23 | 23 |
"gotest.tools/v3/assert" |
| 24 |
+ is "gotest.tools/v3/assert/cmp" |
|
| 24 | 25 |
"gotest.tools/v3/skip" |
| 25 | 26 |
) |
| 26 | 27 |
|
| ... | ... |
@@ -155,3 +158,40 @@ func TestImagePullStoredfDigestForOtherRepo(t *testing.T) {
|
| 155 | 155 |
assert.Assert(t, err != nil, "Expected error, got none: %v", err) |
| 156 | 156 |
assert.Assert(t, errdefs.IsNotFound(err), err) |
| 157 | 157 |
} |
| 158 |
+ |
|
| 159 |
+// TestImagePullNonExisting pulls non-existing images from the central registry, with different |
|
| 160 |
+// combinations of implicit tag and library prefix. |
|
| 161 |
+func TestImagePullNonExisting(t *testing.T) {
|
|
| 162 |
+ ctx := setupTest(t) |
|
| 163 |
+ |
|
| 164 |
+ for _, ref := range []string{
|
|
| 165 |
+ "asdfasdf:foobar", |
|
| 166 |
+ "library/asdfasdf:foobar", |
|
| 167 |
+ "asdfasdf", |
|
| 168 |
+ "asdfasdf:latest", |
|
| 169 |
+ "library/asdfasdf", |
|
| 170 |
+ "library/asdfasdf:latest", |
|
| 171 |
+ } {
|
|
| 172 |
+ ref := ref |
|
| 173 |
+ all := strings.Contains(ref, ":") |
|
| 174 |
+ t.Run(ref, func(t *testing.T) {
|
|
| 175 |
+ t.Parallel() |
|
| 176 |
+ |
|
| 177 |
+ client := testEnv.APIClient() |
|
| 178 |
+ rdr, err := client.ImagePull(ctx, ref, types.ImagePullOptions{
|
|
| 179 |
+ All: all, |
|
| 180 |
+ }) |
|
| 181 |
+ if err == nil {
|
|
| 182 |
+ rdr.Close() |
|
| 183 |
+ } |
|
| 184 |
+ |
|
| 185 |
+ expectedMsg := fmt.Sprintf("pull access denied for %s, repository does not exist or may require 'docker login'", "asdfasdf")
|
|
| 186 |
+ assert.Assert(t, is.ErrorContains(err, expectedMsg)) |
|
| 187 |
+ assert.Check(t, is.ErrorType(err, errdefs.IsNotFound)) |
|
| 188 |
+ if all {
|
|
| 189 |
+ // pull -a on a nonexistent registry should fall back as well |
|
| 190 |
+ assert.Check(t, !strings.Contains(err.Error(), "unauthorized"), `message should not contain "unauthorized"`) |
|
| 191 |
+ } |
|
| 192 |
+ }) |
|
| 193 |
+ } |
|
| 194 |
+} |