docker_hub_pull_suite_test.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package main
  2. import (
  3. "os/exec"
  4. "runtime"
  5. "strings"
  6. "github.com/docker/docker/pkg/integration/checker"
  7. "github.com/go-check/check"
  8. )
  9. func init() {
  10. // FIXME. Temporarily turning this off for Windows as GH16039 was breaking
  11. // Windows to Linux CI @icecrime
  12. if runtime.GOOS != "windows" {
  13. check.Suite(newDockerHubPullSuite())
  14. }
  15. }
  16. // DockerHubPullSuite provides an isolated daemon that doesn't have all the
  17. // images that are baked into our 'global' test environment daemon (e.g.,
  18. // busybox, httpserver, ...).
  19. //
  20. // We use it for push/pull tests where we want to start fresh, and measure the
  21. // relative impact of each individual operation. As part of this suite, all
  22. // images are removed after each test.
  23. type DockerHubPullSuite struct {
  24. d *Daemon
  25. ds *DockerSuite
  26. }
  27. // newDockerHubPullSuite returns a new instance of a DockerHubPullSuite.
  28. func newDockerHubPullSuite() *DockerHubPullSuite {
  29. return &DockerHubPullSuite{
  30. ds: &DockerSuite{},
  31. }
  32. }
  33. // SetUpSuite starts the suite daemon.
  34. func (s *DockerHubPullSuite) SetUpSuite(c *check.C) {
  35. testRequires(c, DaemonIsLinux)
  36. s.d = NewDaemon(c)
  37. err := s.d.Start()
  38. c.Assert(err, checker.IsNil, check.Commentf("starting push/pull test daemon: %v", err))
  39. }
  40. // TearDownSuite stops the suite daemon.
  41. func (s *DockerHubPullSuite) TearDownSuite(c *check.C) {
  42. if s.d != nil {
  43. err := s.d.Stop()
  44. c.Assert(err, checker.IsNil, check.Commentf("stopping push/pull test daemon: %v", err))
  45. }
  46. }
  47. // SetUpTest declares that all tests of this suite require network.
  48. func (s *DockerHubPullSuite) SetUpTest(c *check.C) {
  49. testRequires(c, Network)
  50. }
  51. // TearDownTest removes all images from the suite daemon.
  52. func (s *DockerHubPullSuite) TearDownTest(c *check.C) {
  53. out := s.Cmd(c, "images", "-aq")
  54. images := strings.Split(out, "\n")
  55. images = append([]string{"rmi", "-f"}, images...)
  56. s.d.Cmd(images...)
  57. s.ds.TearDownTest(c)
  58. }
  59. // Cmd executes a command against the suite daemon and returns the combined
  60. // output. The function fails the test when the command returns an error.
  61. func (s *DockerHubPullSuite) Cmd(c *check.C, name string, arg ...string) string {
  62. out, err := s.CmdWithError(name, arg...)
  63. c.Assert(err, checker.IsNil, check.Commentf("%q failed with errors: %s, %v", strings.Join(arg, " "), out, err))
  64. return out
  65. }
  66. // CmdWithError executes a command against the suite daemon and returns the
  67. // combined output as well as any error.
  68. func (s *DockerHubPullSuite) CmdWithError(name string, arg ...string) (string, error) {
  69. c := s.MakeCmd(name, arg...)
  70. b, err := c.CombinedOutput()
  71. return string(b), err
  72. }
  73. // MakeCmd returns an exec.Cmd command to run against the suite daemon.
  74. func (s *DockerHubPullSuite) MakeCmd(name string, arg ...string) *exec.Cmd {
  75. args := []string{"--host", s.d.sock(), name}
  76. args = append(args, arg...)
  77. return exec.Command(dockerBinary, args...)
  78. }