Skip to content

Commit

Permalink
all tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
YousefHaggyHeroku committed Jul 14, 2021
1 parent ee432f5 commit a30787f
Showing 1 changed file with 86 additions and 21 deletions.
107 changes: 86 additions & 21 deletions buildpack_downloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ func testBuildpackDownloader(t *testing.T, when spec.G, it spec.S) {
logger logging.Logger
out bytes.Buffer
tmpDir string
registryFixture string
packHome string
configPath string
)
var createBuildpack = func(descriptor dist.BuildpackDescriptor) string {
bp, err := ifakes.NewFakeBuildpackBlob(descriptor, 0644)
Expand Down Expand Up @@ -106,29 +103,11 @@ func testBuildpackDownloader(t *testing.T, when spec.G, it spec.S) {

tmpDir, err = ioutil.TempDir("", "buildpack-downloader-test")
h.AssertNil(t, err)

registryFixture = h.CreateRegistryFixture(t, tmpDir, filepath.Join("testdata", "registry"))

packHome = filepath.Join(tmpDir, "packHome")
err = os.MkdirAll(packHome, 0755)
h.AssertNil(t, err)
h.AssertNil(t, os.Setenv("PACK_HOME", packHome))
configPath = filepath.Join(packHome, "config.toml")
h.AssertNil(t, cfg.Write(cfg.Config{
Registries: []cfg.Registry{
{
Name: "some-registry",
Type: "github",
URL: registryFixture,
},
},
}, configPath))
})

it.After(func() {
mockController.Finish()
h.AssertNil(t, os.RemoveAll(tmpDir))
os.Unsetenv("PACK_HOME")
})

when("#DownloadBuildpack", func() {
Expand All @@ -142,11 +121,46 @@ func testBuildpackDownloader(t *testing.T, when spec.G, it spec.S) {

var buildpackDownloadOptions pack.BuildpackDownloadOptions = pack.BuildpackDownloadOptions{ImageOS: "linux"}
when("package image lives in cnb registry", func() {
var (
registryFixture string
packHome string
tmpDir string
)
it.Before(func() {
var err error
tmpDir, err = ioutil.TempDir("", "registry")
h.AssertNil(t, err)

packHome = filepath.Join(tmpDir, ".pack")
err = os.MkdirAll(packHome, 0755)
h.AssertNil(t, err)
os.Setenv("PACK_HOME", packHome)

registryFixture = h.CreateRegistryFixture(t, tmpDir, filepath.Join("testdata", "registry"))

packageImage = createPackage("example.com/some/package@sha256:74eb48882e835d8767f62940d453eb96ed2737de3a16573881dcea7dea769df7")
})
it.After(func() {
os.Unsetenv("PACK_HOME")
err := os.RemoveAll(tmpDir)
h.AssertNil(t, err)
})
when("daemon=true and pull-policy=always", func() {
var configPath string

it("should pull and use local package image", func() {
packHome := filepath.Join(tmpDir, "packHome")
h.AssertNil(t, os.Setenv("PACK_HOME", packHome))
configPath = filepath.Join(packHome, "config.toml")
h.AssertNil(t, cfg.Write(cfg.Config{
Registries: []cfg.Registry{
{
Name: "some-registry",
Type: "github",
URL: registryFixture,
},
},
}, configPath))
buildpackDownloadOptions = pack.BuildpackDownloadOptions{
RegistryName: "some-registry",
ImageOS: "linux",
Expand All @@ -161,7 +175,22 @@ func testBuildpackDownloader(t *testing.T, when spec.G, it spec.S) {
})
})
when("ambigious URI provided", func() {
var configPath string

it("should find package in registry", func() {
packHome := filepath.Join(tmpDir, "packHome")
h.AssertNil(t, os.Setenv("PACK_HOME", packHome))
configPath = filepath.Join(packHome, "config.toml")
h.AssertNil(t, cfg.Write(cfg.Config{
Registries: []cfg.Registry{
{
Name: "some-registry",
Type: "github",
URL: registryFixture,
},
},
}, configPath))

buildpackDownloadOptions = pack.BuildpackDownloadOptions{
RegistryName: "some-registry",
ImageOS: "linux",
Expand Down Expand Up @@ -358,7 +387,26 @@ func testBuildpackDownloader(t *testing.T, when spec.G, it spec.S) {
})

when("buildpack is missing from registry", func() {
var configPath string
var registryFixture string

it("errors", func() {
registryFixture = h.CreateRegistryFixture(t, tmpDir, filepath.Join("testdata", "registry"))

packHome := filepath.Join(tmpDir, "packHome")
h.AssertNil(t, os.Setenv("PACK_HOME", packHome))

configPath = filepath.Join(packHome, "config.toml")
h.AssertNil(t, cfg.Write(cfg.Config{
Registries: []cfg.Registry{
{
Name: "some-registry",
Type: "github",
URL: registryFixture,
},
},
}, configPath))

buildpackDownloadOptions.RegistryName = "some-registry"
_, _, err := subject.BuildpackDownloader.Download(context.TODO(), "urn:cnb:registry:fake", buildpackDownloadOptions)
h.AssertError(t, err,
Expand All @@ -367,7 +415,24 @@ func testBuildpackDownloader(t *testing.T, when spec.G, it spec.S) {
})

when("can't download image from registry", func() {
var configPath string
var registryFixture string

it("errors", func() {
registryFixture = h.CreateRegistryFixture(t, tmpDir, filepath.Join("testdata", "registry"))
packHome := filepath.Join(tmpDir, "packHome")
h.AssertNil(t, os.Setenv("PACK_HOME", packHome))

configPath = filepath.Join(packHome, "config.toml")
h.AssertNil(t, cfg.Write(cfg.Config{
Registries: []cfg.Registry{
{
Name: "some-registry",
Type: "github",
URL: registryFixture,
},
},
}, configPath))

packageImage := fakes.NewImage("example.com/some/package@sha256:74eb48882e835d8767f62940d453eb96ed2737de3a16573881dcea7dea769df7", "", nil)
mockImageFetcher.EXPECT().Fetch(gomock.Any(), packageImage.Name(), image.FetchOptions{Daemon: false, PullPolicy: config.PullAlways}).Return(nil, errors.New("failed to pull"))
Expand Down

0 comments on commit a30787f

Please sign in to comment.