diff --git a/pkg/resource/asset.go b/pkg/resource/asset.go index 26aaf8647..4b6a45f1c 100644 --- a/pkg/resource/asset.go +++ b/pkg/resource/asset.go @@ -860,6 +860,7 @@ func addNextFileToZIP(r ArchiveReader, zw *zip.Writer) error { if err != nil { return err } + defer contract.IgnoreClose(data) fw, err := zw.Create(file) if err != nil { diff --git a/pkg/resource/asset_test.go b/pkg/resource/asset_test.go index 5a5a6765b..c3f8a4590 100644 --- a/pkg/resource/asset_test.go +++ b/pkg/resource/asset_test.go @@ -7,11 +7,13 @@ import ( "bytes" "fmt" "io" + "io/ioutil" "math/rand" "os" "path/filepath" "testing" + "github.com/pkg/errors" "github.com/stretchr/testify/assert" "github.com/pulumi/pulumi/pkg/util/contract" @@ -259,6 +261,49 @@ func TestArchiveZip(t *testing.T) { validateTestDirArchive(t, arch) } +func findRepositoryRoot() (string, error) { + wd, err := os.Getwd() + if err != nil { + return "", err + } + + for d := wd; ; d = filepath.Dir(d) { + if d == "" || d == "." || d[len(d)-1] == filepath.Separator { + return "", errors.New("could not find repository root") + } + gitDir := filepath.Join(d, ".git") + _, err := os.Lstat(gitDir) + switch { + case err == nil: + return d, nil + case !os.IsNotExist(err): + return "", err + } + } +} + +func TestArchiveTarFiles(t *testing.T) { + repoRoot, err := findRepositoryRoot() + assert.Nil(t, err) + + arch, err := NewPathArchive(repoRoot) + assert.Nil(t, err) + + err = arch.Archive(TarArchive, ioutil.Discard) + assert.Nil(t, err) +} + +func TestArchiveZipFiles(t *testing.T) { + repoRoot, err := findRepositoryRoot() + assert.Nil(t, err) + + arch, err := NewPathArchive(repoRoot) + assert.Nil(t, err) + + err = arch.Archive(ZIPArchive, ioutil.Discard) + assert.Nil(t, err) +} + func validateTestDirArchive(t *testing.T, arch *Archive) { r, err := arch.Open() assert.Nil(t, err)