Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Commit

Permalink
Use a temporary directory for export
Browse files Browse the repository at this point in the history
Fixes #721
  • Loading branch information
benpatt authored and glyn committed Jul 22, 2019
1 parent 85156ca commit 2fd6743
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
3 changes: 2 additions & 1 deletion pkg/packager/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package packager
import (
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"time"
Expand Down Expand Up @@ -75,7 +76,7 @@ func (ex *Exporter) Export() error {
return fmt.Errorf("Error loading bundle: %s", err)
}
name := bun.Name + "-" + bun.Version
archiveDir, err := filepath.Abs(name + "-export")
archiveDir, err := ioutil.TempDir("", name)
if err != nil {
return err
}
Expand Down
13 changes: 7 additions & 6 deletions pkg/packager/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"path/filepath"
"reflect"
"sort"
"strings"
"testing"

"github.com/deislabs/duffle/pkg/loader"
Expand Down Expand Up @@ -52,10 +53,10 @@ func TestExport(t *testing.T) {
t.Errorf("Expected no error, got error: %v", err)
}

expectedConfigArchiveDirBase := "examplebun-0.1.0-export"
expectedPrefix := "examplebun-0.1.0"
configArchiveDirBase := filepath.Base(configArchiveDir)
if configArchiveDirBase != expectedConfigArchiveDirBase {
t.Errorf("ImageStore.configure was passed an archive directory ending in %s; expected %s", configArchiveDirBase, expectedConfigArchiveDirBase)
if !strings.HasPrefix(configArchiveDirBase, expectedPrefix) {
t.Errorf("ImageStore.configure was passed an archive directory %s; expected prefix %s", configArchiveDirBase, expectedPrefix)
}

expectedImagesAdded := []string{"mock/examplebun:0.1.0", "mock/image-a:58326809e0p19b79054015bdd4e93e84b71ae1ta", "mock/image-b:88426103e0p19b38554015bd34e93e84b71de2fc"}
Expand Down Expand Up @@ -107,10 +108,10 @@ func TestExportCreatesFileProperly(t *testing.T) {
t.Error("Expected path does not exist error, got no error")
}

expectedConfigArchiveDirBase := "examplebun-0.1.0-export"
expectedPrefix := "examplebun-0.1.0"
configArchiveDirBase := filepath.Base(configArchiveDir)
if configArchiveDirBase != expectedConfigArchiveDirBase {
t.Errorf("ImageStore.configure was passed an archive directory ending in %s; expected %s", configArchiveDirBase, expectedConfigArchiveDirBase)
if !strings.HasPrefix(configArchiveDirBase, expectedPrefix) {
t.Errorf("ImageStore.configure was passed an archive directory %s; expected prefix %s", configArchiveDirBase, expectedPrefix)
}

expectedImagesAdded := []string{"mock/examplebun:0.1.0", "mock/image-a:58326809e0p19b79054015bdd4e93e84b71ae1ta", "mock/image-b:88426103e0p19b38554015bd34e93e84b71de2fc"}
Expand Down

0 comments on commit 2fd6743

Please sign in to comment.