Skip to content

Commit

Permalink
Avoid a test dependency on github.com/otiai10/copy
Browse files Browse the repository at this point in the history
Signed-off-by: Miloslav Trmač <[email protected]>
  • Loading branch information
mtrmac committed Apr 3, 2024
1 parent 5205c56 commit 35811c7
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ require (
github.com/opencontainers/image-spec v1.1.0
github.com/opencontainers/selinux v1.11.0
github.com/ostreedev/ostree-go v0.0.0-20210805093236-719684c64e4f
github.com/otiai10/copy v1.14.0
github.com/proglottis/gpgme v0.1.3
github.com/secure-systems-lab/go-securesystemslib v0.8.0
github.com/sigstore/fulcio v1.4.3
Expand Down
3 changes: 0 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,6 @@ github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
github.com/ostreedev/ostree-go v0.0.0-20210805093236-719684c64e4f h1:/UDgs8FGMqwnHagNDPGOlts35QkhAZ8by3DR7nMih7M=
github.com/ostreedev/ostree-go v0.0.0-20210805093236-719684c64e4f/go.mod h1:J6OG6YJVEWopen4avK3VNQSnALmmjvniMmni/YFYAwc=
github.com/otiai10/copy v1.14.0 h1:dCI/t1iTdYGtkvCuBG2BgR6KZa83PTclw4U5n2wAllU=
github.com/otiai10/copy v1.14.0/go.mod h1:ECfuL02W+/FkTWZWgQqXPWZgW9oeKCSQ5qVfSc4qc4w=
github.com/otiai10/mint v1.5.1 h1:XaPLeE+9vGbuyEHem1JNk3bYc7KKqyI/na0/mLd/Kks=
github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down
45 changes: 41 additions & 4 deletions oci/layout/oci_delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package layout
import (
"context"
"fmt"
"io"
"io/fs"
"os"
"path/filepath"
"testing"

"github.com/containers/image/v5/types"
digest "github.com/opencontainers/go-digest"
imgspecv1 "github.com/opencontainers/image-spec/specs-go/v1"
cp "github.com/otiai10/copy"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -275,10 +276,46 @@ func TestReferenceDeleteImage_multipleImages_twoIdenticalReferences(t *testing.T
}

func loadFixture(t *testing.T, fixtureName string) string {
tmpDir := t.TempDir()
err := cp.Copy(fmt.Sprintf("fixtures/%v/", fixtureName), tmpDir)
destDir := t.TempDir()
srcDir := filepath.Join("fixtures", fixtureName)
err := filepath.WalkDir(srcDir, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
relPath, err := filepath.Rel(srcDir, path)
if err != nil {
return err
}
destPath := filepath.Join(destDir, relPath)
switch d.Type() {
case fs.ModeDir:
if err := os.MkdirAll(destPath, 0o700); err != nil {
return err
}
case 0: // regular file
src, err := os.Open(path)
if err != nil {
return err
}
defer src.Close()
dest, err := os.OpenFile(destPath, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0o600)
if err != nil {
return err
}
if _, err := io.Copy(dest, src); err != nil {
_ = dest.Close()
return err
}
if err := dest.Close(); err != nil {
return err
}
default:
return fmt.Errorf("unexpected file type %#v", d.Type())
}
return nil
})
require.NoError(t, err)
return tmpDir
return destDir
}

func assertBlobExists(t *testing.T, blobsDir string, blobDigest string) {
Expand Down

0 comments on commit 35811c7

Please sign in to comment.