Skip to content

Commit

Permalink
checkpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Jeff Ortel <[email protected]>
  • Loading branch information
jortel committed Aug 16, 2023
1 parent cb45018 commit fed7684
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion tar/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type Writer struct {
}

//
// Open the streamer.
// Open the writer.
func (r *Writer) Open(output io.Writer) {
if r.writer != nil {
return
Expand Down
1 change: 1 addition & 0 deletions test/tar/data/rabbit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
RABBIT
30 changes: 26 additions & 4 deletions test/tar/tar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package tar

import (
uuid2 "github.com/google/uuid"
liberr "github.com/jortel/go-utils/error"
"github.com/konveyor/tackle2-hub/nas"
"github.com/konveyor/tackle2-hub/tar"
"github.com/konveyor/tackle2-hub/test/assert"
"github.com/onsi/gomega"
"os"
"path"
"path/filepath"
"testing"
)

Expand All @@ -20,21 +23,40 @@ func TestWriter(t *testing.T) {
defer func() {
_ = nas.RmDir(tmpDir)
}()

// Writer
outPath := path.Join(tmpDir, "output.tar.gz")
file, err := os.Create(outPath)
g.Expect(err).To(gomega.BeNil())
// Write the ./data tree.
writer := tar.NewWriter(file)
err = writer.AddDir("./data", tar.Filter{})
g.Expect(err).To(gomega.BeNil())
g.Expect(err).To(gomega.BeNil())
// Write ./data/rabbit => data/pet/rabbit
err = writer.AddFile("./data/rabbit", "data/pet/rabbit")
g.Expect(err).To(gomega.BeNil())
writer.Close()
_ = file.Close()

// Reader
// Read/expand the tarball.
reader := tar.NewReader()
file, err = os.Open(outPath)
g.Expect(err).To(gomega.BeNil())
err = reader.Extract(tmpDir, file)
g.Expect(err).To(gomega.BeNil())

// Validate ./data
err = filepath.Walk(
path.Join("./data"),
func(p string, info os.FileInfo, nErr error) (err error) {
if nErr != nil {
err = liberr.Wrap(nErr)
return
}
if !info.IsDir() {
_ = assert.EqualFileContent(p, path.Join(tmpDir, p))
}
return
})
g.Expect(err).To(gomega.BeNil())
// Validate ./data/pet/rabbit
_ = assert.EqualFileContent("./data/rabbit", path.Join(tmpDir, "data", "pet", "rabbit"))
}

0 comments on commit fed7684

Please sign in to comment.