@@ -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,45 @@ 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" )
66+ specPackageImageSourceFound := false
67+
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+ }
6180 }
6281
63- s := ops [ 0 ]. Op . GetSource ( )
64- if s = = nil {
65- t .Fatalf ("expected source op, got nil" )
82+ raw , err := test . LLBOpsToJSON ( ops )
83+ if err ! = nil {
84+ t .Fatalf ("failed to marshal llb op to json: %v" , err )
6685 }
6786
68- if ! strings .Contains (s .Identifier , expectedRef ) {
69- t .Fatalf ("expected source identifier to contain %q, got %q" , expectedRef , s .Identifier )
87+ _ = raw
88+ // t.Errorf("\n%s", raw)
89+
90+ if ! specPackageImageSourceFound {
91+ t .Fatalf ("Expected to find spec package source in llb ops" )
7092 }
7193 })
7294
@@ -78,6 +100,7 @@ func Test_Building_container(t *testing.T) {
78100 expectedRef := "foo"
79101
80102 c := & Config {
103+ ImageRef : "foo" ,
81104 DefaultOutputImage : expectedRef ,
82105 }
83106
@@ -89,7 +112,13 @@ func Test_Building_container(t *testing.T) {
89112
90113 ctx := t .Context ()
91114
92- state := c .BuildContainer (ctx , client , dalec.SourceOpts {}, spec , "target" , llb.State {})
115+ sopt := dalec.SourceOpts {
116+ GetContext : func (string , ... llb.LocalOption ) (* llb.State , error ) {
117+ return nil , nil
118+ },
119+ }
120+
121+ state := c .BuildContainer (ctx , client , sopt , spec , "target" , llb.State {})
93122
94123 ops , err := test .LLBOpsFromState (ctx , state )
95124 if err != nil {
@@ -119,6 +148,7 @@ func Test_Building_container(t *testing.T) {
119148 extraInstallRepo := "extra-install-repo"
120149
121150 c := & Config {
151+ ImageRef : "foo" ,
122152 DefaultOutputImage : "foo" ,
123153 ExtraRepos : []dalec.PackageRepositoryConfig {
124154 {
@@ -150,7 +180,12 @@ func Test_Building_container(t *testing.T) {
150180
151181 ctx := t .Context ()
152182
153- ops , err := test .LLBOpsFromState (ctx , c .BuildContainer (ctx , & testClient {}, dalec.SourceOpts {}, & dalec.Spec {}, "target" , llb.State {}))
183+ sopt := dalec.SourceOpts {
184+ GetContext : func (string , ... llb.LocalOption ) (* llb.State , error ) {
185+ return nil , nil
186+ },
187+ }
188+ ops , err := test .LLBOpsFromState (ctx , c .BuildContainer (ctx , & testClient {}, sopt , & dalec.Spec {}, "target" , llb.State {}))
154189 if err != nil {
155190 t .Fatalf ("failed to get llb ops from state: %v" , err )
156191 }
@@ -190,6 +225,7 @@ func Test_Building_container(t *testing.T) {
190225 aptCachePrefix := "apt-cache-prefix"
191226
192227 c := & Config {
228+ ImageRef : "foo" ,
193229 DefaultOutputImage : "foo" ,
194230 VersionID : "bar" ,
195231 ContextRef : "distro-context-ref" ,
@@ -200,9 +236,7 @@ func Test_Building_container(t *testing.T) {
200236
201237 sopt := dalec.SourceOpts {
202238 GetContext : func (string , ... llb.LocalOption ) (* llb.State , error ) {
203- s := llb .Scratch ()
204-
205- return & s , nil
239+ return nil , nil
206240 },
207241 }
208242
@@ -255,6 +289,7 @@ func Test_Building_container(t *testing.T) {
255289 t .Parallel ()
256290
257291 c := & Config {
292+ ImageRef : "foo" ,
258293 DefaultOutputImage : "foo" ,
259294 BasePackages : []string {"base-package-1" },
260295 VersionID : "bar" ,
@@ -265,9 +300,7 @@ func Test_Building_container(t *testing.T) {
265300
266301 sopt := dalec.SourceOpts {
267302 GetContext : func (string , ... llb.LocalOption ) (* llb.State , error ) {
268- s := llb .Scratch ()
269-
270- return & s , nil
303+ return nil , nil
271304 },
272305 }
273306
@@ -278,12 +311,16 @@ func Test_Building_container(t *testing.T) {
278311 t .Fatalf ("failed to get llb ops from state: %v" , err )
279312 }
280313
314+ execOpFound := false
315+
281316 for _ , op := range ops {
282317 e := op .Op .GetExec ()
283318 if e == nil || op .OpMetadata .ProgressGroup .Name != "Install base image packages" {
284319 continue
285320 }
286321
322+ execOpFound = true
323+
287324 for _ , v := range e .Meta .Env {
288325 s := strings .Split (v , "=" )
289326 if len (s ) != 2 {
@@ -304,13 +341,18 @@ func Test_Building_container(t *testing.T) {
304341 }
305342 }
306343
344+ if ! execOpFound {
345+ t .Fatalf ("Exec op for installing base packages not found" )
346+ }
347+
307348 t .Fatalf ("Expected DALEC_UPGRADE to be set when installing base packages" )
308349 })
309350
310351 t .Run ("before_installing_spec_package" , func (t * testing.T ) {
311352 t .Parallel ()
312353
313354 c := & Config {
355+ ImageRef : "foo" ,
314356 DefaultOutputImage : "foo" ,
315357 BasePackages : []string {"base-package-1" },
316358 VersionID : "bar" ,
@@ -321,9 +363,7 @@ func Test_Building_container(t *testing.T) {
321363
322364 sopt := dalec.SourceOpts {
323365 GetContext : func (string , ... llb.LocalOption ) (* llb.State , error ) {
324- s := llb .Scratch ()
325-
326- return & s , nil
366+ return nil , nil
327367 },
328368 }
329369
@@ -385,6 +425,7 @@ func Test_Building_container(t *testing.T) {
385425 aptCachePrefix := "apt-cache-prefix"
386426
387427 c := & Config {
428+ ImageRef : "foo" ,
388429 DefaultOutputImage : "foo" ,
389430 BasePackages : []string {"base-package-1" },
390431 VersionID : "bar" ,
@@ -396,9 +437,7 @@ func Test_Building_container(t *testing.T) {
396437
397438 sopt := dalec.SourceOpts {
398439 GetContext : func (string , ... llb.LocalOption ) (* llb.State , error ) {
399- s := llb .Scratch ()
400-
401- return & s , nil
440+ return nil , nil
402441 },
403442 }
404443
@@ -411,12 +450,16 @@ func Test_Building_container(t *testing.T) {
411450
412451 aptCacheFound := false
413452
453+ execOpFound := false
454+
414455 for _ , op := range ops {
415456 e := op .Op .GetExec ()
416457 if e == nil || op .OpMetadata .ProgressGroup .Name != "Install base image packages" {
417458 continue
418459 }
419460
461+ execOpFound = true
462+
420463 for _ , mount := range e .Mounts {
421464 if mount .Dest == "/var/cache/apt" {
422465 aptCacheFound = true
@@ -438,6 +481,10 @@ func Test_Building_container(t *testing.T) {
438481 }
439482 }
440483
484+ if ! execOpFound {
485+ t .Fatalf ("Exec op for installing base packages not found" )
486+ }
487+
441488 if ! aptCacheFound {
442489 t .Fatalf ("Apt cache mount not found before installing base packages" )
443490 }
0 commit comments