Skip to content

Commit

Permalink
vacation: untangle compression and tar handling
Browse files Browse the repository at this point in the history
Support use case where the archive is a gzipped executable.
Signed-off-by: Mikey Boldt <mboldt@vmware.com>
  • Loading branch information
mboldt committed Nov 24, 2021
1 parent a1e3871 commit 74e615a
Show file tree
Hide file tree
Showing 7 changed files with 3 additions and 49 deletions.
46 changes: 0 additions & 46 deletions postal/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func NewTarBzip2Archive(inputReader io.Reader) TarBzip2Archive {
// 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)
return NewArchive(bzip2.NewReader(tbz.reader)).StripComponents(tbz.components).Decompress(destination)
}

// StripComponents behaves like the --strip-components flag on tar command
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion vacation/tar_gzip_archive.go → vacation/gzip_archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (gz TarGzipArchive) Decompress(destination string) error {
return fmt.Errorf("failed to create gzip reader: %w", err)
}

return NewTarArchive(gzr).StripComponents(gz.components).Decompress(destination)
return NewArchive(gzr).StripComponents(gz.components).Decompress(destination)
}

// StripComponents behaves like the --strip-components flag on tar command
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion vacation/tar_xz_archive.go → vacation/xz_archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (txz TarXZArchive) Decompress(destination string) error {
return fmt.Errorf("failed to create xz reader: %w", err)
}

return NewTarArchive(xzr).StripComponents(txz.components).Decompress(destination)
return NewArchive(xzr).StripComponents(txz.components).Decompress(destination)
}

// StripComponents behaves like the --strip-components flag on tar command
Expand Down
File renamed without changes.

0 comments on commit 74e615a

Please sign in to comment.