implement test api images history integration test on dedicated file

Signed-off-by: Abubacarr Ceesay <abubacarr671@gmail.com>
This commit is contained in:
Abubacarr Ceesay
2025-07-11 19:04:37 +02:00
parent 669163c416
commit f6b3b257c8
2 changed files with 33 additions and 28 deletions

View File

@@ -0,0 +1,33 @@
package image
import (
"testing"
"github.com/docker/docker/integration/internal/build"
"github.com/docker/docker/testutil/fakecontext"
"gotest.tools/v3/assert"
)
func TestAPIImagesHistory(t *testing.T) {
ctx := setupTest(t)
client := testEnv.APIClient()
dockerfile := "FROM busybox\nENV FOO bar"
imgID := build.Do(ctx, t, client, fakecontext.New(t, t.TempDir(), fakecontext.WithDockerfile(dockerfile)))
historydata, err := client.ImageHistory(ctx, imgID)
assert.NilError(t, err)
assert.Assert(t, len(historydata) != 0)
var found bool
for _, imageLayer := range historydata {
if imageLayer.ID == imgID {
found = true
break
}
}
assert.Assert(t, found)
}

View File

@@ -13,12 +13,10 @@ import (
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/api/types/versions"
"github.com/docker/docker/client"
buildImage "github.com/docker/docker/integration/internal/build"
"github.com/docker/docker/integration/internal/container"
"github.com/docker/docker/internal/testutils/specialimage"
"github.com/docker/docker/testutil"
"github.com/docker/docker/testutil/daemon"
"github.com/docker/docker/testutil/fakecontext"
"github.com/google/go-cmp/cmp/cmpopts"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"gotest.tools/v3/assert"
@@ -315,29 +313,3 @@ func TestAPIImagesListManifests(t *testing.T) {
}
}
}
func TestAPIImagesHistory(t *testing.T) {
ctx := setupTest(t)
client := testEnv.APIClient()
dockerfile := "FROM busybox\nENV FOO bar"
imgID := buildImage.Do(ctx, t, client, fakecontext.New(t, t.TempDir(), fakecontext.WithDockerfile(dockerfile)))
historydata, err := client.ImageHistory(ctx, imgID)
assert.NilError(t, err)
assert.Assert(t, len(historydata) != 0)
var found bool
for _, imageLayer := range historydata {
if imageLayer.ID == imgID {
found = true
break
}
}
assert.Assert(t, found)
}