Merge pull request #704 from pulumi/CloseAssetsInZip
Close assets while creating ZIP archives.
This commit is contained in:
commit
4d59c70d9e
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue