Skip to content

Commit

Permalink
Fix missing OS/Architecture when using random.Image in tests
Browse files Browse the repository at this point in the history
moby/buildkit#4601 added additional validation
that causes the export of images generated with random.Image to fail so
manually set OS and Architecture

Signed-off-by: Pedro Nuno Santos <pedro.santos@yoti.com>
  • Loading branch information
pn-santos committed Nov 27, 2024
1 parent 5d37987 commit d8df06c
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/google/go-containerregistry/pkg/registry"
v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/google/go-containerregistry/pkg/v1/layout"
"github.com/google/go-containerregistry/pkg/v1/mutate"
"github.com/google/go-containerregistry/pkg/v1/random"
"github.com/google/go-containerregistry/pkg/v1/remote"
"github.com/google/go-containerregistry/pkg/v1/tarball"
Expand Down Expand Up @@ -272,8 +273,7 @@ func (s *TaskSuite) TestRegistryMirrors() {
mirror := httptest.NewServer(registry.New())
defer mirror.Close()

image, err := random.Image(1024, 2)
s.NoError(err)
image := s.randomImage(1024, 2, "linux", "amd64")

mirrorURL, err := url.Parse(mirror.URL)
s.NoError(err)
Expand Down Expand Up @@ -329,14 +329,12 @@ func (s *TaskSuite) TestImageArgs() {

defer os.RemoveAll(imagesDir)

firstImage, err := random.Image(1024, 2)
s.NoError(err)
firstImage := s.randomImage(1024, 2, "linux", "amd64")
firstPath := filepath.Join(imagesDir, "first.tar")
err = tarball.WriteToFile(firstPath, nil, firstImage)
s.NoError(err)

secondImage, err := random.Image(1024, 2)
s.NoError(err)
secondImage := s.randomImage(1024, 2, "linux", "amd64")
secondPath := filepath.Join(imagesDir, "second.tar")
err = tarball.WriteToFile(secondPath, nil, secondImage)
s.NoError(err)
Expand Down Expand Up @@ -389,8 +387,7 @@ func (s *TaskSuite) TestImageArgsWithUppercaseName() {

defer os.RemoveAll(imagesDir)

image, err := random.Image(1024, 2)
s.NoError(err)
image := s.randomImage(1024, 2, "linux", "amd64")
imagePath := filepath.Join(imagesDir, "first.tar")
err = tarball.WriteToFile(imagePath, nil, image)
s.NoError(err)
Expand Down Expand Up @@ -426,8 +423,7 @@ func (s *TaskSuite) TestImageArgsUnpack() {

defer os.RemoveAll(imagesDir)

image, err := random.Image(1024, 2)
s.NoError(err)
image := s.randomImage(1024, 2, "linux", "amd64")
imagePath := filepath.Join(imagesDir, "first.tar")
err = tarball.WriteToFile(imagePath, nil, image)
s.NoError(err)
Expand Down Expand Up @@ -652,6 +648,23 @@ func (s *TaskSuite) imageMetadata(output string) (task.ImageMetadata, error) {
return meta, nil
}

func (s *TaskSuite) randomImage(byteSize, layers int64, os, arch string) v1.Image {
image, err := random.Image(byteSize, layers)
s.NoError(err)

cf, err := image.ConfigFile()
s.NoError(err)

cf = cf.DeepCopy()
cf.OS = os
cf.Architecture = arch

image, err = mutate.ConfigFile(image, cf)
s.NoError(err)

return image
}

func TestSuite(t *testing.T) {
suite.Run(t, &TaskSuite{
Assertions: require.New(t),
Expand Down

0 comments on commit d8df06c

Please sign in to comment.