diff --git a/postal/service.go b/postal/service.go index fabe4fba..fd0435e0 100644 --- a/postal/service.go +++ b/postal/service.go @@ -162,7 +162,10 @@ func (s Service) Deliver(dependency Dependency, cnbPath, layerPath, platformPath validatedReader := cargo.NewValidatedReader(bundle, dependency.SHA256) - name := filepath.Base(dependency.URI) + name := dependency.Name + if name == "" { + name = filepath.Base(dependency.URI) + } err = vacation.NewArchive(validatedReader).WithName(name).StripComponents(dependency.StripComponents).Decompress(layerPath) if err != nil { return err diff --git a/postal/service_test.go b/postal/service_test.go index 32a55d4d..2080a46d 100644 --- a/postal/service_test.go +++ b/postal/service_test.go @@ -598,29 +598,6 @@ version = "this is super not semver" }) }) - context("when the file contents are malformed", func() { - it.Before(func() { - buffer := bytes.NewBuffer(nil) - gzipWriter := gzip.NewWriter(buffer) - - _, err := gzipWriter.Write([]byte("something")) - Expect(err).NotTo(HaveOccurred()) - - Expect(gzipWriter.Close()).To(Succeed()) - - transport.DropCall.Returns.ReadCloser = io.NopCloser(buffer) - - sum := sha256.Sum256(buffer.Bytes()) - dependencySHA = hex.EncodeToString(sum[:]) - }) - - it("fails to create a tar reader", func() { - err := deliver() - - Expect(err).To(MatchError(ContainSubstring("failed to read tar response"))) - }) - }) - context("when the file checksum does not match", func() { it("fails to create a tar reader", func() { err := service.Deliver( @@ -865,29 +842,6 @@ version = "this is super not semver" }) }) - context("when the file contents are malformed", func() { - it.Before(func() { - buffer := bytes.NewBuffer(nil) - gzipWriter := gzip.NewWriter(buffer) - - _, err := gzipWriter.Write([]byte("something")) - Expect(err).NotTo(HaveOccurred()) - - Expect(gzipWriter.Close()).To(Succeed()) - - transport.DropCall.Returns.ReadCloser = io.NopCloser(buffer) - - sum := sha256.Sum256(buffer.Bytes()) - dependencySHA = hex.EncodeToString(sum[:]) - }) - - it("fails to create a tar reader", func() { - err := install() - - Expect(err).To(MatchError(ContainSubstring("failed to read tar response"))) - }) - }) - context("when the file checksum does not match", func() { it("fails to create a tar reader", func() { err := service.Install(postal.Dependency{ diff --git a/vacation/archive.go b/vacation/archive.go index 06a7a886..82fe1258 100644 --- a/vacation/archive.go +++ b/vacation/archive.go @@ -58,13 +58,15 @@ func (a Archive) Decompress(destination string) error { case "application/x-tar": decompressor = NewTarArchive(bufferedReader).StripComponents(a.components) case "application/gzip": - decompressor = NewTarGzipArchive(bufferedReader).StripComponents(a.components) + decompressor = NewGzipArchive(bufferedReader).StripComponents(a.components).WithName(a.name) case "application/x-xz": - decompressor = NewTarXZArchive(bufferedReader).StripComponents(a.components) + decompressor = NewXZArchive(bufferedReader).StripComponents(a.components) case "application/x-bzip2": - decompressor = NewTarBzip2Archive(bufferedReader).StripComponents(a.components) + decompressor = NewBzip2Archive(bufferedReader).StripComponents(a.components) case "application/zip": decompressor = NewZipArchive(bufferedReader).StripComponents(a.components) + case "application/x-executable": + decompressor = NewExecutable(bufferedReader, a.name) case "text/plain; charset=utf-8", "application/jar": destination = filepath.Join(destination, a.name) decompressor = NewNopArchive(bufferedReader) diff --git a/vacation/archive_test.go b/vacation/archive_test.go index eca0d5a3..7684a5dd 100644 --- a/vacation/archive_test.go +++ b/vacation/archive_test.go @@ -5,6 +5,9 @@ import ( "archive/zip" "bytes" "compress/gzip" + "encoding/base64" + "io/fs" + "io/ioutil" "os" "path/filepath" "testing" @@ -346,6 +349,50 @@ func testArchive(t *testing.T, context spec.G, it spec.S) { }) }) + context("when passed the reader of an executable file", func() { + var ( + archive vacation.Archive + tempDir string + // Encoding of a very small elf executable from https://github.com/mathiasbynens/small + encodedContents = []byte(`f0VMRgEBAQAAAAAAAAAAAAIAAwABAAAAGUDNgCwAAAAAAAAAAAAAADQAIAABAAAAAAAAAABAzYAAQM2ATAAAAEwAAAAFAAAAABAAAA==`) + literalContents []byte + fileName = "exe" + ) + + it.Before(func() { + var err error + tempDir, err = os.MkdirTemp("", "vacation") + Expect(err).NotTo(HaveOccurred()) + + literalContents, err = ioutil.ReadAll(base64.NewDecoder(base64.StdEncoding, bytes.NewBuffer(encodedContents))) + Expect(err).NotTo(HaveOccurred()) + + archive = vacation.NewArchive(bytes.NewBuffer(literalContents)).WithName(fileName) + }) + + it.After(func() { + Expect(os.RemoveAll(tempDir)).To(Succeed()) + }) + + it("writes the executable in the bin dir", func() { + err := archive.Decompress(tempDir) + Expect(err).NotTo(HaveOccurred()) + + content, err := os.ReadFile(filepath.Join(tempDir, "bin", fileName)) + Expect(err).NotTo(HaveOccurred()) + Expect(content).To(Equal(literalContents)) + }) + + it("gives the executable execute permission", func() { + err := archive.Decompress(tempDir) + Expect(err).NotTo(HaveOccurred()) + + info, err := os.Stat(filepath.Join(tempDir, "bin", fileName)) + Expect(err).NotTo(HaveOccurred()) + Expect(info.Mode()).To(Equal(fs.FileMode(0755))) + }) + }) + context("when passed the reader of a text file", func() { var ( archive vacation.Archive diff --git a/vacation/bzip2_archive.go b/vacation/bzip2_archive.go new file mode 100644 index 00000000..04e98392 --- /dev/null +++ b/vacation/bzip2_archive.go @@ -0,0 +1,30 @@ +package vacation + +import ( + "compress/bzip2" + "io" +) + +// A Bzip2Archive decompresses bzip2 files from an input stream. +type Bzip2Archive struct { + reader io.Reader + components int +} + +// NewBzip2Archive returns a new Bzip2Archive that reads from inputReader. +func NewBzip2Archive(inputReader io.Reader) Bzip2Archive { + return Bzip2Archive{reader: inputReader} +} + +// Decompress reads from Bzip2Archive and writes files into the destination +// specified. +func (tbz Bzip2Archive) Decompress(destination string) error { + return NewArchive(bzip2.NewReader(tbz.reader)).StripComponents(tbz.components).Decompress(destination) +} + +// StripComponents behaves like the --strip-components flag on tar command +// removing the first n levels from the final decompression destination. +func (tbz Bzip2Archive) StripComponents(components int) Bzip2Archive { + tbz.components = components + return tbz +} diff --git a/vacation/tar_bzip2_archive_test.go b/vacation/bzip2_archive_test.go similarity index 92% rename from vacation/tar_bzip2_archive_test.go rename to vacation/bzip2_archive_test.go index 5cf4e3ea..499c0b54 100644 --- a/vacation/tar_bzip2_archive_test.go +++ b/vacation/bzip2_archive_test.go @@ -15,7 +15,7 @@ import ( . "github.com/onsi/gomega" ) -func testTarBzip2Archive(t *testing.T, context spec.G, it spec.S) { +func testBzip2Archive(t *testing.T, context spec.G, it spec.S) { var ( Expect = NewWithT(t).Expect ) @@ -23,7 +23,7 @@ func testTarBzip2Archive(t *testing.T, context spec.G, it spec.S) { context("Decompress", func() { var ( tempDir string - tarBzip2Archive vacation.TarBzip2Archive + bzip2Archive vacation.Bzip2Archive ) it.Before(func() { @@ -68,7 +68,7 @@ func testTarBzip2Archive(t *testing.T, context spec.G, it spec.S) { Expect(tw.Close()).To(Succeed()) Expect(bz.Close()).To(Succeed()) - tarBzip2Archive = vacation.NewTarBzip2Archive(bytes.NewReader(buffer.Bytes())) + bzip2Archive = vacation.NewBzip2Archive(bytes.NewReader(buffer.Bytes())) }) it.After(func() { @@ -77,7 +77,7 @@ func testTarBzip2Archive(t *testing.T, context spec.G, it spec.S) { it("unpackages the archive into the path", func() { var err error - err = tarBzip2Archive.Decompress(tempDir) + err = bzip2Archive.Decompress(tempDir) Expect(err).ToNot(HaveOccurred()) files, err := filepath.Glob(fmt.Sprintf("%s/*", tempDir)) @@ -104,7 +104,7 @@ func testTarBzip2Archive(t *testing.T, context spec.G, it spec.S) { it("unpackages the archive into the path but also strips the first component", func() { var err error - err = tarBzip2Archive.StripComponents(1).Decompress(tempDir) + err = bzip2Archive.StripComponents(1).Decompress(tempDir) Expect(err).ToNot(HaveOccurred()) files, err := filepath.Glob(fmt.Sprintf("%s/*", tempDir)) diff --git a/vacation/example_test.go b/vacation/example_test.go index 53b3b2e5..99581352 100644 --- a/vacation/example_test.go +++ b/vacation/example_test.go @@ -313,7 +313,7 @@ func ExampleTarArchive_StripComponents() { // some-other-dir/some-file } -func ExampleTarGzipArchive() { +func ExampleGzipArchive() { buffer := bytes.NewBuffer(nil) gw := gzip.NewWriter(buffer) tw := tar.NewWriter(gw) @@ -348,7 +348,7 @@ func ExampleTarGzipArchive() { } defer os.RemoveAll(destination) - archive := vacation.NewTarGzipArchive(bytes.NewReader(buffer.Bytes())) + archive := vacation.NewGzipArchive(bytes.NewReader(buffer.Bytes())) if err := archive.Decompress(destination); err != nil { log.Fatal(err) } @@ -376,7 +376,7 @@ func ExampleTarGzipArchive() { // third } -func ExampleTarGzipArchive_StripComponents() { +func ExampleGzipArchive_StripComponents() { buffer := bytes.NewBuffer(nil) gw := gzip.NewWriter(buffer) tw := tar.NewWriter(gw) @@ -411,7 +411,7 @@ func ExampleTarGzipArchive_StripComponents() { } defer os.RemoveAll(destination) - archive := vacation.NewTarGzipArchive(bytes.NewReader(buffer.Bytes())).StripComponents(1) + archive := vacation.NewGzipArchive(bytes.NewReader(buffer.Bytes())).StripComponents(1) if err := archive.Decompress(destination); err != nil { log.Fatal(err) } @@ -436,7 +436,7 @@ func ExampleTarGzipArchive_StripComponents() { // some-other-dir/some-file } -func ExampleTarXZArchive() { +func ExampleXZArchive() { buffer := bytes.NewBuffer(nil) xw, err := xz.NewWriter(buffer) if err != nil { @@ -475,7 +475,7 @@ func ExampleTarXZArchive() { } defer os.RemoveAll(destination) - archive := vacation.NewTarXZArchive(bytes.NewReader(buffer.Bytes())) + archive := vacation.NewXZArchive(bytes.NewReader(buffer.Bytes())) if err := archive.Decompress(destination); err != nil { log.Fatal(err) } @@ -503,7 +503,7 @@ func ExampleTarXZArchive() { // third } -func ExampleTarXZArchive_StripComponents() { +func ExampleXZArchive_StripComponents() { buffer := bytes.NewBuffer(nil) xw, err := xz.NewWriter(buffer) if err != nil { @@ -542,7 +542,7 @@ func ExampleTarXZArchive_StripComponents() { } defer os.RemoveAll(destination) - archive := vacation.NewTarXZArchive(bytes.NewReader(buffer.Bytes())).StripComponents(1) + archive := vacation.NewXZArchive(bytes.NewReader(buffer.Bytes())).StripComponents(1) if err := archive.Decompress(destination); err != nil { log.Fatal(err) } @@ -567,7 +567,7 @@ func ExampleTarXZArchive_StripComponents() { // some-other-dir/some-file } -func ExampleTarBzip2Archive() { +func ExampleBzip2Archive() { buffer := bytes.NewBuffer(nil) // Using the dsnet library because the Go compression library does not @@ -611,7 +611,7 @@ func ExampleTarBzip2Archive() { } defer os.RemoveAll(destination) - archive := vacation.NewTarBzip2Archive(bytes.NewReader(buffer.Bytes())) + archive := vacation.NewBzip2Archive(bytes.NewReader(buffer.Bytes())) if err := archive.Decompress(destination); err != nil { log.Fatal(err) } @@ -639,7 +639,7 @@ func ExampleTarBzip2Archive() { // third } -func ExampleTarBzip2Archive_StripComponents() { +func ExampleBzip2Archive_StripComponents() { buffer := bytes.NewBuffer(nil) // Using the dsnet library because the Go compression library does not @@ -683,7 +683,7 @@ func ExampleTarBzip2Archive_StripComponents() { } defer os.RemoveAll(destination) - archive := vacation.NewTarBzip2Archive(bytes.NewReader(buffer.Bytes())).StripComponents(1) + archive := vacation.NewBzip2Archive(bytes.NewReader(buffer.Bytes())).StripComponents(1) if err := archive.Decompress(destination); err != nil { log.Fatal(err) } diff --git a/vacation/executable.go b/vacation/executable.go new file mode 100644 index 00000000..db10f2a3 --- /dev/null +++ b/vacation/executable.go @@ -0,0 +1,42 @@ +package vacation + +import ( + "io" + "os" + "path/filepath" +) + +// An Executable writes an executable files from an input stream to the bin/ directory. +type Executable struct { + reader io.Reader + name string +} + +func NewExecutable(inputReader io.Reader, name string) Executable { + return Executable{reader: inputReader, name: name} +} + +func (e Executable) Decompress(destination string) error { + err := os.MkdirAll(filepath.Join(destination, "bin"), 0755) + if err != nil { + return err + } + + file, err := os.Create(filepath.Join(destination, "bin", e.name)) + if err != nil { + return err + } + defer file.Close() + + _, err = io.Copy(file, e.reader) + if err != nil { + return err + } + + err = os.Chmod(filepath.Join(destination, "bin", e.name), 0755) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/vacation/gzip_archive.go b/vacation/gzip_archive.go new file mode 100644 index 00000000..a65514d6 --- /dev/null +++ b/vacation/gzip_archive.go @@ -0,0 +1,42 @@ +package vacation + +import ( + "compress/gzip" + "fmt" + "io" +) + +// A GzipArchive decompresses gzipped files from an input stream. +type GzipArchive struct { + reader io.Reader + components int + name string +} + +// NewGzipArchive returns a new GzipArchive that reads from inputReader. +func NewGzipArchive(inputReader io.Reader) GzipArchive { + return GzipArchive{reader: inputReader} +} + +// Decompress reads from GzipArchive and writes files into the destination +// specified. +func (gz GzipArchive) Decompress(destination string) error { + gzr, err := gzip.NewReader(gz.reader) + if err != nil { + return fmt.Errorf("failed to create gzip reader: %w", err) + } + + return NewArchive(gzr).WithName(gz.name).StripComponents(gz.components).Decompress(destination) +} + +// StripComponents behaves like the --strip-components flag on tar command +// removing the first n levels from the final decompression destination. +func (gz GzipArchive) StripComponents(components int) GzipArchive { + gz.components = components + return gz +} + +func (gz GzipArchive) WithName(name string) GzipArchive { + gz.name = name + return gz +} diff --git a/vacation/tar_gzip_archive_test.go b/vacation/gzip_archive_test.go similarity index 90% rename from vacation/tar_gzip_archive_test.go rename to vacation/gzip_archive_test.go index 75503d5a..a8a996cd 100644 --- a/vacation/tar_gzip_archive_test.go +++ b/vacation/gzip_archive_test.go @@ -15,7 +15,7 @@ import ( . "github.com/onsi/gomega" ) -func testTarGzipArchive(t *testing.T, context spec.G, it spec.S) { +func testGzipArchive(t *testing.T, context spec.G, it spec.S) { var ( Expect = NewWithT(t).Expect ) @@ -23,7 +23,7 @@ func testTarGzipArchive(t *testing.T, context spec.G, it spec.S) { context("Decompress", func() { var ( tempDir string - tarGzipArchive vacation.TarGzipArchive + gzipArchive vacation.GzipArchive ) it.Before(func() { @@ -61,7 +61,7 @@ func testTarGzipArchive(t *testing.T, context spec.G, it spec.S) { Expect(tw.Close()).To(Succeed()) Expect(gw.Close()).To(Succeed()) - tarGzipArchive = vacation.NewTarGzipArchive(bytes.NewReader(buffer.Bytes())) + gzipArchive = vacation.NewGzipArchive(bytes.NewReader(buffer.Bytes())) }) @@ -71,7 +71,7 @@ func testTarGzipArchive(t *testing.T, context spec.G, it spec.S) { it("unpackages the archive into the path", func() { var err error - err = tarGzipArchive.Decompress(tempDir) + err = gzipArchive.Decompress(tempDir) Expect(err).ToNot(HaveOccurred()) files, err := filepath.Glob(fmt.Sprintf("%s/*", tempDir)) @@ -98,7 +98,7 @@ func testTarGzipArchive(t *testing.T, context spec.G, it spec.S) { it("unpackages the archive into the path but also strips the first component", func() { var err error - err = tarGzipArchive.StripComponents(1).Decompress(tempDir) + err = gzipArchive.StripComponents(1).Decompress(tempDir) Expect(err).ToNot(HaveOccurred()) files, err := filepath.Glob(fmt.Sprintf("%s/*", tempDir)) @@ -114,7 +114,7 @@ func testTarGzipArchive(t *testing.T, context spec.G, it spec.S) { context("failure cases", func() { context("when it fails to create a grip reader", func() { it("returns an error", func() { - readyArchive := vacation.NewTarGzipArchive(bytes.NewBuffer([]byte(`something`))) + readyArchive := vacation.NewGzipArchive(bytes.NewBuffer([]byte(`something`))) err := readyArchive.Decompress(tempDir) Expect(err).To(MatchError(ContainSubstring("failed to create gzip reader"))) diff --git a/vacation/init_test.go b/vacation/init_test.go index 12f7ea15..d9a6f71e 100644 --- a/vacation/init_test.go +++ b/vacation/init_test.go @@ -13,9 +13,9 @@ func TestVacation(t *testing.T) { suite("LinkSorting", testLinkSorting) suite("NopArchive", testNopArchive) suite("TarArchive", testTarArchive) - suite("TarBzip2Archive", testTarBzip2Archive) - suite("TarGzipArchive", testTarGzipArchive) - suite("TarXZArchive", testTarXZArchive) + suite("Bzip2Archive", testBzip2Archive) + suite("GzipArchive", testGzipArchive) + suite("XZArchive", testXZArchive) suite("ZipArchive", testZipArchive) suite.Run(t) } diff --git a/vacation/tar_bzip2_archive.go b/vacation/tar_bzip2_archive.go deleted file mode 100644 index cfe54636..00000000 --- a/vacation/tar_bzip2_archive.go +++ /dev/null @@ -1,30 +0,0 @@ -package vacation - -import ( - "compress/bzip2" - "io" -) - -// A TarBzip2Archive decompresses bzip2 files from an input stream. -type TarBzip2Archive struct { - reader io.Reader - components int -} - -// NewTarBzip2Archive returns a new Bzip2Archive that reads from inputReader. -func NewTarBzip2Archive(inputReader io.Reader) TarBzip2Archive { - return TarBzip2Archive{reader: inputReader} -} - -// Decompress reads from TarBzip2Archive and writes files into the destination -// specified. -func (tbz TarBzip2Archive) Decompress(destination string) error { - return NewTarArchive(bzip2.NewReader(tbz.reader)).StripComponents(tbz.components).Decompress(destination) -} - -// StripComponents behaves like the --strip-components flag on tar command -// removing the first n levels from the final decompression destination. -func (tbz TarBzip2Archive) StripComponents(components int) TarBzip2Archive { - tbz.components = components - return tbz -} diff --git a/vacation/tar_gzip_archive.go b/vacation/tar_gzip_archive.go deleted file mode 100644 index f5a756a0..00000000 --- a/vacation/tar_gzip_archive.go +++ /dev/null @@ -1,36 +0,0 @@ -package vacation - -import ( - "compress/gzip" - "fmt" - "io" -) - -// A TarGzipArchive decompresses gziped tar files from an input stream. -type TarGzipArchive struct { - reader io.Reader - components int -} - -// NewTarGzipArchive returns a new TarGzipArchive that reads from inputReader. -func NewTarGzipArchive(inputReader io.Reader) TarGzipArchive { - return TarGzipArchive{reader: inputReader} -} - -// Decompress reads from TarGzipArchive and writes files into the destination -// specified. -func (gz TarGzipArchive) Decompress(destination string) error { - gzr, err := gzip.NewReader(gz.reader) - if err != nil { - return fmt.Errorf("failed to create gzip reader: %w", err) - } - - return NewTarArchive(gzr).StripComponents(gz.components).Decompress(destination) -} - -// StripComponents behaves like the --strip-components flag on tar command -// removing the first n levels from the final decompression destination. -func (gz TarGzipArchive) StripComponents(components int) TarGzipArchive { - gz.components = components - return gz -} diff --git a/vacation/tar_xz_archive.go b/vacation/tar_xz_archive.go deleted file mode 100644 index 73c308ad..00000000 --- a/vacation/tar_xz_archive.go +++ /dev/null @@ -1,37 +0,0 @@ -package vacation - -import ( - "fmt" - "io" - - "github.com/ulikunitz/xz" -) - -// A TarXZArchive decompresses xz tar files from an input stream. -type TarXZArchive struct { - reader io.Reader - components int -} - -// NewTarXZArchive returns a new TarXZArchive that reads from inputReader. -func NewTarXZArchive(inputReader io.Reader) TarXZArchive { - return TarXZArchive{reader: inputReader} -} - -// Decompress reads from TarXZArchive and writes files into the destination -// specified. -func (txz TarXZArchive) Decompress(destination string) error { - xzr, err := xz.NewReader(txz.reader) - if err != nil { - return fmt.Errorf("failed to create xz reader: %w", err) - } - - return NewTarArchive(xzr).StripComponents(txz.components).Decompress(destination) -} - -// StripComponents behaves like the --strip-components flag on tar command -// removing the first n levels from the final decompression destination. -func (txz TarXZArchive) StripComponents(components int) TarXZArchive { - txz.components = components - return txz -} diff --git a/vacation/xz_archive.go b/vacation/xz_archive.go new file mode 100644 index 00000000..5517fe0b --- /dev/null +++ b/vacation/xz_archive.go @@ -0,0 +1,37 @@ +package vacation + +import ( + "fmt" + "io" + + "github.com/ulikunitz/xz" +) + +// A XZArchive decompresses xz files from an input stream. +type XZArchive struct { + reader io.Reader + components int +} + +// NewXZArchive returns a new XZArchive that reads from inputReader. +func NewXZArchive(inputReader io.Reader) XZArchive { + return XZArchive{reader: inputReader} +} + +// Decompress reads from XZArchive and writes files into the destination +// specified. +func (xzArchive XZArchive) Decompress(destination string) error { + xzr, err := xz.NewReader(xzArchive.reader) + if err != nil { + return fmt.Errorf("failed to create xz reader: %w", err) + } + + return NewArchive(xzr).StripComponents(xzArchive.components).Decompress(destination) +} + +// StripComponents behaves like the --strip-components flag on tar command +// removing the first n levels from the final decompression destination. +func (xzArchive XZArchive) StripComponents(components int) XZArchive { + xzArchive.components = components + return xzArchive +} diff --git a/vacation/tar_xz_archive_test.go b/vacation/xz_archive_test.go similarity index 90% rename from vacation/tar_xz_archive_test.go rename to vacation/xz_archive_test.go index f9e9ea73..77f3ca9a 100644 --- a/vacation/tar_xz_archive_test.go +++ b/vacation/xz_archive_test.go @@ -15,15 +15,15 @@ import ( . "github.com/onsi/gomega" ) -func testTarXZArchive(t *testing.T, context spec.G, it spec.S) { +func testXZArchive(t *testing.T, context spec.G, it spec.S) { var ( Expect = NewWithT(t).Expect ) context("Decompress", func() { var ( - tempDir string - tarXZArchive vacation.TarXZArchive + tempDir string + xzArchive vacation.XZArchive ) it.Before(func() { @@ -63,7 +63,7 @@ func testTarXZArchive(t *testing.T, context spec.G, it spec.S) { Expect(tw.Close()).To(Succeed()) Expect(xzw.Close()).To(Succeed()) - tarXZArchive = vacation.NewTarXZArchive(bytes.NewReader(buffer.Bytes())) + xzArchive = vacation.NewXZArchive(bytes.NewReader(buffer.Bytes())) }) @@ -73,7 +73,7 @@ func testTarXZArchive(t *testing.T, context spec.G, it spec.S) { it("unpackages the archive into the path", func() { var err error - err = tarXZArchive.Decompress(tempDir) + err = xzArchive.Decompress(tempDir) Expect(err).ToNot(HaveOccurred()) files, err := filepath.Glob(fmt.Sprintf("%s/*", tempDir)) @@ -100,7 +100,7 @@ func testTarXZArchive(t *testing.T, context spec.G, it spec.S) { it("unpackages the archive into the path but also strips the first component", func() { var err error - err = tarXZArchive.StripComponents(1).Decompress(tempDir) + err = xzArchive.StripComponents(1).Decompress(tempDir) Expect(err).ToNot(HaveOccurred()) files, err := filepath.Glob(fmt.Sprintf("%s/*", tempDir)) @@ -117,7 +117,7 @@ func testTarXZArchive(t *testing.T, context spec.G, it spec.S) { context("failure cases", func() { context("when it fails to create a xz reader", func() { it("returns an error", func() { - readyArchive := vacation.NewTarXZArchive(bytes.NewBuffer([]byte(`something`))) + readyArchive := vacation.NewXZArchive(bytes.NewBuffer([]byte(`something`))) err := readyArchive.Decompress(tempDir) Expect(err).To(MatchError(ContainSubstring("failed to create xz reader")))