@@ -50,9 +50,6 @@ func testBuildpackDownloader(t *testing.T, when spec.G, it spec.S) {
5050 logger logging.Logger
5151 out bytes.Buffer
5252 tmpDir string
53- registryFixture string
54- packHome string
55- configPath string
5653 )
5754 var createBuildpack = func (descriptor dist.BuildpackDescriptor ) string {
5855 bp , err := ifakes .NewFakeBuildpackBlob (descriptor , 0644 )
@@ -106,29 +103,11 @@ func testBuildpackDownloader(t *testing.T, when spec.G, it spec.S) {
106103
107104 tmpDir , err = ioutil .TempDir ("" , "buildpack-downloader-test" )
108105 h .AssertNil (t , err )
109-
110- registryFixture = h .CreateRegistryFixture (t , tmpDir , filepath .Join ("testdata" , "registry" ))
111-
112- packHome = filepath .Join (tmpDir , "packHome" )
113- err = os .MkdirAll (packHome , 0755 )
114- h .AssertNil (t , err )
115- h .AssertNil (t , os .Setenv ("PACK_HOME" , packHome ))
116- configPath = filepath .Join (packHome , "config.toml" )
117- h .AssertNil (t , cfg .Write (cfg.Config {
118- Registries : []cfg.Registry {
119- {
120- Name : "some-registry" ,
121- Type : "github" ,
122- URL : registryFixture ,
123- },
124- },
125- }, configPath ))
126106 })
127107
128108 it .After (func () {
129109 mockController .Finish ()
130110 h .AssertNil (t , os .RemoveAll (tmpDir ))
131- os .Unsetenv ("PACK_HOME" )
132111 })
133112
134113 when ("#DownloadBuildpack" , func () {
@@ -142,11 +121,46 @@ func testBuildpackDownloader(t *testing.T, when spec.G, it spec.S) {
142121
143122 var buildpackDownloadOptions pack.BuildpackDownloadOptions = pack.BuildpackDownloadOptions {ImageOS : "linux" }
144123 when ("package image lives in cnb registry" , func () {
124+ var (
125+ registryFixture string
126+ packHome string
127+ tmpDir string
128+ )
145129 it .Before (func () {
130+ var err error
131+ tmpDir , err = ioutil .TempDir ("" , "registry" )
132+ h .AssertNil (t , err )
133+
134+ packHome = filepath .Join (tmpDir , ".pack" )
135+ err = os .MkdirAll (packHome , 0755 )
136+ h .AssertNil (t , err )
137+ os .Setenv ("PACK_HOME" , packHome )
138+
139+ registryFixture = h .CreateRegistryFixture (t , tmpDir , filepath .Join ("testdata" , "registry" ))
140+
146141 packageImage = createPackage ("example.com/some/package@sha256:74eb48882e835d8767f62940d453eb96ed2737de3a16573881dcea7dea769df7" )
147142 })
143+ it .After (func () {
144+ os .Unsetenv ("PACK_HOME" )
145+ err := os .RemoveAll (tmpDir )
146+ h .AssertNil (t , err )
147+ })
148148 when ("daemon=true and pull-policy=always" , func () {
149+ var configPath string
150+
149151 it ("should pull and use local package image" , func () {
152+ packHome := filepath .Join (tmpDir , "packHome" )
153+ h .AssertNil (t , os .Setenv ("PACK_HOME" , packHome ))
154+ configPath = filepath .Join (packHome , "config.toml" )
155+ h .AssertNil (t , cfg .Write (cfg.Config {
156+ Registries : []cfg.Registry {
157+ {
158+ Name : "some-registry" ,
159+ Type : "github" ,
160+ URL : registryFixture ,
161+ },
162+ },
163+ }, configPath ))
150164 buildpackDownloadOptions = pack.BuildpackDownloadOptions {
151165 RegistryName : "some-registry" ,
152166 ImageOS : "linux" ,
@@ -161,7 +175,22 @@ func testBuildpackDownloader(t *testing.T, when spec.G, it spec.S) {
161175 })
162176 })
163177 when ("ambigious URI provided" , func () {
178+ var configPath string
179+
164180 it ("should find package in registry" , func () {
181+ packHome := filepath .Join (tmpDir , "packHome" )
182+ h .AssertNil (t , os .Setenv ("PACK_HOME" , packHome ))
183+ configPath = filepath .Join (packHome , "config.toml" )
184+ h .AssertNil (t , cfg .Write (cfg.Config {
185+ Registries : []cfg.Registry {
186+ {
187+ Name : "some-registry" ,
188+ Type : "github" ,
189+ URL : registryFixture ,
190+ },
191+ },
192+ }, configPath ))
193+
165194 buildpackDownloadOptions = pack.BuildpackDownloadOptions {
166195 RegistryName : "some-registry" ,
167196 ImageOS : "linux" ,
@@ -358,7 +387,26 @@ func testBuildpackDownloader(t *testing.T, when spec.G, it spec.S) {
358387 })
359388
360389 when ("buildpack is missing from registry" , func () {
390+ var configPath string
391+ var registryFixture string
392+
361393 it ("errors" , func () {
394+ registryFixture = h .CreateRegistryFixture (t , tmpDir , filepath .Join ("testdata" , "registry" ))
395+
396+ packHome := filepath .Join (tmpDir , "packHome" )
397+ h .AssertNil (t , os .Setenv ("PACK_HOME" , packHome ))
398+
399+ configPath = filepath .Join (packHome , "config.toml" )
400+ h .AssertNil (t , cfg .Write (cfg.Config {
401+ Registries : []cfg.Registry {
402+ {
403+ Name : "some-registry" ,
404+ Type : "github" ,
405+ URL : registryFixture ,
406+ },
407+ },
408+ }, configPath ))
409+
362410 buildpackDownloadOptions .RegistryName = "some-registry"
363411 _ , _ , err := subject .BuildpackDownloader .Download (context .TODO (), "urn:cnb:registry:fake" , buildpackDownloadOptions )
364412 h .AssertError (t , err ,
@@ -367,7 +415,24 @@ func testBuildpackDownloader(t *testing.T, when spec.G, it spec.S) {
367415 })
368416
369417 when ("can't download image from registry" , func () {
418+ var configPath string
419+ var registryFixture string
420+
370421 it ("errors" , func () {
422+ registryFixture = h .CreateRegistryFixture (t , tmpDir , filepath .Join ("testdata" , "registry" ))
423+ packHome := filepath .Join (tmpDir , "packHome" )
424+ h .AssertNil (t , os .Setenv ("PACK_HOME" , packHome ))
425+
426+ configPath = filepath .Join (packHome , "config.toml" )
427+ h .AssertNil (t , cfg .Write (cfg.Config {
428+ Registries : []cfg.Registry {
429+ {
430+ Name : "some-registry" ,
431+ Type : "github" ,
432+ URL : registryFixture ,
433+ },
434+ },
435+ }, configPath ))
371436
372437 packageImage := fakes .NewImage ("example.com/some/package@sha256:74eb48882e835d8767f62940d453eb96ed2737de3a16573881dcea7dea769df7" , "" , nil )
373438 mockImageFetcher .EXPECT ().Fetch (gomock .Any (), packageImage .Name (), image.FetchOptions {Daemon : false , PullPolicy : config .PullAlways }).Return (nil , errors .New ("failed to pull" ))
0 commit comments