github.com/go/docker@v1.12.0-rc2/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 const defaultSwarmPort = 2477 188 189 func init() { 190 check.Suite(&DockerSwarmSuite{ 191 ds: &DockerSuite{}, 192 }) 193 } 194 195 type DockerSwarmSuite struct { 196 ds *DockerSuite 197 daemons []*SwarmDaemon 198 portIndex int 199 } 200 201 func (s *DockerSwarmSuite) SetUpTest(c *check.C) { 202 testRequires(c, DaemonIsLinux) 203 } 204 205 func (s *DockerSwarmSuite) AddDaemon(c *check.C, joinSwarm, manager bool) *SwarmDaemon { 206 d := &SwarmDaemon{ 207 Daemon: NewDaemon(c), 208 port: defaultSwarmPort + s.portIndex, 209 } 210 d.listenAddr = fmt.Sprintf("0.0.0.0:%d", d.port) 211 err := d.StartWithBusybox() 212 c.Assert(err, check.IsNil) 213 214 if joinSwarm == true { 215 if len(s.daemons) > 0 { 216 c.Assert(d.Join(s.daemons[0].listenAddr, "", "", manager), check.IsNil) 217 } else { 218 aa := make(map[string]bool) 219 aa["worker"] = true 220 aa["manager"] = true 221 c.Assert(d.Init(aa, ""), check.IsNil) 222 } 223 } 224 225 s.portIndex++ 226 s.daemons = append(s.daemons, d) 227 228 return d 229 } 230 231 func (s *DockerSwarmSuite) TearDownTest(c *check.C) { 232 testRequires(c, DaemonIsLinux) 233 for _, d := range s.daemons { 234 d.Stop() 235 } 236 s.daemons = nil 237 s.portIndex = 0 238 239 s.ds.TearDownTest(c) 240 } 241 242 func init() { 243 check.Suite(&DockerTrustSuite{ 244 ds: &DockerSuite{}, 245 }) 246 } 247 248 type DockerTrustSuite struct { 249 ds *DockerSuite 250 reg *testRegistryV2 251 not *testNotary 252 } 253 254 func (s *DockerTrustSuite) SetUpTest(c *check.C) { 255 testRequires(c, RegistryHosting, NotaryServerHosting) 256 s.reg = setupRegistry(c, false, "", "") 257 s.not = setupNotary(c) 258 } 259 260 func (s *DockerTrustSuite) TearDownTest(c *check.C) { 261 if s.reg != nil { 262 s.reg.Close() 263 } 264 if s.not != nil { 265 s.not.Close() 266 } 267 268 // Remove trusted keys and metadata after test 269 os.RemoveAll(filepath.Join(cliconfig.ConfigDir(), "trust")) 270 s.ds.TearDownTest(c) 271 }