@@ -131,6 +131,31 @@ func TestBuildahCli_Build(t *testing.T) {
131131 g .Expect (capturedArgs ).To (ContainElement ("--volume=/host/dir2:/container/dir2:ro" ))
132132 })
133133
134+ t .Run ("should turn BuildArgs(File) into --build-arg(-file) params" , func (t * testing.T ) {
135+ buildahCli , executor := setupBuildahCli ()
136+ var capturedArgs []string
137+ executor .executeWithOutput = func (command string , args ... string ) (string , string , int , error ) {
138+ g .Expect (command ).To (Equal ("buildah" ))
139+ capturedArgs = args
140+ return "" , "" , 0 , nil
141+ }
142+
143+ buildArgs := & cliwrappers.BuildahBuildArgs {
144+ Containerfile : containerfile ,
145+ ContextDir : contextDir ,
146+ OutputRef : outputRef ,
147+ BuildArgs : []string {"VERSION=1.0.0" , "BUILD_DATE=2024-01-01" },
148+ BuildArgsFile : "/path/to/build-args-file" ,
149+ }
150+
151+ err := buildahCli .Build (buildArgs )
152+ g .Expect (err ).ToNot (HaveOccurred ())
153+
154+ g .Expect (capturedArgs ).To (ContainElement ("--build-arg=VERSION=1.0.0" ))
155+ g .Expect (capturedArgs ).To (ContainElement ("--build-arg=BUILD_DATE=2024-01-01" ))
156+ g .Expect (capturedArgs ).To (ContainElement ("--build-arg-file=/path/to/build-args-file" ))
157+ })
158+
134159 t .Run ("should append extra args before context directory" , func (t * testing.T ) {
135160 buildahCli , executor := setupBuildahCli ()
136161 var capturedArgs []string
@@ -309,6 +334,7 @@ func TestBuildahBuildArgs_MakePathsAbsolute(t *testing.T) {
309334 Volumes : []cliwrappers.BuildahVolume {
310335 {HostDir : "/absolute/path/volume" , ContainerDir : "/container/dir" , Options : "" },
311336 },
337+ BuildArgsFile : "/absolute/path/build-args-file" ,
312338 }
313339
314340 err := args .MakePathsAbsolute ("/base/dir" )
@@ -317,6 +343,7 @@ func TestBuildahBuildArgs_MakePathsAbsolute(t *testing.T) {
317343 g .Expect (args .ContextDir ).To (Equal ("/absolute/path/context" ))
318344 g .Expect (args .Secrets [0 ].Src ).To (Equal ("/absolute/path/secret" ))
319345 g .Expect (args .Volumes [0 ].HostDir ).To (Equal ("/absolute/path/volume" ))
346+ g .Expect (args .BuildArgsFile ).To (Equal ("/absolute/path/build-args-file" ))
320347 })
321348
322349 t .Run ("should make relative paths absolute" , func (t * testing.T ) {
@@ -329,6 +356,7 @@ func TestBuildahBuildArgs_MakePathsAbsolute(t *testing.T) {
329356 Volumes : []cliwrappers.BuildahVolume {
330357 {HostDir : "relative/volume" , ContainerDir : "/container/dir" , Options : "" },
331358 },
359+ BuildArgsFile : "relative/build-args-file" ,
332360 }
333361
334362 err := args .MakePathsAbsolute ("/base/dir" )
@@ -337,6 +365,7 @@ func TestBuildahBuildArgs_MakePathsAbsolute(t *testing.T) {
337365 g .Expect (args .ContextDir ).To (Equal ("/base/dir" ))
338366 g .Expect (args .Secrets [0 ].Src ).To (Equal ("/base/dir/relative/secret" ))
339367 g .Expect (args .Volumes [0 ].HostDir ).To (Equal ("/base/dir/relative/volume" ))
368+ g .Expect (args .BuildArgsFile ).To (Equal ("/base/dir/relative/build-args-file" ))
340369 })
341370
342371 t .Run ("should handle a mix of relative and absolute paths" , func (t * testing.T ) {
@@ -378,6 +407,18 @@ func TestBuildahBuildArgs_MakePathsAbsolute(t *testing.T) {
378407 g .Expect (args .Containerfile ).To (Equal (filepath .Join (cwd , "Containerfile" )))
379408 g .Expect (args .ContextDir ).To (Equal (filepath .Join (cwd , "context" )))
380409 })
410+
411+ t .Run ("should not modify empty BuildArgsFile" , func (t * testing.T ) {
412+ args := & cliwrappers.BuildahBuildArgs {
413+ Containerfile : "/absolute/path/Containerfile" ,
414+ ContextDir : "/absolute/path/context" ,
415+ BuildArgsFile : "" ,
416+ }
417+
418+ err := args .MakePathsAbsolute ("/base/dir" )
419+ g .Expect (err ).ToNot (HaveOccurred ())
420+ g .Expect (args .BuildArgsFile ).To (Equal ("" ))
421+ })
381422}
382423
383424func TestBuildahBuildArgs_Validate (t * testing.T ) {
0 commit comments