Skip to content

Commit

Permalink
test: use testing/fstest instead of memoryfs
Browse files Browse the repository at this point in the history
Signed-off-by: Nikita Pivkin <[email protected]>
  • Loading branch information
nikpivkin authored and simar7 committed Nov 29, 2024
1 parent bb71495 commit d0839ca
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ require (
github.com/aws-cloudformation/rain v1.19.0
github.com/hashicorp/hcl/v2 v2.23.0
github.com/liamg/iamgo v0.0.9
github.com/liamg/memoryfs v1.6.0
github.com/open-policy-agent/opa v0.70.0
github.com/owenrumney/squealer v1.2.5
github.com/samber/lo v1.47.0
Expand Down
21 changes: 11 additions & 10 deletions test/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ import (
"io"
"os"
"os/exec"
"path/filepath"
"runtime"
"testing"
"testing/fstest"

"github.com/stretchr/testify/assert"

"github.com/liamg/memoryfs"

"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -59,7 +58,7 @@ func Test_ManifestValidity(t *testing.T) {

tarReader := tar.NewReader(gz)

mfs := memoryfs.New()
fsys := make(fstest.MapFS)

for {
header, err := tarReader.Next()
Expand All @@ -70,18 +69,20 @@ func Test_ManifestValidity(t *testing.T) {

switch header.Typeflag {
case tar.TypeDir:
require.NoError(t, mfs.MkdirAll(header.Name, 0755))
case tar.TypeReg:
buffer := bytes.NewBuffer([]byte{})
_, err = io.CopyN(buffer, tarReader, header.Size)
var buffer bytes.Buffer
buffer.Grow(int(header.Size))
_, err = io.Copy(&buffer, tarReader)
require.NoError(t, err)
require.NoError(t, mfs.WriteFile(header.Name, buffer.Bytes(), 0644))
fsys[filepath.Clean(header.Name)] = &fstest.MapFile{
Data: buffer.Bytes(),
}
default:
t.Fatalf("unknown type in %s: 0x%X", header.Name, header.Typeflag)
}
}

mf, err := mfs.Open(".manifest")
mf, err := fsys.Open(".manifest")
require.NoError(t, err)

var m2 manifest
Expand All @@ -90,7 +91,7 @@ func Test_ManifestValidity(t *testing.T) {
assert.Len(t, m2.Roots, 1)
assert.Equal(t, "", m2.Roots[0])

policies, err := mfs.ReadDir("./policies")
policies, err := fsys.ReadDir("policies")
require.NoError(t, err)

entries, err := os.ReadDir("../checks")
Expand Down

0 comments on commit d0839ca

Please sign in to comment.