@@ -64,6 +64,7 @@ func TestRunnerDefaults(t *testing.T) {
6464 assert .False (t , runner .HasNoPreClean ())
6565 assert .Empty (t , runner .BaseDir ())
6666 assert .Empty (t , runner .RootDir ())
67+ assert .Empty (t , runner .ConfigOpts ())
6768}
6869
6970func TestClone (t * testing.T ) {
@@ -83,6 +84,7 @@ func TestClone(t *testing.T) {
8384 runner .WithRootDir (testRootDir )
8485 runner .WithNoPreClean ()
8586 runner .EnableNetwork ()
87+ runner .WithConfigOpts (map [string ]string {"cleanup_on_success" : "True" , "cleanup_on_failure" : "False" })
8688
8789 clone := runner .Clone ()
8890
@@ -93,6 +95,7 @@ func TestClone(t *testing.T) {
9395 assert .True (t , clone .HasNoPreClean ())
9496 assert .Equal (t , testBaseDir , clone .BaseDir ())
9597 assert .Equal (t , testRootDir , clone .RootDir ())
98+ assert .Equal (t , map [string ]string {"cleanup_on_success" : "True" , "cleanup_on_failure" : "False" }, clone .ConfigOpts ())
9699}
97100
98101func TestGetRootPath (t * testing.T ) {
@@ -280,3 +283,49 @@ func TestCmdInChroot_EnableNetworking(t *testing.T) {
280283 // Look for enable-network arg.
281284 assert .Contains (t , cmd .GetArgs (), "--enable-network" )
282285}
286+
287+ func TestCmdInChroot_ConfigOpts (t * testing.T ) {
288+ ctx := newTestCtxWithMockPrereqsPresent ()
289+
290+ runner := mock .NewRunner (ctx , testMockConfigPath )
291+ runner .WithConfigOpts (map [string ]string {"cleanup_on_success" : "True" , "cleanup_on_failure" : "False" })
292+ assert .Equal (t , map [string ]string {"cleanup_on_success" : "True" , "cleanup_on_failure" : "False" }, runner .ConfigOpts ())
293+
294+ cmd , err := runner .CmdInChroot (ctx , []string {"arg" }, false /*interactive*/ )
295+ require .NoError (t , err )
296+ require .NotNil (t , cmd )
297+
298+ // Look for config-opts args (keys should be sorted deterministically).
299+ cmdArgs := cmd .GetArgs ()
300+ assert .Contains (t , cmdArgs , "--config-opts" )
301+ assert .Contains (t , cmdArgs , "cleanup_on_failure=False" )
302+ assert .Contains (t , cmdArgs , "cleanup_on_success=True" )
303+ }
304+
305+ func TestBuildRPM_WithConfigOpts (t * testing.T ) {
306+ ctx := newTestCtxWithMockPrereqsPresent ()
307+ executedCmds := []string {}
308+
309+ ctx .CmdFactory .RunHandler = func (cmd * exec.Cmd ) error {
310+ executedCmds = append (executedCmds , strings .Join (cmd .Args , " " ))
311+
312+ require .NoError (t , fileutils .WriteFile (ctx .FS (), testRPMPath , []byte {}, fileperms .PrivateFile ))
313+
314+ return nil
315+ }
316+
317+ runner := mock .NewRunner (ctx , testMockConfigPath )
318+ runner .WithConfigOpts (map [string ]string {"cleanup_on_success" : "True" })
319+
320+ mockOptions := mock.RPMBuildOptions {}
321+
322+ err := runner .BuildRPM (ctx , testSRPMPath , testOutputDirPath , mockOptions )
323+ require .NoError (t , err )
324+
325+ // Confirm that mock was invoked once.
326+ assert .Len (t , executedCmds , 1 )
327+
328+ // Confirm the config-opts flag was passed through.
329+ mockCmd := executedCmds [0 ]
330+ assert .Contains (t , mockCmd , "--config-opts cleanup_on_success=True" )
331+ }
0 commit comments