-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Makes api changes to Executable and NopArchive
- NopArchive will now no longer write directly to the destination if a name is not given becuase it now set a default name (`artifact`). If you were using the generic Archive type you will see no difference but those who were using the type directly must now specify a directory as the destination, not a file name. - NewExecutable now conforms to the same api as the other archive instantiation functions excepting only a reader and allowing individuals to set the file name using a `WithName()` option with mirrors the behavior of all other archive objects. -Executable now has a default file name (`artifact`) if you were using the generic Archive type you will see no difference however becuase the Executable instantiation function no longer requires a name a default is now assigned on instantiation the same way it is done for the NopArchive. - Excutable no longer places the executable in a directory name `bin` nor does it create all directories in the destination path. I felt that automatically placing the executable in a `bin` directory felt to opinionated, I think that it is more than reasonable for a user to want to download and executable and not want to have it placed in a directory named `bin` and this default behavior hinders that user. I think that it is more than reasonable to expect that the destination given is a `bin` directory if that is the desired effect. As for no longer creating all of directories in the destination path, NopArchive is precedent setting as it expects to write files only to destinations that exist already.
- Loading branch information
1 parent
879f5f0
commit 9e15703
Showing
7 changed files
with
149 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package vacation_test | ||
|
||
import ( | ||
"bytes" | ||
"encoding/base64" | ||
"io/fs" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/paketo-buildpacks/packit/vacation" | ||
"github.com/sclevine/spec" | ||
|
||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func testExecutable(t *testing.T, context spec.G, it spec.S) { | ||
var Expect = NewWithT(t).Expect | ||
|
||
context("Decompress", func() { | ||
var ( | ||
archive vacation.Executable | ||
tempDir string | ||
// Encoding of a very small elf executable from https://github.com/mathiasbynens/small | ||
encodedContents = []byte(`f0VMRgEBAQAAAAAAAAAAAAIAAwABAAAAGUDNgCwAAAAAAAAAAAAAADQAIAABAAAAAAAAAABAzYAAQM2ATAAAAEwAAAAFAAAAABAAAA==`) | ||
literalContents []byte | ||
) | ||
|
||
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.NewExecutable(bytes.NewBuffer(literalContents)) | ||
}) | ||
|
||
it.After(func() { | ||
Expect(os.RemoveAll(tempDir)).To(Succeed()) | ||
}) | ||
|
||
context("when passed the reader of an executable file", func() { | ||
it("writes the executable in the destination directory and sets the permissions using a default name", func() { | ||
err := archive.Decompress(tempDir) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
content, err := os.ReadFile(filepath.Join(tempDir, "artifact")) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(content).To(Equal(literalContents)) | ||
|
||
info, err := os.Stat(filepath.Join(tempDir, "artifact")) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(info.Mode()).To(Equal(fs.FileMode(0755))) | ||
}) | ||
|
||
it("writes the executable in the destination directory and sets the permissions using a given name", func() { | ||
err := archive.WithName("executable").Decompress(tempDir) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
content, err := os.ReadFile(filepath.Join(tempDir, "executable")) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(content).To(Equal(literalContents)) | ||
|
||
info, err := os.Stat(filepath.Join(tempDir, "executable")) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(info.Mode()).To(Equal(fs.FileMode(0755))) | ||
}) | ||
}) | ||
|
||
context("failure cases", func() { | ||
context("when the destination file cannot be created", func() { | ||
it("returns an error", func() { | ||
err := archive.Decompress("/no/such/path") | ||
Expect(err).To(MatchError(ContainSubstring("no such file or directory"))) | ||
}) | ||
}) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters