1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714
|
package main
import (
"context"
"flag"
"fmt"
"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"
"github.com/docker/docker/internal/test/suite"
"github.com/docker/docker/testutil"
testdaemon "github.com/docker/docker/testutil/daemon"
ienv "github.com/docker/docker/testutil/environment"
"github.com/docker/docker/testutil/fakestorage"
"github.com/docker/docker/testutil/fixtures/plugin"
"github.com/docker/docker/testutil/registry"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"gotest.tools/v3/assert"
"gotest.tools/v3/skip"
)
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 (
testEnvOnce sync.Once
testEnv *environment.Execution
// the docker client binary to use
dockerBinary = ""
baseContext context.Context
)
func TestMain(m *testing.M) {
flag.Parse()
os.Exit(testRun(m))
}
func testRun(m *testing.M) (ret int) {
// Global set up
var err error
shutdown := testutil.ConfigureTracing()
ctx, span := otel.Tracer("").Start(context.Background(), "integration-cli/TestMain")
defer func() {
if err != nil {
span.SetStatus(codes.Error, err.Error())
ret = 255
} else {
if ret != 0 {
span.SetAttributes(attribute.Int("exitCode", ret))
span.SetStatus(codes.Error, "m.Run() exited with non-zero code")
}
}
span.End()
shutdown(ctx)
}()
baseContext = ctx
testEnv, err = environment.New(ctx)
if err != nil {
return
}
if testEnv.IsLocalDaemon() {
setupLocalInfo()
}
dockerBinary = testEnv.DockerBinary()
err = ienv.EnsureFrozenImagesLinux(ctx, &testEnv.Execution)
if err != nil {
return
}
testEnv.Print()
printCliVersion()
return m.Run()
}
func printCliVersion() {
// Print output of "docker version"
cli.SetTestEnvironment(testEnv)
cmd := cli.Docker(cli.Args("version"))
if cmd.Error != nil {
fmt.Printf("WARNING: Failed to run 'docker version': %+v\n", cmd.Error)
return
}
fmt.Println("INFO: Testing with docker cli version:")
fmt.Println(cmd.Stdout())
}
func ensureTestEnvSetup(ctx context.Context, t *testing.T) {
testEnvOnce.Do(func() {
cli.SetTestEnvironment(testEnv)
fakestorage.SetTestEnvironment(&testEnv.Execution)
ienv.ProtectAll(ctx, t, &testEnv.Execution)
})
}
func TestDockerAPISuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerAPISuite{ds: &DockerSuite{}})
}
func TestDockerBenchmarkSuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerBenchmarkSuite{ds: &DockerSuite{}})
}
func TestDockerCLIAttachSuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerCLIAttachSuite{ds: &DockerSuite{}})
}
func TestDockerCLIBuildSuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerCLIBuildSuite{ds: &DockerSuite{}})
}
func TestDockerCLICommitSuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerCLICommitSuite{ds: &DockerSuite{}})
}
func TestDockerCLICpSuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerCLICpSuite{ds: &DockerSuite{}})
}
func TestDockerCLICreateSuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerCLICreateSuite{ds: &DockerSuite{}})
}
func TestDockerCLIEventSuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerCLIEventSuite{ds: &DockerSuite{}})
}
func TestDockerCLIExecSuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerCLIExecSuite{ds: &DockerSuite{}})
}
func TestDockerCLIHealthSuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerCLIHealthSuite{ds: &DockerSuite{}})
}
func TestDockerCLIHistorySuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerCLIHistorySuite{ds: &DockerSuite{}})
}
func TestDockerCLIImagesSuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerCLIImagesSuite{ds: &DockerSuite{}})
}
func TestDockerCLIImportSuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerCLIImportSuite{ds: &DockerSuite{}})
}
func TestDockerCLIInfoSuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerCLIInfoSuite{ds: &DockerSuite{}})
}
func TestDockerCLIInspectSuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerCLIInspectSuite{ds: &DockerSuite{}})
}
func TestDockerCLILinksSuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerCLILinksSuite{ds: &DockerSuite{}})
}
func TestDockerCLILoginSuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerCLILoginSuite{ds: &DockerSuite{}})
}
func TestDockerCLILogsSuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerCLILogsSuite{ds: &DockerSuite{}})
}
func TestDockerCLINetmodeSuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerCLINetmodeSuite{ds: &DockerSuite{}})
}
func TestDockerCLINetworkSuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerCLINetworkSuite{ds: &DockerSuite{}})
}
func TestDockerCLIPluginLogDriverSuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerCLIPluginLogDriverSuite{ds: &DockerSuite{}})
}
func TestDockerCLIPluginsSuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerCLIPluginsSuite{ds: &DockerSuite{}})
}
func TestDockerCLIPortSuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerCLIPortSuite{ds: &DockerSuite{}})
}
func TestDockerCLIProxySuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerCLIProxySuite{ds: &DockerSuite{}})
}
func TestDockerCLIPruneSuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerCLIPruneSuite{ds: &DockerSuite{}})
}
func TestDockerCLIPsSuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerCLIPsSuite{ds: &DockerSuite{}})
}
func TestDockerCLIPullSuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerCLIPullSuite{ds: &DockerSuite{}})
}
func TestDockerCLIPushSuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerCLIPushSuite{ds: &DockerSuite{}})
}
func TestDockerCLIRestartSuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerCLIRestartSuite{ds: &DockerSuite{}})
}
func TestDockerCLIRmiSuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerCLIRmiSuite{ds: &DockerSuite{}})
}
func TestDockerCLIRunSuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerCLIRunSuite{ds: &DockerSuite{}})
}
func TestDockerCLISaveLoadSuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerCLISaveLoadSuite{ds: &DockerSuite{}})
}
func TestDockerCLISearchSuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerCLISearchSuite{ds: &DockerSuite{}})
}
func TestDockerCLISNISuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerCLISNISuite{ds: &DockerSuite{}})
}
func TestDockerCLIStartSuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerCLIStartSuite{ds: &DockerSuite{}})
}
func TestDockerCLIStatsSuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerCLIStatsSuite{ds: &DockerSuite{}})
}
func TestDockerCLITopSuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerCLITopSuite{ds: &DockerSuite{}})
}
func TestDockerCLIUpdateSuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerCLIUpdateSuite{ds: &DockerSuite{}})
}
func TestDockerCLIVolumeSuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerCLIVolumeSuite{ds: &DockerSuite{}})
}
func TestDockerRegistrySuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerRegistrySuite{ds: &DockerSuite{}})
}
func TestDockerSchema1RegistrySuite(t *testing.T) {
skip.If(t, testEnv.UsingSnapshotter())
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerSchema1RegistrySuite{ds: &DockerSuite{}})
}
func TestDockerRegistryAuthHtpasswdSuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerRegistryAuthHtpasswdSuite{ds: &DockerSuite{}})
}
func TestDockerRegistryAuthTokenSuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerRegistryAuthTokenSuite{ds: &DockerSuite{}})
}
func TestDockerDaemonSuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerDaemonSuite{ds: &DockerSuite{}})
}
func TestDockerSwarmSuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerSwarmSuite{ds: &DockerSuite{}})
}
func TestDockerPluginSuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerPluginSuite{ds: &DockerSuite{}})
}
func TestDockerExternalVolumeSuite(t *testing.T) {
testRequires(t, DaemonIsLinux)
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerExternalVolumeSuite{ds: &DockerSuite{}})
}
func TestDockerNetworkSuite(t *testing.T) {
testRequires(t, DaemonIsLinux)
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
suite.Run(ctx, t, &DockerNetworkSuite{ds: &DockerSuite{}})
}
func TestDockerHubPullSuite(t *testing.T) {
ctx := testutil.StartSpan(baseContext, t)
ensureTestEnvSetup(ctx, t)
// FIXME. Temporarily turning this off for Windows as GH16039 was breaking
// Windows to Linux CI @icecrime
testRequires(t, DaemonIsLinux)
suite.Run(ctx, t, newDockerHubPullSuite())
}
type DockerSuite struct{}
func (s *DockerSuite) OnTimeout(c *testing.T) {
if testEnv.IsRemoteDaemon() {
return
}
path := filepath.Join(os.Getenv("DEST"), "docker.pid")
b, err := os.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(ctx context.Context, c *testing.T) {
testEnv.Clean(ctx, c)
}
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(ctx context.Context, 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(ctx context.Context, c *testing.T) {
if s.reg != nil {
s.reg.Close()
}
if s.d != nil {
s.d.Stop(c)
}
s.ds.TearDownTest(ctx, c)
}
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(ctx context.Context, 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(ctx context.Context, c *testing.T) {
if s.reg != nil {
s.reg.Close()
}
if s.d != nil {
s.d.Stop(c)
}
s.ds.TearDownTest(ctx, c)
}
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(ctx context.Context, 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(ctx context.Context, 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(ctx, c)
}
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(ctx context.Context, c *testing.T) {
testRequires(c, DaemonIsLinux, RegistryHosting, testEnv.IsLocalDaemon)
s.d = daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution))
}
func (s *DockerRegistryAuthTokenSuite) TearDownTest(ctx context.Context, 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(ctx, 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)
}
type DockerDaemonSuite struct {
ds *DockerSuite
d *daemon.Daemon
}
func (s *DockerDaemonSuite) OnTimeout(c *testing.T) {
s.d.DumpStackAndQuit()
}
func (s *DockerDaemonSuite) SetUpTest(ctx context.Context, c *testing.T) {
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
s.d = daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution))
}
func (s *DockerDaemonSuite) TearDownTest(ctx context.Context, c *testing.T) {
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
if s.d != nil {
s.d.Stop(c)
}
s.ds.TearDownTest(ctx, c)
}
func (s *DockerDaemonSuite) TearDownSuite(ctx context.Context, 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
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(ctx context.Context, c *testing.T) {
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
}
func (s *DockerSwarmSuite) AddDaemon(ctx context.Context, c *testing.T, joinSwarm, manager bool) *daemon.Daemon {
c.Helper()
d := daemon.New(c, dockerBinary, dockerdBinary,
testdaemon.WithEnvironment(testEnv.Execution),
testdaemon.WithSwarmPort(defaultSwarmPort+s.portIndex),
)
if joinSwarm {
if len(s.daemons) > 0 {
d.StartAndSwarmJoin(ctx, c, s.daemons[0].Daemon, manager)
} else {
d.StartAndSwarmInit(ctx, c)
}
} else {
d.StartNodeWithBusybox(ctx, c)
}
s.daemonsLock.Lock()
s.portIndex++
s.daemons = append(s.daemons, d)
s.daemonsLock.Unlock()
return d
}
func (s *DockerSwarmSuite) TearDownTest(ctx context.Context, c *testing.T) {
testRequires(c, DaemonIsLinux)
s.daemonsLock.Lock()
for _, d := range s.daemons {
if d != nil {
if c.Failed() {
d.TailLogsT(c, 100)
}
d.Stop(c)
d.Cleanup(c)
}
}
s.daemons = nil
s.portIndex = 0
s.daemonsLock.Unlock()
s.ds.TearDownTest(ctx, c)
}
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(ctx context.Context, c *testing.T) {
testRequires(c, DaemonIsLinux, RegistryHosting)
ps.registry = registry.NewV2(c)
ps.registry.WaitReady(c)
ctx, cancel := context.WithTimeout(ctx, 60*time.Second)
defer cancel()
err := plugin.CreateInRegistry(ctx, ps.getPluginRepo(), nil)
assert.NilError(c, err, "failed to create plugin")
}
func (ps *DockerPluginSuite) TearDownSuite(ctx context.Context, c *testing.T) {
if ps.registry != nil {
ps.registry.Close()
}
}
func (ps *DockerPluginSuite) TearDownTest(ctx context.Context, c *testing.T) {
ps.ds.TearDownTest(ctx, c)
}
func (ps *DockerPluginSuite) OnTimeout(c *testing.T) {
ps.ds.OnTimeout(c)
}
|