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