check_test.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. package main
  2. import (
  3. "fmt"
  4. "os"
  5. "path/filepath"
  6. "testing"
  7. "github.com/docker/docker/cliconfig"
  8. "github.com/docker/docker/pkg/reexec"
  9. "github.com/go-check/check"
  10. )
  11. func Test(t *testing.T) {
  12. reexec.Init() // This is required for external graphdriver tests
  13. if !isLocalDaemon {
  14. fmt.Println("INFO: Testing against a remote daemon")
  15. } else {
  16. fmt.Println("INFO: Testing against a local daemon")
  17. }
  18. check.TestingT(t)
  19. }
  20. func init() {
  21. check.Suite(&DockerSuite{})
  22. }
  23. type DockerSuite struct {
  24. }
  25. func (s *DockerSuite) TearDownTest(c *check.C) {
  26. unpauseAllContainers()
  27. deleteAllContainers()
  28. deleteAllImages()
  29. deleteAllVolumes()
  30. deleteAllNetworks()
  31. }
  32. func init() {
  33. check.Suite(&DockerRegistrySuite{
  34. ds: &DockerSuite{},
  35. })
  36. }
  37. type DockerRegistrySuite struct {
  38. ds *DockerSuite
  39. reg *testRegistryV2
  40. d *Daemon
  41. }
  42. func (s *DockerRegistrySuite) SetUpTest(c *check.C) {
  43. testRequires(c, DaemonIsLinux, RegistryHosting)
  44. s.reg = setupRegistry(c, false, "", "")
  45. s.d = NewDaemon(c)
  46. }
  47. func (s *DockerRegistrySuite) TearDownTest(c *check.C) {
  48. if s.reg != nil {
  49. s.reg.Close()
  50. }
  51. if s.d != nil {
  52. s.d.Stop()
  53. }
  54. s.ds.TearDownTest(c)
  55. }
  56. func init() {
  57. check.Suite(&DockerSchema1RegistrySuite{
  58. ds: &DockerSuite{},
  59. })
  60. }
  61. type DockerSchema1RegistrySuite struct {
  62. ds *DockerSuite
  63. reg *testRegistryV2
  64. d *Daemon
  65. }
  66. func (s *DockerSchema1RegistrySuite) SetUpTest(c *check.C) {
  67. testRequires(c, DaemonIsLinux, RegistryHosting)
  68. s.reg = setupRegistry(c, true, "", "")
  69. s.d = NewDaemon(c)
  70. }
  71. func (s *DockerSchema1RegistrySuite) TearDownTest(c *check.C) {
  72. if s.reg != nil {
  73. s.reg.Close()
  74. }
  75. if s.d != nil {
  76. s.d.Stop()
  77. }
  78. s.ds.TearDownTest(c)
  79. }
  80. func init() {
  81. check.Suite(&DockerRegistryAuthHtpasswdSuite{
  82. ds: &DockerSuite{},
  83. })
  84. }
  85. type DockerRegistryAuthHtpasswdSuite struct {
  86. ds *DockerSuite
  87. reg *testRegistryV2
  88. d *Daemon
  89. }
  90. func (s *DockerRegistryAuthHtpasswdSuite) SetUpTest(c *check.C) {
  91. testRequires(c, DaemonIsLinux, RegistryHosting)
  92. s.reg = setupRegistry(c, false, "htpasswd", "")
  93. s.d = NewDaemon(c)
  94. }
  95. func (s *DockerRegistryAuthHtpasswdSuite) TearDownTest(c *check.C) {
  96. if s.reg != nil {
  97. out, err := s.d.Cmd("logout", privateRegistryURL)
  98. c.Assert(err, check.IsNil, check.Commentf(out))
  99. s.reg.Close()
  100. }
  101. if s.d != nil {
  102. s.d.Stop()
  103. }
  104. s.ds.TearDownTest(c)
  105. }
  106. func init() {
  107. check.Suite(&DockerRegistryAuthTokenSuite{
  108. ds: &DockerSuite{},
  109. })
  110. }
  111. type DockerRegistryAuthTokenSuite struct {
  112. ds *DockerSuite
  113. reg *testRegistryV2
  114. d *Daemon
  115. }
  116. func (s *DockerRegistryAuthTokenSuite) SetUpTest(c *check.C) {
  117. testRequires(c, DaemonIsLinux, RegistryHosting)
  118. s.d = NewDaemon(c)
  119. }
  120. func (s *DockerRegistryAuthTokenSuite) TearDownTest(c *check.C) {
  121. if s.reg != nil {
  122. out, err := s.d.Cmd("logout", privateRegistryURL)
  123. c.Assert(err, check.IsNil, check.Commentf(out))
  124. s.reg.Close()
  125. }
  126. if s.d != nil {
  127. s.d.Stop()
  128. }
  129. s.ds.TearDownTest(c)
  130. }
  131. func (s *DockerRegistryAuthTokenSuite) setupRegistryWithTokenService(c *check.C, tokenURL string) {
  132. if s == nil {
  133. c.Fatal("registry suite isn't initialized")
  134. }
  135. s.reg = setupRegistry(c, false, "token", tokenURL)
  136. }
  137. func init() {
  138. check.Suite(&DockerDaemonSuite{
  139. ds: &DockerSuite{},
  140. })
  141. }
  142. type DockerDaemonSuite struct {
  143. ds *DockerSuite
  144. d *Daemon
  145. }
  146. func (s *DockerDaemonSuite) SetUpTest(c *check.C) {
  147. testRequires(c, DaemonIsLinux)
  148. s.d = NewDaemon(c)
  149. }
  150. func (s *DockerDaemonSuite) TearDownTest(c *check.C) {
  151. testRequires(c, DaemonIsLinux)
  152. if s.d != nil {
  153. s.d.Stop()
  154. }
  155. s.ds.TearDownTest(c)
  156. }
  157. func init() {
  158. check.Suite(&DockerTrustSuite{
  159. ds: &DockerSuite{},
  160. })
  161. }
  162. type DockerTrustSuite struct {
  163. ds *DockerSuite
  164. reg *testRegistryV2
  165. not *testNotary
  166. }
  167. func (s *DockerTrustSuite) SetUpTest(c *check.C) {
  168. testRequires(c, RegistryHosting, NotaryServerHosting)
  169. s.reg = setupRegistry(c, false, "", "")
  170. s.not = setupNotary(c)
  171. }
  172. func (s *DockerTrustSuite) TearDownTest(c *check.C) {
  173. if s.reg != nil {
  174. s.reg.Close()
  175. }
  176. if s.not != nil {
  177. s.not.Close()
  178. }
  179. // Remove trusted keys and metadata after test
  180. os.RemoveAll(filepath.Join(cliconfig.ConfigDir(), "trust"))
  181. s.ds.TearDownTest(c)
  182. }