summaryrefslogtreecommitdiff
path: root/integration/internal
diff options
context:
space:
mode:
authorBrian Goff <cpuguy83@gmail.com>2023-03-11 22:34:21 +0000
committerSebastiaan van Stijn <github@gone.nl>2023-03-14 11:06:26 +0100
commit146df5fbd369dc2a48180dbbacb4d7071cf18f1a (patch)
tree1b90a05cae55715ea639102c0788e5d6898b222d /integration/internal
parent8224c74f081329d9bf2b56ed912eb59114795998 (diff)
downloaddocker-146df5fbd369dc2a48180dbbacb4d7071cf18f1a.tar.gz
Fix pruning anon volume created from image config
Volumes created from the image config were not being pruned because the volume service did not think they were anonymous since the code to create passes along a generated name instead of letting the volume service generate it. This changes the code path to have the volume service generate the name instead of doing it ahead of time. Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Diffstat (limited to 'integration/internal')
-rw-r--r--integration/internal/build/build.go52
-rw-r--r--integration/internal/container/container.go1
2 files changed, 53 insertions, 0 deletions
diff --git a/integration/internal/build/build.go b/integration/internal/build/build.go
new file mode 100644
index 0000000000..9dbdd1241e
--- /dev/null
+++ b/integration/internal/build/build.go
@@ -0,0 +1,52 @@
+package build
+
+import (
+ "context"
+ "encoding/json"
+ "io"
+ "testing"
+
+ "github.com/docker/docker/api/types"
+ "github.com/docker/docker/client"
+ "github.com/docker/docker/pkg/jsonmessage"
+ "github.com/docker/docker/testutil/fakecontext"
+ "gotest.tools/v3/assert"
+)
+
+// Do builds an image from the given context and returns the image ID.
+func Do(ctx context.Context, t *testing.T, client client.APIClient, buildCtx *fakecontext.Fake) string {
+ resp, err := client.ImageBuild(ctx, buildCtx.AsTarReader(t), types.ImageBuildOptions{})
+ if resp.Body != nil {
+ defer resp.Body.Close()
+ }
+ assert.NilError(t, err)
+ img := GetImageIDFromBody(t, resp.Body)
+ t.Cleanup(func() {
+ client.ImageRemove(ctx, img, types.ImageRemoveOptions{Force: true})
+ })
+ return img
+}
+
+// GetImageIDFRommBody reads the image ID from the build response body.
+func GetImageIDFromBody(t *testing.T, body io.Reader) string {
+ var (
+ jm jsonmessage.JSONMessage
+ br types.BuildResult
+ dec = json.NewDecoder(body)
+ )
+ for {
+ err := dec.Decode(&jm)
+ if err == io.EOF {
+ break
+ }
+ assert.NilError(t, err)
+ if jm.Aux == nil {
+ continue
+ }
+ assert.NilError(t, json.Unmarshal(*jm.Aux, &br))
+ assert.Assert(t, br.ID != "", "could not read image ID from build output")
+ break
+ }
+ io.Copy(io.Discard, body)
+ return br.ID
+}
diff --git a/integration/internal/container/container.go b/integration/internal/container/container.go
index dadc6b44e4..6559bd4f4a 100644
--- a/integration/internal/container/container.go
+++ b/integration/internal/container/container.go
@@ -48,6 +48,7 @@ func create(ctx context.Context, t *testing.T, client client.APIClient, ops ...f
// Create creates a container with the specified options, asserting that there was no error
func Create(ctx context.Context, t *testing.T, client client.APIClient, ops ...func(*TestContainerConfig)) string {
+ t.Helper()
c, err := create(ctx, t, client, ops...)
assert.NilError(t, err)