Merge pull request #46602 from vvoland/integration-TestPullNonExistingImage
TestPullNonExistingImage: Simplify and move to integration
This commit is contained in:
commit
949f8c9f2a
2 changed files with 40 additions and 74 deletions
|
@ -2,10 +2,8 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
@ -51,78 +49,6 @@ func (s *DockerHubPullSuite) TestPullFromCentralRegistry(c *testing.T) {
|
|||
assert.Assert(c, match, "invalid output for `docker images` (expected image and tag name)")
|
||||
}
|
||||
|
||||
// TestPullNonExistingImage pulls non-existing images from the central registry, with different
|
||||
// combinations of implicit tag and library prefix.
|
||||
func (s *DockerHubPullSuite) TestPullNonExistingImage(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
type entry struct {
|
||||
repo string
|
||||
alias string
|
||||
tag string
|
||||
}
|
||||
|
||||
entries := []entry{
|
||||
{"asdfasdf", "asdfasdf", "foobar"},
|
||||
{"asdfasdf", "library/asdfasdf", "foobar"},
|
||||
{"asdfasdf", "asdfasdf", ""},
|
||||
{"asdfasdf", "asdfasdf", "latest"},
|
||||
{"asdfasdf", "library/asdfasdf", ""},
|
||||
{"asdfasdf", "library/asdfasdf", "latest"},
|
||||
}
|
||||
|
||||
// The option field indicates "-a" or not.
|
||||
type record struct {
|
||||
e entry
|
||||
option string
|
||||
out string
|
||||
err error
|
||||
}
|
||||
|
||||
// Execute 'docker pull' in parallel, pass results (out, err) and
|
||||
// necessary information ("-a" or not, and the image name) to channel.
|
||||
var group sync.WaitGroup
|
||||
recordChan := make(chan record, len(entries)*2)
|
||||
for _, e := range entries {
|
||||
group.Add(1)
|
||||
go func(e entry) {
|
||||
defer group.Done()
|
||||
repoName := e.alias
|
||||
if e.tag != "" {
|
||||
repoName += ":" + e.tag
|
||||
}
|
||||
out, err := s.CmdWithError("pull", repoName)
|
||||
recordChan <- record{e, "", out, err}
|
||||
}(e)
|
||||
if e.tag == "" {
|
||||
// pull -a on a nonexistent registry should fall back as well
|
||||
group.Add(1)
|
||||
go func(e entry) {
|
||||
defer group.Done()
|
||||
out, err := s.CmdWithError("pull", "-a", e.alias)
|
||||
recordChan <- record{e, "-a", out, err}
|
||||
}(e)
|
||||
}
|
||||
}
|
||||
|
||||
// Wait for completion
|
||||
group.Wait()
|
||||
close(recordChan)
|
||||
|
||||
// Process the results (out, err).
|
||||
for record := range recordChan {
|
||||
if len(record.option) == 0 {
|
||||
assert.ErrorContains(c, record.err, "", "expected non-zero exit status when pulling non-existing image: %s", record.out)
|
||||
assert.Assert(c, strings.Contains(record.out, fmt.Sprintf("pull access denied for %s, repository does not exist or may require 'docker login'", record.e.repo)), "expected image not found error messages")
|
||||
} else {
|
||||
// pull -a on a nonexistent registry should fall back as well
|
||||
assert.ErrorContains(c, record.err, "", "expected non-zero exit status when pulling non-existing image: %s", record.out)
|
||||
assert.Assert(c, strings.Contains(record.out, fmt.Sprintf("pull access denied for %s, repository does not exist or may require 'docker login'", record.e.repo)), "expected image not found error messages")
|
||||
assert.Assert(c, !strings.Contains(record.out, "unauthorized"), `message should not contain "unauthorized"`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestPullFromCentralRegistryImplicitRefParts pulls an image from the central registry and verifies
|
||||
// that pulling the same image with different combinations of implicit elements of the image
|
||||
// reference (tag, repository, central registry url, ...) doesn't trigger a new pull nor leads to
|
||||
|
|
|
@ -3,9 +3,11 @@ package image
|
|||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/containerd/containerd"
|
||||
|
@ -21,6 +23,7 @@ import (
|
|||
"github.com/opencontainers/image-spec/specs-go"
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"gotest.tools/v3/assert"
|
||||
is "gotest.tools/v3/assert/cmp"
|
||||
"gotest.tools/v3/skip"
|
||||
)
|
||||
|
||||
|
@ -155,3 +158,40 @@ func TestImagePullStoredfDigestForOtherRepo(t *testing.T) {
|
|||
assert.Assert(t, err != nil, "Expected error, got none: %v", err)
|
||||
assert.Assert(t, errdefs.IsNotFound(err), err)
|
||||
}
|
||||
|
||||
// TestImagePullNonExisting pulls non-existing images from the central registry, with different
|
||||
// combinations of implicit tag and library prefix.
|
||||
func TestImagePullNonExisting(t *testing.T) {
|
||||
ctx := setupTest(t)
|
||||
|
||||
for _, ref := range []string{
|
||||
"asdfasdf:foobar",
|
||||
"library/asdfasdf:foobar",
|
||||
"asdfasdf",
|
||||
"asdfasdf:latest",
|
||||
"library/asdfasdf",
|
||||
"library/asdfasdf:latest",
|
||||
} {
|
||||
ref := ref
|
||||
all := strings.Contains(ref, ":")
|
||||
t.Run(ref, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
client := testEnv.APIClient()
|
||||
rdr, err := client.ImagePull(ctx, ref, types.ImagePullOptions{
|
||||
All: all,
|
||||
})
|
||||
if err == nil {
|
||||
rdr.Close()
|
||||
}
|
||||
|
||||
expectedMsg := fmt.Sprintf("pull access denied for %s, repository does not exist or may require 'docker login'", "asdfasdf")
|
||||
assert.Assert(t, is.ErrorContains(err, expectedMsg))
|
||||
assert.Check(t, is.ErrorType(err, errdefs.IsNotFound))
|
||||
if all {
|
||||
// pull -a on a nonexistent registry should fall back as well
|
||||
assert.Check(t, !strings.Contains(err.Error(), "unauthorized"), `message should not contain "unauthorized"`)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue