Merge pull request #704 from pulumi/CloseAssetsInZip

Close assets while creating ZIP archives.
This commit is contained in:
Joe Duffy 2017-12-12 11:09:08 -08:00 committed by GitHub
commit 4d59c70d9e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 0 deletions

View file

@ -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 {

View file

@ -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)