Merge pull request #704 from pulumi/CloseAssetsInZip
Close assets while creating ZIP archives.
This commit is contained in:
commit
4d59c70d9e
2 changed files with 46 additions and 0 deletions
|
@ -860,6 +860,7 @@ func addNextFileToZIP(r ArchiveReader, zw *zip.Writer) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
defer contract.IgnoreClose(data)
|
||||||
|
|
||||||
fw, err := zw.Create(file)
|
fw, err := zw.Create(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -7,11 +7,13 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"github.com/pulumi/pulumi/pkg/util/contract"
|
"github.com/pulumi/pulumi/pkg/util/contract"
|
||||||
|
@ -259,6 +261,49 @@ func TestArchiveZip(t *testing.T) {
|
||||||
validateTestDirArchive(t, arch)
|
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) {
|
func validateTestDirArchive(t *testing.T, arch *Archive) {
|
||||||
r, err := arch.Open()
|
r, err := arch.Open()
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
Loading…
Reference in a new issue