Skip to content

Commit

Permalink
Merge pull request #373 from developer-guy/feature/3176
Browse files Browse the repository at this point in the history
feat: accept files in oci build
  • Loading branch information
stefanprodan authored Oct 10, 2022
2 parents a7d54fb + 943902c commit 60dfe84
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion oci/client/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
// Build archives the given directory as a tarball to the given local path.
// While archiving, any environment specific data (for example, the user and group name) is stripped from file headers.
func (c *Client) Build(artifactPath, sourceDir string, ignorePaths []string) (err error) {
if f, err := os.Stat(sourceDir); os.IsNotExist(err) || !f.IsDir() {
if _, err := os.Stat(sourceDir); os.IsNotExist(err) {
return fmt.Errorf("invalid source dir path: %s", sourceDir)
}

Expand Down
35 changes: 35 additions & 0 deletions oci/client/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,41 @@ func TestBuild(t *testing.T) {
}
}

// test only one file exists
func TestBuildOneFile(t *testing.T) {
c := NewLocalClient()
g := NewWithT(t)

tmpDir := t.TempDir()
artifactPath := filepath.Join(tmpDir, "files.tar.gz")

sourceDir := "testdata/artifact"
sourceFile := filepath.Join(sourceDir, "/deployment.yaml")

err := c.Build(artifactPath, sourceFile, []string{})
if err != nil {
t.Fatal(err)
}

_, err = os.Stat(artifactPath)
g.Expect(err).ToNot(HaveOccurred())

b, err := os.ReadFile(artifactPath)
g.Expect(err).ToNot(HaveOccurred())

untarDir := t.TempDir()
_, err = untar.Untar(bytes.NewReader(b), untarDir)
g.Expect(err).ToNot(HaveOccurred())

_, err = os.Stat(filepath.Join(untarDir, sourceFile))
g.Expect(err).ToNot(HaveOccurred())

files, err := os.ReadDir(filepath.Join(untarDir, sourceDir))
g.Expect(err).ToNot(HaveOccurred())

g.Expect(len(files)).To(Equal(1))
}

func checkPathExists(t *testing.T, dir, testDir string, paths []string) {
g := NewWithT(t)

Expand Down

0 comments on commit 60dfe84

Please sign in to comment.