Merge pull request #40991 from cyenyxe/36583-integration-tests-no-names

Use unique names in integration tests (build, container, image)
This commit is contained in:
Sebastiaan van Stijn 2020-05-19 16:57:18 +02:00 committed by GitHub
commit 30d75348e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 33 additions and 24 deletions

View file

@ -48,7 +48,7 @@ func TestBuildSquashParent(t *testing.T) {
source := fakecontext.New(t, "", fakecontext.WithDockerfile(dockerfile))
defer source.Close()
name := "test"
name := strings.ToLower(t.Name())
resp, err := client.ImageBuild(ctx,
source.AsTarReader(t),
types.ImageBuildOptions{

View file

@ -207,19 +207,20 @@ func TestBuildMultiStageParentConfig(t *testing.T) {
defer source.Close()
apiclient := testEnv.APIClient()
imgName := strings.ToLower(t.Name())
resp, err := apiclient.ImageBuild(ctx,
source.AsTarReader(t),
types.ImageBuildOptions{
Remove: true,
ForceRemove: true,
Tags: []string{"build1"},
Tags: []string{imgName},
})
assert.NilError(t, err)
_, err = io.Copy(ioutil.Discard, resp.Body)
resp.Body.Close()
assert.NilError(t, err)
image, _, err := apiclient.ImageInspectWithRaw(ctx, "build1")
image, _, err := apiclient.ImageInspectWithRaw(ctx, imgName)
assert.NilError(t, err)
expected := "/foo/sub2"
@ -234,7 +235,7 @@ func TestBuildMultiStageParentConfig(t *testing.T) {
func TestBuildLabelWithTargets(t *testing.T) {
skip.If(t, versions.LessThan(testEnv.DaemonAPIVersion(), "1.38"), "test added after 1.38")
skip.If(t, testEnv.DaemonInfo.OSType == "windows", "FIXME")
bldName := "build-a"
imgName := strings.ToLower(t.Name() + "-a")
testLabels := map[string]string{
"foo": "bar",
"dead": "beef",
@ -260,7 +261,7 @@ func TestBuildLabelWithTargets(t *testing.T) {
types.ImageBuildOptions{
Remove: true,
ForceRemove: true,
Tags: []string{bldName},
Tags: []string{imgName},
Labels: testLabels,
Target: "target-a",
})
@ -269,7 +270,7 @@ func TestBuildLabelWithTargets(t *testing.T) {
resp.Body.Close()
assert.NilError(t, err)
image, _, err := apiclient.ImageInspectWithRaw(ctx, bldName)
image, _, err := apiclient.ImageInspectWithRaw(ctx, imgName)
assert.NilError(t, err)
testLabels["label-a"] = "inline-a"
@ -280,14 +281,14 @@ func TestBuildLabelWithTargets(t *testing.T) {
}
// For `target-b` build
bldName = "build-b"
imgName = strings.ToLower(t.Name() + "-b")
delete(testLabels, "label-a")
resp, err = apiclient.ImageBuild(ctx,
source.AsTarReader(t),
types.ImageBuildOptions{
Remove: true,
ForceRemove: true,
Tags: []string{bldName},
Tags: []string{imgName},
Labels: testLabels,
Target: "target-b",
})
@ -296,7 +297,7 @@ func TestBuildLabelWithTargets(t *testing.T) {
resp.Body.Close()
assert.NilError(t, err)
image, _, err = apiclient.ImageInspectWithRaw(ctx, bldName)
image, _, err = apiclient.ImageInspectWithRaw(ctx, imgName)
assert.NilError(t, err)
testLabels["label-b"] = "inline-b"
@ -581,7 +582,7 @@ func TestBuildPreserveOwnership(t *testing.T) {
ctx := context.Background()
dockerfile, err := ioutil.ReadFile("testdata/Dockerfile.testBuildPreserveOwnership")
dockerfile, err := ioutil.ReadFile("testdata/Dockerfile." + t.Name())
assert.NilError(t, err)
source := fakecontext.New(t, "", fakecontext.WithDockerfile(string(dockerfile)))

View file

@ -559,7 +559,7 @@ func TestCreateTmpfsOverrideAnonymousVolume(t *testing.T) {
inspect, err := client.ContainerInspect(ctx, id)
assert.NilError(t, err)
// tmpfs do not currently get added to inspect.Mounts
// Normally an anoynmous volume would, except now tmpfs should prevent that.
// Normally an anonymous volume would, except now tmpfs should prevent that.
assert.Assert(t, is.Len(inspect.Mounts, 0))
chWait, chErr := client.ContainerWait(ctx, id, container.WaitConditionNextExit)

View file

@ -3,6 +3,7 @@ package container // import "github.com/docker/docker/integration/container"
import (
"context"
"encoding/json"
"strings"
"testing"
"time"
@ -28,7 +29,7 @@ func TestExportContainerAndImportImage(t *testing.T) {
cID := container.Run(ctx, t, client, container.WithCmd("true"))
poll.WaitOn(t, container.IsStopped(ctx, client, cID), poll.WithDelay(100*time.Millisecond))
reference := "repo/testexp:v1"
reference := "repo/" + strings.ToLower(t.Name()) + ":v1"
exportResp, err := client.ContainerExport(ctx, cID)
assert.NilError(t, err)
importResp, err := client.ImageImport(ctx, types.ImageImportSource{

View file

@ -3,6 +3,7 @@ package container // import "github.com/docker/docker/integration/container"
import (
"context"
"encoding/json"
"strings"
"testing"
"time"
@ -22,7 +23,7 @@ func TestInspectCpusetInConfigPre120(t *testing.T) {
client := request.NewAPIClient(t, client.WithVersion("1.19"))
ctx := context.Background()
name := "cpusetinconfig-pre120-" + t.Name()
name := strings.ToLower(t.Name())
// Create container with up to-date-API
container.Run(ctx, t, request.NewAPIClient(t), container.WithName(name),
container.WithCmd("true"),

View file

@ -2,6 +2,7 @@ package image // import "github.com/docker/docker/integration/image"
import (
"context"
"strings"
"testing"
"github.com/docker/docker/api/types"
@ -20,10 +21,11 @@ func TestCommitInheritsEnv(t *testing.T) {
ctx := context.Background()
cID1 := container.Create(ctx, t, client)
imgName := strings.ToLower(t.Name())
commitResp1, err := client.ContainerCommit(ctx, cID1, types.ContainerCommitOptions{
Changes: []string{"ENV PATH=/bin"},
Reference: "test-commit-image",
Reference: imgName,
})
assert.NilError(t, err)
@ -37,7 +39,7 @@ func TestCommitInheritsEnv(t *testing.T) {
commitResp2, err := client.ContainerCommit(ctx, cID2, types.ContainerCommitOptions{
Changes: []string{"ENV PATH=/usr/bin:$PATH"},
Reference: "test-commit-image",
Reference: imgName,
})
assert.NilError(t, err)

View file

@ -6,6 +6,7 @@ import (
"context"
"io"
"runtime"
"strings"
"testing"
"github.com/docker/docker/api/types"
@ -38,10 +39,11 @@ func TestImportExtremelyLargeImageWorks(t *testing.T) {
err := tw.Close()
assert.NilError(t, err)
imageRdr := io.MultiReader(&tarBuffer, io.LimitReader(testutil.DevZero, 8*1024*1024*1024))
reference := strings.ToLower(t.Name()) + ":v42"
_, err = client.ImageImport(context.Background(),
types.ImageImportSource{Source: imageRdr, SourceName: "-"},
"test1234:v42",
reference,
types.ImageImportOptions{})
assert.NilError(t, err)
}

View file

@ -2,6 +2,7 @@ package image // import "github.com/docker/docker/integration/image"
import (
"context"
"strings"
"testing"
"github.com/docker/docker/api/types"
@ -19,7 +20,7 @@ func TestImagesFilterMultiReference(t *testing.T) {
client := testEnv.APIClient()
ctx := context.Background()
name := "images_filter_multi_reference"
name := strings.ToLower(t.Name())
repoTags := []string{
name + ":v1",
name + ":v2",

View file

@ -2,6 +2,7 @@ package image // import "github.com/docker/docker/integration/image"
import (
"context"
"strings"
"testing"
"github.com/docker/docker/api/types"
@ -17,36 +18,36 @@ func TestRemoveImageOrphaning(t *testing.T) {
ctx := context.Background()
client := testEnv.APIClient()
img := "test-container-orphaning"
imgName := strings.ToLower(t.Name())
// Create a container from busybox, and commit a small change so we have a new image
cID1 := container.Create(ctx, t, client, container.WithCmd(""))
commitResp1, err := client.ContainerCommit(ctx, cID1, types.ContainerCommitOptions{
Changes: []string{`ENTRYPOINT ["true"]`},
Reference: img,
Reference: imgName,
})
assert.NilError(t, err)
// verifies that reference now points to first image
resp, _, err := client.ImageInspectWithRaw(ctx, img)
resp, _, err := client.ImageInspectWithRaw(ctx, imgName)
assert.NilError(t, err)
assert.Check(t, is.Equal(resp.ID, commitResp1.ID))
// Create a container from created image, and commit a small change with same reference name
cID2 := container.Create(ctx, t, client, container.WithImage(img), container.WithCmd(""))
cID2 := container.Create(ctx, t, client, container.WithImage(imgName), container.WithCmd(""))
commitResp2, err := client.ContainerCommit(ctx, cID2, types.ContainerCommitOptions{
Changes: []string{`LABEL Maintainer="Integration Tests"`},
Reference: img,
Reference: imgName,
})
assert.NilError(t, err)
// verifies that reference now points to second image
resp, _, err = client.ImageInspectWithRaw(ctx, img)
resp, _, err = client.ImageInspectWithRaw(ctx, imgName)
assert.NilError(t, err)
assert.Check(t, is.Equal(resp.ID, commitResp2.ID))
// try to remove the image, should not error out.
_, err = client.ImageRemove(ctx, img, types.ImageRemoveOptions{})
_, err = client.ImageRemove(ctx, imgName, types.ImageRemoveOptions{})
assert.NilError(t, err)
// check if the first image is still there