This repository has been archived by the owner on May 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref(*): use bundle reference for export
- Loading branch information
Michelle Noorali
committed
Jan 25, 2019
1 parent
2af5fe4
commit 93a25e8
Showing
19 changed files
with
250 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package main | ||
|
||
import ( | ||
"io" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/deislabs/duffle/pkg/duffle/home" | ||
) | ||
|
||
func setupTempDuffleHome(t *testing.T) (string, error) { | ||
tempDuffleHome, err := ioutil.TempDir("", "dufflehome") | ||
if err != nil { | ||
return "", err | ||
} | ||
duffleHome := home.Home(tempDuffleHome) | ||
if err := os.MkdirAll(duffleHome.Bundles(), 0755); err != nil { | ||
return "", err | ||
} | ||
if err := os.MkdirAll(duffleHome.Logs(), 0755); err != nil { | ||
return "", err | ||
} | ||
keyring := filepath.Join("..", "..", "pkg", "signature", "testdata", "keyring.gpg") | ||
|
||
err = copyFile(keyring, filepath.Join(tempDuffleHome, "public.ring")) | ||
if err != nil { | ||
return "", err | ||
} | ||
mockSigningKeyring(tempDuffleHome, t) | ||
|
||
return tempDuffleHome, nil | ||
} | ||
|
||
func TestExportSetup(t *testing.T) { | ||
out := ioutil.Discard | ||
tempDuffleHome, err := setupTempDuffleHome(t) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer os.Remove(tempDuffleHome) | ||
|
||
signedBundle := filepath.Join("..", "..", "tests", "testdata", "bundles", "foo.cnab") | ||
outfile := "foo-1.0.0.cnab" | ||
if err = copyFile(signedBundle, filepath.Join(tempDuffleHome, "bundles", outfile)); err != nil { | ||
t.Fatal(err) | ||
} | ||
var jsonBlob = []byte(`{ | ||
"foo": { | ||
"1.0.0": "foo-1.0.0.cnab" | ||
} | ||
} `) | ||
if err := ioutil.WriteFile(filepath.Join(tempDuffleHome, "repositories.json"), jsonBlob, 0644); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// Setup a temporary dir for destination | ||
tempDir, err := ioutil.TempDir("", "duffledest") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
duffleHome := home.Home(tempDuffleHome) | ||
exp := &exportCmd{ | ||
bundleRef: "foo:1.0.0", | ||
dest: tempDir, | ||
home: duffleHome, | ||
out: out, | ||
} | ||
|
||
source, _, err := exp.setup() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
expectedSource := filepath.Join(tempDuffleHome, "bundles", "foo-1.0.0.cnab") | ||
if source != expectedSource { | ||
t.Errorf("Expected source to be %s, got %s", expectedSource, source) | ||
} | ||
|
||
expFail := &exportCmd{ | ||
bundleRef: "bar:1.0.0", | ||
dest: tempDir, | ||
home: duffleHome, | ||
out: out, | ||
} | ||
_, _, err = expFail.setup() | ||
if err == nil { | ||
t.Error("Expected error, got none") | ||
} | ||
|
||
} | ||
|
||
func copyFile(src, dst string) (err error) { | ||
in, err := os.Open(src) | ||
if err != nil { | ||
return | ||
} | ||
defer in.Close() | ||
|
||
out, err := os.Create(dst) | ||
if err != nil { | ||
return | ||
} | ||
defer out.Close() | ||
|
||
if _, err = io.Copy(out, in); err != nil { | ||
return nil | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.