|
@@ -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
|