@@ -36,7 +36,7 @@ import (
3636func TestBuildpackDownloader (t * testing.T ) {
3737 color .Disable (true )
3838 defer color .Disable (false )
39- spec .Run (t , "BuildpackDownloader" , testBuildpackDownloader , spec .Parallel (), spec . Report (report.Terminal {}))
39+ spec .Run (t , "BuildpackDownloader" , testBuildpackDownloader , spec .Report (report.Terminal {}))
4040}
4141func testBuildpackDownloader (t * testing.T , when spec.G , it spec.S ) {
4242 var (
@@ -102,12 +102,31 @@ func testBuildpackDownloader(t *testing.T, when spec.G, it spec.S) {
102102 mockDockerClient .EXPECT ().Info (context .TODO ()).Return (types.Info {OSType : "linux" }, nil ).AnyTimes ()
103103
104104 tmpDir , err = ioutil .TempDir ("" , "buildpack-downloader-test" )
105+
106+ packHome := filepath .Join (tmpDir , ".pack" )
107+ err = os .MkdirAll (packHome , 0755 )
108+ h .AssertNil (t , err )
109+ os .Setenv ("PACK_HOME" , packHome )
110+ t .Logf ("%v pack home here %v" , t .Name (), packHome )
111+ registryFixture := h .CreateRegistryFixture (t , tmpDir , filepath .Join ("testdata" , "registry" ))
112+ configPath := filepath .Join (packHome , "config.toml" )
113+ h .AssertNil (t , cfg .Write (cfg.Config {
114+ Registries : []cfg.Registry {
115+ {
116+ Name : "some-registry" ,
117+ Type : "github" ,
118+ URL : registryFixture ,
119+ },
120+ },
121+ }, configPath ))
122+
105123 h .AssertNil (t , err )
106124 })
107125
108126 it .After (func () {
109127 mockController .Finish ()
110128 h .AssertNil (t , os .RemoveAll (tmpDir ))
129+ os .Unsetenv ("PACK_HOME" )
111130 })
112131
113132 when ("#DownloadBuildpack" , func () {
@@ -121,46 +140,13 @@ func testBuildpackDownloader(t *testing.T, when spec.G, it spec.S) {
121140
122141 var buildpackDownloadOptions pack.BuildpackDownloadOptions = pack.BuildpackDownloadOptions {ImageOS : "linux" }
123142 when ("package image lives in cnb registry" , func () {
124- var (
125- registryFixture string
126- packHome string
127- tmpDir string
128- )
129143 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-
141144 packageImage = createPackage ("example.com/some/package@sha256:74eb48882e835d8767f62940d453eb96ed2737de3a16573881dcea7dea769df7" )
142145 })
143- it .After (func () {
144- os .Unsetenv ("PACK_HOME" )
145- err := os .RemoveAll (tmpDir )
146- h .AssertNil (t , err )
147- })
148146 when ("daemon=true and pull-policy=always" , func () {
149- var configPath string
150147
151148 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 ))
149+
164150 buildpackDownloadOptions = pack.BuildpackDownloadOptions {
165151 RegistryName : "some-registry" ,
166152 ImageOS : "linux" ,
@@ -175,22 +161,7 @@ func testBuildpackDownloader(t *testing.T, when spec.G, it spec.S) {
175161 })
176162 })
177163 when ("ambigious URI provided" , func () {
178- var configPath string
179-
180164 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-
194165 buildpackDownloadOptions = pack.BuildpackDownloadOptions {
195166 RegistryName : "some-registry" ,
196167 ImageOS : "linux" ,
@@ -385,25 +356,8 @@ func testBuildpackDownloader(t *testing.T, when spec.G, it spec.S) {
385356 })
386357
387358 when ("buildpack is missing from registry" , func () {
388- var configPath string
389- var registryFixture string
390359
391360 it ("errors" , func () {
392- registryFixture = h .CreateRegistryFixture (t , tmpDir , filepath .Join ("testdata" , "registry" ))
393-
394- packHome := filepath .Join (tmpDir , "packHome" )
395- h .AssertNil (t , os .Setenv ("PACK_HOME" , packHome ))
396-
397- configPath = filepath .Join (packHome , "config.toml" )
398- h .AssertNil (t , cfg .Write (cfg.Config {
399- Registries : []cfg.Registry {
400- {
401- Name : "some-registry" ,
402- Type : "github" ,
403- URL : registryFixture ,
404- },
405- },
406- }, configPath ))
407361
408362 buildpackDownloadOptions .RegistryName = "some-registry"
409363 _ , _ , err := subject .BuildpackDownloader .Download (context .TODO (), "urn:cnb:registry:fake" , buildpackDownloadOptions )
@@ -413,24 +367,8 @@ func testBuildpackDownloader(t *testing.T, when spec.G, it spec.S) {
413367 })
414368
415369 when ("can't download image from registry" , func () {
416- var configPath string
417- var registryFixture string
418370
419371 it ("errors" , func () {
420- registryFixture = h .CreateRegistryFixture (t , tmpDir , filepath .Join ("testdata" , "registry" ))
421- packHome := filepath .Join (tmpDir , "packHome" )
422- h .AssertNil (t , os .Setenv ("PACK_HOME" , packHome ))
423-
424- configPath = filepath .Join (packHome , "config.toml" )
425- h .AssertNil (t , cfg .Write (cfg.Config {
426- Registries : []cfg.Registry {
427- {
428- Name : "some-registry" ,
429- Type : "github" ,
430- URL : registryFixture ,
431- },
432- },
433- }, configPath ))
434372
435373 packageImage := fakes .NewImage ("example.com/some/package@sha256:74eb48882e835d8767f62940d453eb96ed2737de3a16573881dcea7dea769df7" , "" , nil )
436374 mockImageFetcher .EXPECT ().Fetch (gomock .Any (), packageImage .Name (), image.FetchOptions {Daemon : false , PullPolicy : config .PullAlways }).Return (nil , errors .New ("failed to pull" ))
0 commit comments