@@ -24,6 +24,7 @@ func Test_Building_container(t *testing.T) {
2424 t .Parallel ()
2525
2626 c := & Config {
27+ ImageRef : "foo" ,
2728 DefaultOutputImage : "foo" ,
2829 }
2930
@@ -49,24 +50,37 @@ func Test_Building_container(t *testing.T) {
4950
5051 ctx := t .Context ()
5152
52- state := c .BuildContainer (ctx , client , dalec.SourceOpts {}, spec , "target" , llb.State {})
53+ sopt := dalec.SourceOpts {
54+ GetContext : func (string , ... llb.LocalOption ) (* llb.State , error ) {
55+ return nil , nil
56+ },
57+ }
58+
59+ state := c .BuildContainer (ctx , client , sopt , spec , "target" , llb.State {})
5360
5461 ops , err := test .LLBOpsFromState (ctx , state )
5562 if err != nil {
5663 t .Fatalf ("failed to get llb ops from state: %v" , err )
5764 }
5865
59- if len (ops ) == 0 {
60- t .Fatalf ("expected at least one llb op, got none" )
61- }
66+ specPackageImageSourceFound := false
6267
63- s := ops [0 ].Op .GetSource ()
64- if s == nil {
65- t .Fatalf ("expected source op, got nil" )
68+ for _ , op := range ops {
69+ s := op .Op .GetSource ()
70+
71+ if s == nil || op .OpMetadata .ProgressGroup .Name != "Build Container Image" {
72+ continue
73+ }
74+
75+ specPackageImageSourceFound = true
76+
77+ if ! strings .Contains (s .Identifier , expectedRef ) {
78+ t .Fatalf ("expected source identifier to contain %q, got %q" , expectedRef , s .Identifier )
79+ }
6680 }
6781
68- if ! strings . Contains ( s . Identifier , expectedRef ) {
69- t .Fatalf ("expected source identifier to contain %q, got %q" , expectedRef , s . Identifier )
82+ if ! specPackageImageSourceFound {
83+ t .Fatalf ("Expected to find spec package source in llb ops" )
7084 }
7185 })
7286
@@ -78,6 +92,7 @@ func Test_Building_container(t *testing.T) {
7892 expectedRef := "foo"
7993
8094 c := & Config {
95+ ImageRef : "foo" ,
8196 DefaultOutputImage : expectedRef ,
8297 }
8398
@@ -89,7 +104,13 @@ func Test_Building_container(t *testing.T) {
89104
90105 ctx := t .Context ()
91106
92- state := c .BuildContainer (ctx , client , dalec.SourceOpts {}, spec , "target" , llb.State {})
107+ sopt := dalec.SourceOpts {
108+ GetContext : func (string , ... llb.LocalOption ) (* llb.State , error ) {
109+ return nil , nil
110+ },
111+ }
112+
113+ state := c .BuildContainer (ctx , client , sopt , spec , "target" , llb.State {})
93114
94115 ops , err := test .LLBOpsFromState (ctx , state )
95116 if err != nil {
@@ -119,6 +140,7 @@ func Test_Building_container(t *testing.T) {
119140 extraInstallRepo := "extra-install-repo"
120141
121142 c := & Config {
143+ ImageRef : "foo" ,
122144 DefaultOutputImage : "foo" ,
123145 ExtraRepos : []dalec.PackageRepositoryConfig {
124146 {
@@ -150,7 +172,12 @@ func Test_Building_container(t *testing.T) {
150172
151173 ctx := t .Context ()
152174
153- ops , err := test .LLBOpsFromState (ctx , c .BuildContainer (ctx , & testClient {}, dalec.SourceOpts {}, & dalec.Spec {}, "target" , llb.State {}))
175+ sopt := dalec.SourceOpts {
176+ GetContext : func (string , ... llb.LocalOption ) (* llb.State , error ) {
177+ return nil , nil
178+ },
179+ }
180+ ops , err := test .LLBOpsFromState (ctx , c .BuildContainer (ctx , & testClient {}, sopt , & dalec.Spec {}, "target" , llb.State {}))
154181 if err != nil {
155182 t .Fatalf ("failed to get llb ops from state: %v" , err )
156183 }
@@ -190,6 +217,7 @@ func Test_Building_container(t *testing.T) {
190217 aptCachePrefix := "apt-cache-prefix"
191218
192219 c := & Config {
220+ ImageRef : "foo" ,
193221 DefaultOutputImage : "foo" ,
194222 VersionID : "bar" ,
195223 ContextRef : "distro-context-ref" ,
@@ -200,9 +228,7 @@ func Test_Building_container(t *testing.T) {
200228
201229 sopt := dalec.SourceOpts {
202230 GetContext : func (string , ... llb.LocalOption ) (* llb.State , error ) {
203- s := llb .Scratch ()
204-
205- return & s , nil
231+ return nil , nil
206232 },
207233 }
208234
@@ -255,6 +281,7 @@ func Test_Building_container(t *testing.T) {
255281 t .Parallel ()
256282
257283 c := & Config {
284+ ImageRef : "foo" ,
258285 DefaultOutputImage : "foo" ,
259286 BasePackages : []string {"base-package-1" },
260287 VersionID : "bar" ,
@@ -265,9 +292,7 @@ func Test_Building_container(t *testing.T) {
265292
266293 sopt := dalec.SourceOpts {
267294 GetContext : func (string , ... llb.LocalOption ) (* llb.State , error ) {
268- s := llb .Scratch ()
269-
270- return & s , nil
295+ return nil , nil
271296 },
272297 }
273298
@@ -278,12 +303,16 @@ func Test_Building_container(t *testing.T) {
278303 t .Fatalf ("failed to get llb ops from state: %v" , err )
279304 }
280305
306+ execOpFound := false
307+
281308 for _ , op := range ops {
282309 e := op .Op .GetExec ()
283310 if e == nil || op .OpMetadata .ProgressGroup .Name != "Install base image packages" {
284311 continue
285312 }
286313
314+ execOpFound = true
315+
287316 for _ , v := range e .Meta .Env {
288317 s := strings .Split (v , "=" )
289318 if len (s ) != 2 {
@@ -304,13 +333,18 @@ func Test_Building_container(t *testing.T) {
304333 }
305334 }
306335
336+ if ! execOpFound {
337+ t .Fatalf ("Exec op for installing base packages not found" )
338+ }
339+
307340 t .Fatalf ("Expected DALEC_UPGRADE to be set when installing base packages" )
308341 })
309342
310343 t .Run ("before_installing_spec_package" , func (t * testing.T ) {
311344 t .Parallel ()
312345
313346 c := & Config {
347+ ImageRef : "foo" ,
314348 DefaultOutputImage : "foo" ,
315349 BasePackages : []string {"base-package-1" },
316350 VersionID : "bar" ,
@@ -321,9 +355,7 @@ func Test_Building_container(t *testing.T) {
321355
322356 sopt := dalec.SourceOpts {
323357 GetContext : func (string , ... llb.LocalOption ) (* llb.State , error ) {
324- s := llb .Scratch ()
325-
326- return & s , nil
358+ return nil , nil
327359 },
328360 }
329361
@@ -385,6 +417,7 @@ func Test_Building_container(t *testing.T) {
385417 aptCachePrefix := "apt-cache-prefix"
386418
387419 c := & Config {
420+ ImageRef : "foo" ,
388421 DefaultOutputImage : "foo" ,
389422 BasePackages : []string {"base-package-1" },
390423 VersionID : "bar" ,
@@ -396,9 +429,7 @@ func Test_Building_container(t *testing.T) {
396429
397430 sopt := dalec.SourceOpts {
398431 GetContext : func (string , ... llb.LocalOption ) (* llb.State , error ) {
399- s := llb .Scratch ()
400-
401- return & s , nil
432+ return nil , nil
402433 },
403434 }
404435
@@ -411,12 +442,16 @@ func Test_Building_container(t *testing.T) {
411442
412443 aptCacheFound := false
413444
445+ execOpFound := false
446+
414447 for _ , op := range ops {
415448 e := op .Op .GetExec ()
416449 if e == nil || op .OpMetadata .ProgressGroup .Name != "Install base image packages" {
417450 continue
418451 }
419452
453+ execOpFound = true
454+
420455 for _ , mount := range e .Mounts {
421456 if mount .Dest == "/var/cache/apt" {
422457 aptCacheFound = true
@@ -438,6 +473,10 @@ func Test_Building_container(t *testing.T) {
438473 }
439474 }
440475
476+ if ! execOpFound {
477+ t .Fatalf ("Exec op for installing base packages not found" )
478+ }
479+
441480 if ! aptCacheFound {
442481 t .Fatalf ("Apt cache mount not found before installing base packages" )
443482 }
0 commit comments