mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
1d92789b4f
sed -E -i 's#\bcheck\.C\b#testing.T#g' \ -- "integration-cli/check_test.go" "integration-cli/daemon/daemon.go" "integration-cli/daemon/daemon_swarm.go" "integration-cli/daemon_swarm_hack_test.go" "integration-cli/docker_api_attach_test.go" "integration-cli/docker_api_build_test.go" "integration-cli/docker_api_build_windows_test.go" "integration-cli/docker_api_containers_test.go" "integration-cli/docker_api_containers_windows_test.go" "integration-cli/docker_api_exec_resize_test.go" "integration-cli/docker_api_exec_test.go" "integration-cli/docker_api_images_test.go" "integration-cli/docker_api_inspect_test.go" "integration-cli/docker_api_logs_test.go" "integration-cli/docker_api_network_test.go" "integration-cli/docker_api_stats_test.go" "integration-cli/docker_api_swarm_node_test.go" "integration-cli/docker_api_swarm_service_test.go" "integration-cli/docker_api_swarm_test.go" "integration-cli/docker_api_test.go" "integration-cli/docker_cli_attach_test.go" "integration-cli/docker_cli_attach_unix_test.go" "integration-cli/docker_cli_build_test.go" "integration-cli/docker_cli_build_unix_test.go" "integration-cli/docker_cli_by_digest_test.go" "integration-cli/docker_cli_commit_test.go" "integration-cli/docker_cli_cp_from_container_test.go" "integration-cli/docker_cli_cp_test.go" "integration-cli/docker_cli_cp_to_container_test.go" "integration-cli/docker_cli_cp_to_container_unix_test.go" "integration-cli/docker_cli_cp_utils_test.go" "integration-cli/docker_cli_create_test.go" "integration-cli/docker_cli_daemon_plugins_test.go" "integration-cli/docker_cli_daemon_test.go" "integration-cli/docker_cli_events_test.go" "integration-cli/docker_cli_events_unix_test.go" "integration-cli/docker_cli_exec_test.go" "integration-cli/docker_cli_exec_unix_test.go" "integration-cli/docker_cli_external_volume_driver_unix_test.go" "integration-cli/docker_cli_health_test.go" "integration-cli/docker_cli_history_test.go" "integration-cli/docker_cli_images_test.go" "integration-cli/docker_cli_import_test.go" "integration-cli/docker_cli_info_test.go" "integration-cli/docker_cli_info_unix_test.go" "integration-cli/docker_cli_inspect_test.go" "integration-cli/docker_cli_links_test.go" "integration-cli/docker_cli_login_test.go" "integration-cli/docker_cli_logout_test.go" "integration-cli/docker_cli_logs_test.go" "integration-cli/docker_cli_netmode_test.go" "integration-cli/docker_cli_network_unix_test.go" "integration-cli/docker_cli_plugins_logdriver_test.go" "integration-cli/docker_cli_plugins_test.go" "integration-cli/docker_cli_port_test.go" "integration-cli/docker_cli_proxy_test.go" "integration-cli/docker_cli_prune_unix_test.go" "integration-cli/docker_cli_ps_test.go" "integration-cli/docker_cli_pull_local_test.go" "integration-cli/docker_cli_pull_test.go" "integration-cli/docker_cli_push_test.go" "integration-cli/docker_cli_registry_user_agent_test.go" "integration-cli/docker_cli_restart_test.go" "integration-cli/docker_cli_rmi_test.go" "integration-cli/docker_cli_run_test.go" "integration-cli/docker_cli_run_unix_test.go" "integration-cli/docker_cli_save_load_test.go" "integration-cli/docker_cli_save_load_unix_test.go" "integration-cli/docker_cli_search_test.go" "integration-cli/docker_cli_service_create_test.go" "integration-cli/docker_cli_service_health_test.go" "integration-cli/docker_cli_service_logs_test.go" "integration-cli/docker_cli_service_scale_test.go" "integration-cli/docker_cli_sni_test.go" "integration-cli/docker_cli_start_test.go" "integration-cli/docker_cli_stats_test.go" "integration-cli/docker_cli_swarm_test.go" "integration-cli/docker_cli_swarm_unix_test.go" "integration-cli/docker_cli_top_test.go" "integration-cli/docker_cli_update_unix_test.go" "integration-cli/docker_cli_userns_test.go" "integration-cli/docker_cli_v2_only_test.go" "integration-cli/docker_cli_volume_test.go" "integration-cli/docker_deprecated_api_v124_test.go" "integration-cli/docker_deprecated_api_v124_unix_test.go" "integration-cli/docker_hub_pull_suite_test.go" "integration-cli/docker_utils_test.go" "integration-cli/events_utils_test.go" "integration-cli/fixtures_linux_daemon_test.go" "integration-cli/utils_test.go" "pkg/discovery/discovery_test.go" "pkg/discovery/file/file_test.go" "pkg/discovery/generator_test.go" "pkg/discovery/kv/kv_test.go" "pkg/discovery/memory/memory_test.go" "pkg/discovery/nodes/nodes_test.go" Signed-off-by: Tibor Vass <tibor@docker.com>
408 lines
8.8 KiB
Go
408 lines
8.8 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"net/http/httptest"
|
|
"os"
|
|
"path"
|
|
"path/filepath"
|
|
"strconv"
|
|
"sync"
|
|
"syscall"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/docker/docker/integration-cli/cli"
|
|
"github.com/docker/docker/integration-cli/daemon"
|
|
"github.com/docker/docker/integration-cli/environment"
|
|
testdaemon "github.com/docker/docker/internal/test/daemon"
|
|
ienv "github.com/docker/docker/internal/test/environment"
|
|
"github.com/docker/docker/internal/test/fakestorage"
|
|
"github.com/docker/docker/internal/test/fixtures/plugin"
|
|
"github.com/docker/docker/internal/test/registry"
|
|
"github.com/docker/docker/pkg/reexec"
|
|
"github.com/go-check/check"
|
|
"gotest.tools/assert"
|
|
)
|
|
|
|
const (
|
|
// the private registry to use for tests
|
|
privateRegistryURL = registry.DefaultURL
|
|
|
|
// path to containerd's ctr binary
|
|
ctrBinary = "ctr"
|
|
|
|
// the docker daemon binary to use
|
|
dockerdBinary = "dockerd"
|
|
)
|
|
|
|
var (
|
|
testEnv *environment.Execution
|
|
|
|
// the docker client binary to use
|
|
dockerBinary = ""
|
|
)
|
|
|
|
func init() {
|
|
var err error
|
|
|
|
reexec.Init() // This is required for external graphdriver tests
|
|
|
|
testEnv, err = environment.New()
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
func TestMain(m *testing.M) {
|
|
dockerBinary = testEnv.DockerBinary()
|
|
err := ienv.EnsureFrozenImagesLinux(&testEnv.Execution)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
testEnv.Print()
|
|
os.Exit(m.Run())
|
|
}
|
|
|
|
func Test(t *testing.T) {
|
|
cli.SetTestEnvironment(testEnv)
|
|
fakestorage.SetTestEnvironment(&testEnv.Execution)
|
|
ienv.ProtectAll(t, &testEnv.Execution)
|
|
check.TestingT(t)
|
|
}
|
|
|
|
func init() {
|
|
check.Suite(&DockerSuite{})
|
|
}
|
|
|
|
type DockerSuite struct {
|
|
}
|
|
|
|
func (s *DockerSuite) OnTimeout(c *testing.T) {
|
|
if testEnv.IsRemoteDaemon() {
|
|
return
|
|
}
|
|
path := filepath.Join(os.Getenv("DEST"), "docker.pid")
|
|
b, err := ioutil.ReadFile(path)
|
|
if err != nil {
|
|
c.Fatalf("Failed to get daemon PID from %s\n", path)
|
|
}
|
|
|
|
rawPid, err := strconv.ParseInt(string(b), 10, 32)
|
|
if err != nil {
|
|
c.Fatalf("Failed to parse pid from %s: %s\n", path, err)
|
|
}
|
|
|
|
daemonPid := int(rawPid)
|
|
if daemonPid > 0 {
|
|
testdaemon.SignalDaemonDump(daemonPid)
|
|
}
|
|
}
|
|
|
|
func (s *DockerSuite) TearDownTest(c *testing.T) {
|
|
testEnv.Clean(c)
|
|
}
|
|
|
|
func init() {
|
|
check.Suite(&DockerRegistrySuite{
|
|
ds: &DockerSuite{},
|
|
})
|
|
}
|
|
|
|
type DockerRegistrySuite struct {
|
|
ds *DockerSuite
|
|
reg *registry.V2
|
|
d *daemon.Daemon
|
|
}
|
|
|
|
func (s *DockerRegistrySuite) OnTimeout(c *testing.T) {
|
|
s.d.DumpStackAndQuit()
|
|
}
|
|
|
|
func (s *DockerRegistrySuite) SetUpTest(c *testing.T) {
|
|
testRequires(c, DaemonIsLinux, RegistryHosting, testEnv.IsLocalDaemon)
|
|
s.reg = registry.NewV2(c)
|
|
s.reg.WaitReady(c)
|
|
s.d = daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution))
|
|
}
|
|
|
|
func (s *DockerRegistrySuite) TearDownTest(c *testing.T) {
|
|
if s.reg != nil {
|
|
s.reg.Close()
|
|
}
|
|
if s.d != nil {
|
|
s.d.Stop(c)
|
|
}
|
|
s.ds.TearDownTest(c)
|
|
}
|
|
|
|
func init() {
|
|
check.Suite(&DockerSchema1RegistrySuite{
|
|
ds: &DockerSuite{},
|
|
})
|
|
}
|
|
|
|
type DockerSchema1RegistrySuite struct {
|
|
ds *DockerSuite
|
|
reg *registry.V2
|
|
d *daemon.Daemon
|
|
}
|
|
|
|
func (s *DockerSchema1RegistrySuite) OnTimeout(c *testing.T) {
|
|
s.d.DumpStackAndQuit()
|
|
}
|
|
|
|
func (s *DockerSchema1RegistrySuite) SetUpTest(c *testing.T) {
|
|
testRequires(c, DaemonIsLinux, RegistryHosting, NotArm64, testEnv.IsLocalDaemon)
|
|
s.reg = registry.NewV2(c, registry.Schema1)
|
|
s.reg.WaitReady(c)
|
|
s.d = daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution))
|
|
}
|
|
|
|
func (s *DockerSchema1RegistrySuite) TearDownTest(c *testing.T) {
|
|
if s.reg != nil {
|
|
s.reg.Close()
|
|
}
|
|
if s.d != nil {
|
|
s.d.Stop(c)
|
|
}
|
|
s.ds.TearDownTest(c)
|
|
}
|
|
|
|
func init() {
|
|
check.Suite(&DockerRegistryAuthHtpasswdSuite{
|
|
ds: &DockerSuite{},
|
|
})
|
|
}
|
|
|
|
type DockerRegistryAuthHtpasswdSuite struct {
|
|
ds *DockerSuite
|
|
reg *registry.V2
|
|
d *daemon.Daemon
|
|
}
|
|
|
|
func (s *DockerRegistryAuthHtpasswdSuite) OnTimeout(c *testing.T) {
|
|
s.d.DumpStackAndQuit()
|
|
}
|
|
|
|
func (s *DockerRegistryAuthHtpasswdSuite) SetUpTest(c *testing.T) {
|
|
testRequires(c, DaemonIsLinux, RegistryHosting, testEnv.IsLocalDaemon)
|
|
s.reg = registry.NewV2(c, registry.Htpasswd)
|
|
s.reg.WaitReady(c)
|
|
s.d = daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution))
|
|
}
|
|
|
|
func (s *DockerRegistryAuthHtpasswdSuite) TearDownTest(c *testing.T) {
|
|
if s.reg != nil {
|
|
out, err := s.d.Cmd("logout", privateRegistryURL)
|
|
assert.NilError(c, err, out)
|
|
s.reg.Close()
|
|
}
|
|
if s.d != nil {
|
|
s.d.Stop(c)
|
|
}
|
|
s.ds.TearDownTest(c)
|
|
}
|
|
|
|
func init() {
|
|
check.Suite(&DockerRegistryAuthTokenSuite{
|
|
ds: &DockerSuite{},
|
|
})
|
|
}
|
|
|
|
type DockerRegistryAuthTokenSuite struct {
|
|
ds *DockerSuite
|
|
reg *registry.V2
|
|
d *daemon.Daemon
|
|
}
|
|
|
|
func (s *DockerRegistryAuthTokenSuite) OnTimeout(c *testing.T) {
|
|
s.d.DumpStackAndQuit()
|
|
}
|
|
|
|
func (s *DockerRegistryAuthTokenSuite) SetUpTest(c *testing.T) {
|
|
testRequires(c, DaemonIsLinux, RegistryHosting, testEnv.IsLocalDaemon)
|
|
s.d = daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution))
|
|
}
|
|
|
|
func (s *DockerRegistryAuthTokenSuite) TearDownTest(c *testing.T) {
|
|
if s.reg != nil {
|
|
out, err := s.d.Cmd("logout", privateRegistryURL)
|
|
assert.NilError(c, err, out)
|
|
s.reg.Close()
|
|
}
|
|
if s.d != nil {
|
|
s.d.Stop(c)
|
|
}
|
|
s.ds.TearDownTest(c)
|
|
}
|
|
|
|
func (s *DockerRegistryAuthTokenSuite) setupRegistryWithTokenService(c *testing.T, tokenURL string) {
|
|
if s == nil {
|
|
c.Fatal("registry suite isn't initialized")
|
|
}
|
|
s.reg = registry.NewV2(c, registry.Token(tokenURL))
|
|
s.reg.WaitReady(c)
|
|
}
|
|
|
|
func init() {
|
|
check.Suite(&DockerDaemonSuite{
|
|
ds: &DockerSuite{},
|
|
})
|
|
}
|
|
|
|
type DockerDaemonSuite struct {
|
|
ds *DockerSuite
|
|
d *daemon.Daemon
|
|
}
|
|
|
|
func (s *DockerDaemonSuite) OnTimeout(c *testing.T) {
|
|
s.d.DumpStackAndQuit()
|
|
}
|
|
|
|
func (s *DockerDaemonSuite) SetUpTest(c *testing.T) {
|
|
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
|
|
s.d = daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution))
|
|
}
|
|
|
|
func (s *DockerDaemonSuite) TearDownTest(c *testing.T) {
|
|
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
|
|
if s.d != nil {
|
|
s.d.Stop(c)
|
|
}
|
|
s.ds.TearDownTest(c)
|
|
}
|
|
|
|
func (s *DockerDaemonSuite) TearDownSuite(c *testing.T) {
|
|
filepath.Walk(testdaemon.SockRoot, func(path string, fi os.FileInfo, err error) error {
|
|
if err != nil {
|
|
// ignore errors here
|
|
// not cleaning up sockets is not really an error
|
|
return nil
|
|
}
|
|
if fi.Mode() == os.ModeSocket {
|
|
syscall.Unlink(path)
|
|
}
|
|
return nil
|
|
})
|
|
os.RemoveAll(testdaemon.SockRoot)
|
|
}
|
|
|
|
const defaultSwarmPort = 2477
|
|
|
|
func init() {
|
|
check.Suite(&DockerSwarmSuite{
|
|
ds: &DockerSuite{},
|
|
})
|
|
}
|
|
|
|
type DockerSwarmSuite struct {
|
|
server *httptest.Server
|
|
ds *DockerSuite
|
|
daemonsLock sync.Mutex // protect access to daemons and portIndex
|
|
daemons []*daemon.Daemon
|
|
portIndex int
|
|
}
|
|
|
|
func (s *DockerSwarmSuite) OnTimeout(c *testing.T) {
|
|
s.daemonsLock.Lock()
|
|
defer s.daemonsLock.Unlock()
|
|
for _, d := range s.daemons {
|
|
d.DumpStackAndQuit()
|
|
}
|
|
}
|
|
|
|
func (s *DockerSwarmSuite) SetUpTest(c *testing.T) {
|
|
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
|
|
}
|
|
|
|
func (s *DockerSwarmSuite) AddDaemon(c *testing.T, joinSwarm, manager bool) *daemon.Daemon {
|
|
d := daemon.New(c, dockerBinary, dockerdBinary,
|
|
testdaemon.WithEnvironment(testEnv.Execution),
|
|
testdaemon.WithSwarmPort(defaultSwarmPort+s.portIndex),
|
|
)
|
|
if joinSwarm {
|
|
if len(s.daemons) > 0 {
|
|
d.StartAndSwarmJoin(c, s.daemons[0].Daemon, manager)
|
|
} else {
|
|
d.StartAndSwarmInit(c)
|
|
}
|
|
} else {
|
|
d.StartNode(c)
|
|
}
|
|
|
|
s.daemonsLock.Lock()
|
|
s.portIndex++
|
|
s.daemons = append(s.daemons, d)
|
|
s.daemonsLock.Unlock()
|
|
|
|
return d
|
|
}
|
|
|
|
func (s *DockerSwarmSuite) TearDownTest(c *testing.T) {
|
|
testRequires(c, DaemonIsLinux)
|
|
s.daemonsLock.Lock()
|
|
for _, d := range s.daemons {
|
|
if d != nil {
|
|
d.Stop(c)
|
|
d.Cleanup(c)
|
|
}
|
|
}
|
|
s.daemons = nil
|
|
s.portIndex = 0
|
|
s.daemonsLock.Unlock()
|
|
s.ds.TearDownTest(c)
|
|
}
|
|
|
|
func init() {
|
|
check.Suite(&DockerPluginSuite{
|
|
ds: &DockerSuite{},
|
|
})
|
|
}
|
|
|
|
type DockerPluginSuite struct {
|
|
ds *DockerSuite
|
|
registry *registry.V2
|
|
}
|
|
|
|
func (ps *DockerPluginSuite) registryHost() string {
|
|
return privateRegistryURL
|
|
}
|
|
|
|
func (ps *DockerPluginSuite) getPluginRepo() string {
|
|
return path.Join(ps.registryHost(), "plugin", "basic")
|
|
}
|
|
func (ps *DockerPluginSuite) getPluginRepoWithTag() string {
|
|
return ps.getPluginRepo() + ":" + "latest"
|
|
}
|
|
|
|
func (ps *DockerPluginSuite) SetUpSuite(c *testing.T) {
|
|
testRequires(c, DaemonIsLinux, RegistryHosting)
|
|
ps.registry = registry.NewV2(c)
|
|
ps.registry.WaitReady(c)
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
|
|
defer cancel()
|
|
|
|
err := plugin.CreateInRegistry(ctx, ps.getPluginRepo(), nil)
|
|
assert.NilError(c, err, "failed to create plugin")
|
|
}
|
|
|
|
func (ps *DockerPluginSuite) TearDownSuite(c *testing.T) {
|
|
if ps.registry != nil {
|
|
ps.registry.Close()
|
|
}
|
|
}
|
|
|
|
func (ps *DockerPluginSuite) TearDownTest(c *testing.T) {
|
|
ps.ds.TearDownTest(c)
|
|
}
|
|
|
|
func (ps *DockerPluginSuite) OnTimeout(c *testing.T) {
|
|
ps.ds.OnTimeout(c)
|
|
}
|