2015-04-18 16:46:47 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-06-05 20:09:53 +00:00
|
|
|
"fmt"
|
2016-03-09 08:18:30 +00:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2015-04-18 16:46:47 +00:00
|
|
|
"testing"
|
|
|
|
|
2016-03-09 08:18:30 +00:00
|
|
|
"github.com/docker/docker/cliconfig"
|
2015-06-05 20:09:53 +00:00
|
|
|
"github.com/docker/docker/pkg/reexec"
|
2016-06-20 02:00:45 +00:00
|
|
|
"github.com/docker/engine-api/types/swarm"
|
2015-04-18 16:46:47 +00:00
|
|
|
"github.com/go-check/check"
|
|
|
|
)
|
|
|
|
|
2015-04-22 18:20:32 +00:00
|
|
|
func Test(t *testing.T) {
|
2015-06-05 20:09:53 +00:00
|
|
|
reexec.Init() // This is required for external graphdriver tests
|
|
|
|
|
|
|
|
if !isLocalDaemon {
|
|
|
|
fmt.Println("INFO: Testing against a remote daemon")
|
|
|
|
} else {
|
|
|
|
fmt.Println("INFO: Testing against a local daemon")
|
|
|
|
}
|
|
|
|
|
2015-04-22 18:20:32 +00:00
|
|
|
check.TestingT(t)
|
|
|
|
}
|
2015-04-18 16:46:47 +00:00
|
|
|
|
2015-04-24 21:16:56 +00:00
|
|
|
func init() {
|
|
|
|
check.Suite(&DockerSuite{})
|
|
|
|
}
|
|
|
|
|
2015-04-18 16:46:47 +00:00
|
|
|
type DockerSuite struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TearDownTest(c *check.C) {
|
2015-10-27 20:12:33 +00:00
|
|
|
unpauseAllContainers()
|
2015-04-18 16:46:47 +00:00
|
|
|
deleteAllContainers()
|
2015-04-23 21:39:31 +00:00
|
|
|
deleteAllImages()
|
2015-06-12 13:25:32 +00:00
|
|
|
deleteAllVolumes()
|
2015-10-13 21:18:05 +00:00
|
|
|
deleteAllNetworks()
|
2015-04-18 16:46:47 +00:00
|
|
|
}
|
|
|
|
|
2015-04-24 21:16:56 +00:00
|
|
|
func init() {
|
|
|
|
check.Suite(&DockerRegistrySuite{
|
|
|
|
ds: &DockerSuite{},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
type DockerRegistrySuite struct {
|
|
|
|
ds *DockerSuite
|
|
|
|
reg *testRegistryV2
|
2015-09-16 17:42:17 +00:00
|
|
|
d *Daemon
|
2015-04-24 21:16:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerRegistrySuite) SetUpTest(c *check.C) {
|
2016-01-29 21:35:20 +00:00
|
|
|
testRequires(c, DaemonIsLinux, RegistryHosting)
|
2016-03-14 20:11:35 +00:00
|
|
|
s.reg = setupRegistry(c, false, "", "")
|
2015-09-16 17:42:17 +00:00
|
|
|
s.d = NewDaemon(c)
|
2015-04-24 21:16:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerRegistrySuite) TearDownTest(c *check.C) {
|
2015-07-23 09:40:54 +00:00
|
|
|
if s.reg != nil {
|
|
|
|
s.reg.Close()
|
|
|
|
}
|
2016-01-13 09:51:01 +00:00
|
|
|
if s.d != nil {
|
|
|
|
s.d.Stop()
|
2015-07-23 09:40:54 +00:00
|
|
|
}
|
2016-01-13 09:51:01 +00:00
|
|
|
s.ds.TearDownTest(c)
|
2015-04-24 21:16:56 +00:00
|
|
|
}
|
2015-04-26 02:47:42 +00:00
|
|
|
|
2015-12-18 23:06:23 +00:00
|
|
|
func init() {
|
|
|
|
check.Suite(&DockerSchema1RegistrySuite{
|
|
|
|
ds: &DockerSuite{},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
type DockerSchema1RegistrySuite struct {
|
|
|
|
ds *DockerSuite
|
|
|
|
reg *testRegistryV2
|
|
|
|
d *Daemon
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSchema1RegistrySuite) SetUpTest(c *check.C) {
|
2016-07-04 10:09:46 +00:00
|
|
|
testRequires(c, DaemonIsLinux, RegistryHosting, NotArm64)
|
2016-03-14 20:11:35 +00:00
|
|
|
s.reg = setupRegistry(c, true, "", "")
|
2015-12-18 23:06:23 +00:00
|
|
|
s.d = NewDaemon(c)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSchema1RegistrySuite) TearDownTest(c *check.C) {
|
|
|
|
if s.reg != nil {
|
|
|
|
s.reg.Close()
|
|
|
|
}
|
2016-01-13 09:51:01 +00:00
|
|
|
if s.d != nil {
|
|
|
|
s.d.Stop()
|
2015-12-18 23:06:23 +00:00
|
|
|
}
|
2016-01-13 09:51:01 +00:00
|
|
|
s.ds.TearDownTest(c)
|
2015-12-18 23:06:23 +00:00
|
|
|
}
|
|
|
|
|
2016-01-23 18:45:01 +00:00
|
|
|
func init() {
|
2016-03-14 20:11:35 +00:00
|
|
|
check.Suite(&DockerRegistryAuthHtpasswdSuite{
|
2016-01-23 18:45:01 +00:00
|
|
|
ds: &DockerSuite{},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-03-14 20:11:35 +00:00
|
|
|
type DockerRegistryAuthHtpasswdSuite struct {
|
2016-01-23 18:45:01 +00:00
|
|
|
ds *DockerSuite
|
|
|
|
reg *testRegistryV2
|
|
|
|
d *Daemon
|
|
|
|
}
|
|
|
|
|
2016-03-14 20:11:35 +00:00
|
|
|
func (s *DockerRegistryAuthHtpasswdSuite) SetUpTest(c *check.C) {
|
2016-01-29 21:35:20 +00:00
|
|
|
testRequires(c, DaemonIsLinux, RegistryHosting)
|
2016-03-14 20:11:35 +00:00
|
|
|
s.reg = setupRegistry(c, false, "htpasswd", "")
|
2016-01-23 18:45:01 +00:00
|
|
|
s.d = NewDaemon(c)
|
|
|
|
}
|
|
|
|
|
2016-03-14 20:11:35 +00:00
|
|
|
func (s *DockerRegistryAuthHtpasswdSuite) TearDownTest(c *check.C) {
|
2016-01-23 18:45:01 +00:00
|
|
|
if s.reg != nil {
|
|
|
|
out, err := s.d.Cmd("logout", privateRegistryURL)
|
|
|
|
c.Assert(err, check.IsNil, check.Commentf(out))
|
|
|
|
s.reg.Close()
|
|
|
|
}
|
|
|
|
if s.d != nil {
|
|
|
|
s.d.Stop()
|
|
|
|
}
|
|
|
|
s.ds.TearDownTest(c)
|
|
|
|
}
|
|
|
|
|
2016-03-14 20:11:35 +00:00
|
|
|
func init() {
|
|
|
|
check.Suite(&DockerRegistryAuthTokenSuite{
|
|
|
|
ds: &DockerSuite{},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
type DockerRegistryAuthTokenSuite struct {
|
|
|
|
ds *DockerSuite
|
|
|
|
reg *testRegistryV2
|
|
|
|
d *Daemon
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerRegistryAuthTokenSuite) SetUpTest(c *check.C) {
|
|
|
|
testRequires(c, DaemonIsLinux, RegistryHosting)
|
|
|
|
s.d = NewDaemon(c)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerRegistryAuthTokenSuite) TearDownTest(c *check.C) {
|
|
|
|
if s.reg != nil {
|
|
|
|
out, err := s.d.Cmd("logout", privateRegistryURL)
|
|
|
|
c.Assert(err, check.IsNil, check.Commentf(out))
|
|
|
|
s.reg.Close()
|
|
|
|
}
|
|
|
|
if s.d != nil {
|
|
|
|
s.d.Stop()
|
|
|
|
}
|
|
|
|
s.ds.TearDownTest(c)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerRegistryAuthTokenSuite) setupRegistryWithTokenService(c *check.C, tokenURL string) {
|
|
|
|
if s == nil {
|
|
|
|
c.Fatal("registry suite isn't initialized")
|
|
|
|
}
|
|
|
|
s.reg = setupRegistry(c, false, "token", tokenURL)
|
|
|
|
}
|
|
|
|
|
2015-04-26 02:47:42 +00:00
|
|
|
func init() {
|
|
|
|
check.Suite(&DockerDaemonSuite{
|
|
|
|
ds: &DockerSuite{},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
type DockerDaemonSuite struct {
|
|
|
|
ds *DockerSuite
|
|
|
|
d *Daemon
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerDaemonSuite) SetUpTest(c *check.C) {
|
2015-08-28 17:36:42 +00:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-04-26 02:47:42 +00:00
|
|
|
s.d = NewDaemon(c)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerDaemonSuite) TearDownTest(c *check.C) {
|
2015-08-28 17:36:42 +00:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2016-01-13 09:51:01 +00:00
|
|
|
if s.d != nil {
|
|
|
|
s.d.Stop()
|
|
|
|
}
|
2015-04-26 02:47:42 +00:00
|
|
|
s.ds.TearDownTest(c)
|
|
|
|
}
|
2015-07-20 05:56:10 +00:00
|
|
|
|
2016-06-14 02:54:20 +00:00
|
|
|
const defaultSwarmPort = 2477
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
check.Suite(&DockerSwarmSuite{
|
|
|
|
ds: &DockerSuite{},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
type DockerSwarmSuite struct {
|
|
|
|
ds *DockerSuite
|
|
|
|
daemons []*SwarmDaemon
|
|
|
|
portIndex int
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSwarmSuite) SetUpTest(c *check.C) {
|
|
|
|
testRequires(c, DaemonIsLinux)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSwarmSuite) AddDaemon(c *check.C, joinSwarm, manager bool) *SwarmDaemon {
|
|
|
|
d := &SwarmDaemon{
|
|
|
|
Daemon: NewDaemon(c),
|
|
|
|
port: defaultSwarmPort + s.portIndex,
|
|
|
|
}
|
|
|
|
d.listenAddr = fmt.Sprintf("0.0.0.0:%d", d.port)
|
2016-06-24 19:09:53 +00:00
|
|
|
err := d.StartWithBusybox("--iptables=false") // avoid networking conflicts
|
2016-06-14 02:54:20 +00:00
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
|
|
|
if joinSwarm == true {
|
|
|
|
if len(s.daemons) > 0 {
|
2016-06-20 02:00:45 +00:00
|
|
|
c.Assert(d.Join(swarm.JoinRequest{
|
|
|
|
RemoteAddrs: []string{s.daemons[0].listenAddr},
|
|
|
|
Manager: manager}), check.IsNil)
|
2016-06-14 02:54:20 +00:00
|
|
|
} else {
|
2016-06-20 02:00:45 +00:00
|
|
|
c.Assert(d.Init(swarm.InitRequest{
|
|
|
|
Spec: swarm.Spec{
|
|
|
|
AcceptancePolicy: autoAcceptPolicy,
|
|
|
|
},
|
|
|
|
}), check.IsNil)
|
2016-06-14 02:54:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
s.portIndex++
|
|
|
|
s.daemons = append(s.daemons, d)
|
|
|
|
|
|
|
|
return d
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSwarmSuite) TearDownTest(c *check.C) {
|
|
|
|
testRequires(c, DaemonIsLinux)
|
|
|
|
for _, d := range s.daemons {
|
|
|
|
d.Stop()
|
|
|
|
}
|
|
|
|
s.daemons = nil
|
|
|
|
s.portIndex = 0
|
|
|
|
|
|
|
|
s.ds.TearDownTest(c)
|
|
|
|
}
|
|
|
|
|
2015-07-20 05:56:10 +00:00
|
|
|
func init() {
|
|
|
|
check.Suite(&DockerTrustSuite{
|
|
|
|
ds: &DockerSuite{},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
type DockerTrustSuite struct {
|
|
|
|
ds *DockerSuite
|
|
|
|
reg *testRegistryV2
|
|
|
|
not *testNotary
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerTrustSuite) SetUpTest(c *check.C) {
|
2016-03-11 22:11:35 +00:00
|
|
|
testRequires(c, RegistryHosting, NotaryServerHosting)
|
2016-03-14 20:11:35 +00:00
|
|
|
s.reg = setupRegistry(c, false, "", "")
|
2015-07-20 05:56:10 +00:00
|
|
|
s.not = setupNotary(c)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerTrustSuite) TearDownTest(c *check.C) {
|
2016-01-13 09:51:01 +00:00
|
|
|
if s.reg != nil {
|
|
|
|
s.reg.Close()
|
|
|
|
}
|
|
|
|
if s.not != nil {
|
|
|
|
s.not.Close()
|
|
|
|
}
|
2016-03-09 08:18:30 +00:00
|
|
|
|
|
|
|
// Remove trusted keys and metadata after test
|
|
|
|
os.RemoveAll(filepath.Join(cliconfig.ConfigDir(), "trust"))
|
2015-07-20 05:56:10 +00:00
|
|
|
s.ds.TearDownTest(c)
|
|
|
|
}
|