Skip to content

Commit

Permalink
tests: add testImagetoolsAnnotation integration test
Browse files Browse the repository at this point in the history
Signed-off-by: Qasim Sarfraz <qasimsarfraz@microsoft.com>
  • Loading branch information
mqasimsarfraz committed Aug 2, 2023
1 parent d1b25f4 commit 95b6a2f
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions tests/imagetools.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

var imagetoolsTests = []func(t *testing.T, sb integration.Sandbox){
testImagetoolsInspectAndFilter,
testImagetoolsAnnotation,
}

func testImagetoolsInspectAndFilter(t *testing.T, sb integration.Sandbox) {
Expand Down Expand Up @@ -77,3 +78,56 @@ func testImagetoolsInspectAndFilter(t *testing.T, sb integration.Sandbox) {
require.Equal(t, idx.Manifests[1].Digest, idx2.Manifests[0].Digest)
require.Equal(t, platforms.Format(*idx.Manifests[1].Platform), platforms.Format(*idx2.Manifests[0].Platform))
}

func testImagetoolsAnnotation(t *testing.T, sb integration.Sandbox) {
if sb.Name() != "docker-container" {
t.Skip("imagetools tests are not driver specific and only run on docker-container")
}

dockerfile := []byte(`
FROM scratch
ARG TARGETARCH
COPY foo-${TARGETARCH} /foo
`)
dir := tmpdir(
t,
fstest.CreateFile("Dockerfile", dockerfile, 0600),
fstest.CreateFile("foo-amd64", []byte("foo-amd64"), 0600),
fstest.CreateFile("foo-arm64", []byte("foo-arm64"), 0600),
)

registry, err := sb.NewRegistry()
if errors.Is(err, integration.ErrRequirements) {
t.Skip(err.Error())
}
require.NoError(t, err)
target := registry + "/buildx/imtools:latest"

out, err := buildCmd(sb, withArgs("--output", "type=registry,oci-mediatypes=true,name="+target, "--platform=linux/amd64,linux/arm64", "--provenance=false", dir))
require.NoError(t, err, string(out))

cmd := buildxCmd(sb, withArgs("imagetools", "inspect", target, "--raw"))
dt, err := cmd.CombinedOutput()
require.NoError(t, err, string(dt))

var idx ocispecs.Index
err = json.Unmarshal(dt, &idx)
require.NoError(t, err)
require.Empty(t, idx.Annotations)

// update the index with annotations
cmd = buildxCmd(sb, withArgs("imagetools", "create", "-t", target, target+"@"+string(idx.Manifests[0].Digest),
target+"@"+string(idx.Manifests[1].Digest), "--annotation", "index:foo=bar", "--annotation", "index:bar=baz"))
dt, err = cmd.CombinedOutput()
require.NoError(t, err, string(dt))

cmd = buildxCmd(sb, withArgs("imagetools", "inspect", target, "--raw"))
dt, err = cmd.CombinedOutput()
require.NoError(t, err, string(dt))

err = json.Unmarshal(dt, &idx)
require.NoError(t, err)
require.Len(t, idx.Annotations, 2)
require.Equal(t, "bar", idx.Annotations["foo"])
require.Equal(t, "baz", idx.Annotations["bar"])
}

0 comments on commit 95b6a2f

Please sign in to comment.