2015-09-01 14:08:09 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os/exec"
|
2015-09-04 14:46:42 -04:00
|
|
|
"runtime"
|
2015-09-01 14:08:09 -04:00
|
|
|
"strings"
|
|
|
|
|
2016-12-30 12:23:00 -05:00
|
|
|
"github.com/docker/docker/integration-cli/checker"
|
2016-12-09 04:17:53 -05:00
|
|
|
"github.com/docker/docker/integration-cli/daemon"
|
2018-04-13 11:02:56 -04:00
|
|
|
testdaemon "github.com/docker/docker/internal/test/daemon"
|
2015-09-01 14:08:09 -04:00
|
|
|
"github.com/go-check/check"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2015-09-04 14:46:42 -04:00
|
|
|
// FIXME. Temporarily turning this off for Windows as GH16039 was breaking
|
|
|
|
// Windows to Linux CI @icecrime
|
|
|
|
if runtime.GOOS != "windows" {
|
2019-09-09 17:05:58 -04:00
|
|
|
/*check.Suite(newDockerHubPullSuite())*/
|
2015-09-04 14:46:42 -04:00
|
|
|
}
|
2015-09-01 14:08:09 -04:00
|
|
|
}
|
|
|
|
|
2016-05-07 21:36:10 -04:00
|
|
|
// DockerHubPullSuite provides an isolated daemon that doesn't have all the
|
2015-09-01 14:08:09 -04:00
|
|
|
// images that are baked into our 'global' test environment daemon (e.g.,
|
|
|
|
// busybox, httpserver, ...).
|
|
|
|
//
|
|
|
|
// We use it for push/pull tests where we want to start fresh, and measure the
|
|
|
|
// relative impact of each individual operation. As part of this suite, all
|
|
|
|
// images are removed after each test.
|
|
|
|
type DockerHubPullSuite struct {
|
2016-12-09 04:17:53 -05:00
|
|
|
d *daemon.Daemon
|
2015-09-01 14:08:09 -04:00
|
|
|
ds *DockerSuite
|
|
|
|
}
|
|
|
|
|
|
|
|
// newDockerHubPullSuite returns a new instance of a DockerHubPullSuite.
|
|
|
|
func newDockerHubPullSuite() *DockerHubPullSuite {
|
|
|
|
return &DockerHubPullSuite{
|
|
|
|
ds: &DockerSuite{},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetUpSuite starts the suite daemon.
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerHubPullSuite) SetUpSuite(c *testing.T) {
|
2018-12-24 07:25:53 -05:00
|
|
|
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
|
2018-04-13 11:02:56 -04:00
|
|
|
s.d = daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution))
|
2016-12-09 17:20:14 -05:00
|
|
|
s.d.Start(c)
|
2015-09-01 14:08:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// TearDownSuite stops the suite daemon.
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerHubPullSuite) TearDownSuite(c *testing.T) {
|
2015-08-28 13:36:42 -04:00
|
|
|
if s.d != nil {
|
2016-12-09 17:20:14 -05:00
|
|
|
s.d.Stop(c)
|
2015-09-01 14:08:09 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetUpTest declares that all tests of this suite require network.
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerHubPullSuite) SetUpTest(c *testing.T) {
|
2015-09-01 14:08:09 -04:00
|
|
|
testRequires(c, Network)
|
|
|
|
}
|
|
|
|
|
|
|
|
// TearDownTest removes all images from the suite daemon.
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerHubPullSuite) TearDownTest(c *testing.T) {
|
2015-09-01 14:08:09 -04:00
|
|
|
out := s.Cmd(c, "images", "-aq")
|
|
|
|
images := strings.Split(out, "\n")
|
2016-07-22 12:14:05 -04:00
|
|
|
images = append([]string{"rmi", "-f"}, images...)
|
|
|
|
s.d.Cmd(images...)
|
2015-09-01 14:08:09 -04:00
|
|
|
s.ds.TearDownTest(c)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cmd executes a command against the suite daemon and returns the combined
|
|
|
|
// output. The function fails the test when the command returns an error.
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerHubPullSuite) Cmd(c *testing.T, name string, arg ...string) string {
|
2015-09-01 14:08:09 -04:00
|
|
|
out, err := s.CmdWithError(name, arg...)
|
2019-09-09 17:05:57 -04:00
|
|
|
assert.Assert(c, err == nil, check.Commentf("%q failed with errors: %s, %v", strings.Join(arg, " "), out, err))
|
2015-09-01 14:08:09 -04:00
|
|
|
return out
|
|
|
|
}
|
|
|
|
|
|
|
|
// CmdWithError executes a command against the suite daemon and returns the
|
|
|
|
// combined output as well as any error.
|
|
|
|
func (s *DockerHubPullSuite) CmdWithError(name string, arg ...string) (string, error) {
|
|
|
|
c := s.MakeCmd(name, arg...)
|
|
|
|
b, err := c.CombinedOutput()
|
|
|
|
return string(b), err
|
|
|
|
}
|
|
|
|
|
2016-05-07 21:36:10 -04:00
|
|
|
// MakeCmd returns an exec.Cmd command to run against the suite daemon.
|
2015-09-01 14:08:09 -04:00
|
|
|
func (s *DockerHubPullSuite) MakeCmd(name string, arg ...string) *exec.Cmd {
|
2016-12-09 04:17:53 -05:00
|
|
|
args := []string{"--host", s.d.Sock(), name}
|
2015-09-01 14:08:09 -04:00
|
|
|
args = append(args, arg...)
|
|
|
|
return exec.Command(dockerBinary, args...)
|
|
|
|
}
|