mirror of
https://github.com/docker/compose.git
synced 2026-10-12 02:13:08 +00:00
AGENTS.md documents 'Test unit: go test ./pkg/...' and 'E2E tests: go test -tags e2e ./pkg/e2e/'. Both statements were false: no file in pkg/e2e carried an e2e build constraint, so the -tags flag was a no-op and the 'unit' command actually launched the full e2e suite — requiring a Docker daemon and the locally built binary, creating and destroying containers, for up to 20 minutes. CI only avoided this by grepping e2e out of the package list (Dockerfile). Every *_test.go in pkg/e2e now carries //go:build e2e (merged with the existing !windows constraints), and the Makefile e2e targets pass the tag. The documented commands become true: - go test ./pkg/... -> pkg/e2e reports [no test files] - go test -tags e2e ./pkg/e2e -> runs the suite AGENTS.md now also states the daemon/binary prerequisites explicitly. Part of #14074 (A: the code misdescribes its own structure). Signed-off-by: Nicolas De Loof <[email protected]>
63 lines
2.7 KiB
Go
63 lines
2.7 KiB
Go
//go:build e2e
|
|
|
|
/*
|
|
Copyright 2020 Docker Compose CLI authors
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package e2e
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestCopy(t *testing.T) {
|
|
s := NewScenario(t, "cp must target all replicas by default, one replica with --index, and copy both ways")
|
|
dir := s.Dir()
|
|
s.Step("up starts five replicas",
|
|
ComposeCmd("up", "--scale", "nginx=5", "-d"),
|
|
ServiceScale("nginx", 5)).
|
|
Step("cp to the service reaches every replica by default",
|
|
ComposeCmd("cp", filepath.Join(dir, "cp-me.txt"), "nginx:/tmp/default.txt")).
|
|
Step("replica #1 got the file",
|
|
DockerCmd("exec", s.Project()+"-nginx-1", "cat", "/tmp/default.txt"),
|
|
OutputContains("hello world")).
|
|
Step("replica #3 got the file too",
|
|
DockerCmd("exec", s.Project()+"-nginx-3", "cat", "/tmp/default.txt"),
|
|
OutputContains("hello world")).
|
|
Step("cp --index targets a single replica",
|
|
ComposeCmd("cp", "--index=3", filepath.Join(dir, "cp-me.txt"), "nginx:/tmp/indexed.txt")).
|
|
Step("the indexed replica got the file",
|
|
DockerCmd("exec", s.Project()+"-nginx-3", "cat", "/tmp/indexed.txt"),
|
|
OutputContains("hello world")).
|
|
Step("the other replicas did not",
|
|
DockerCmd("exec", s.Project()+"-nginx-2", "cat", "/tmp/indexed.txt").MayFail(),
|
|
ExitCode(1)).
|
|
Step("cp from the service reads from replica #1 by default",
|
|
ComposeCmd("cp", "nginx:/tmp/default.txt", filepath.Join(dir, "from-default.txt")),
|
|
FileContains(filepath.Join(dir, "from-default.txt"), "hello world")).
|
|
Step("cp --index reads from the chosen replica",
|
|
ComposeCmd("cp", "--index=3", "nginx:/tmp/indexed.txt", filepath.Join(dir, "from-indexed.txt")),
|
|
FileContains(filepath.Join(dir, "from-indexed.txt"), "hello world")).
|
|
Step("cp copies a folder into the container",
|
|
ComposeCmd("cp", filepath.Join(dir, "cp-folder"), "nginx:/tmp")).
|
|
Step("the folder's content is in the container",
|
|
DockerCmd("exec", s.Project()+"-nginx-1", "cat", "/tmp/cp-folder/cp-me.txt"),
|
|
OutputContains("hello world from folder")).
|
|
Step("cp copies a folder out of the container",
|
|
ComposeCmd("cp", "nginx:/tmp/cp-folder", filepath.Join(dir, "cp-folder2")),
|
|
FileContains(filepath.Join(dir, "cp-folder2", "cp-me.txt"), "hello world from folder"))
|
|
}
|