@@ -220,6 +220,7 @@ var allTests = []func(t *testing.T, sb integration.Sandbox){
220220 testOCIIndexMediatype ,
221221 testLayerLimitOnMounts ,
222222 testFrontendVerifyPlatforms ,
223+ testRunValidExitCodes ,
223224}
224225
225226func TestIntegration (t * testing.T ) {
@@ -10588,3 +10589,47 @@ func testClientCustomGRPCOpts(t *testing.T, sb integration.Sandbox) {
1058810589
1058910590 require .Contains (t , interceptedMethods , "/moby.buildkit.v1.Control/Solve" )
1059010591}
10592+
10593+ func testRunValidExitCodes (t * testing.T , sb integration.Sandbox ) {
10594+ requiresLinux (t )
10595+ c , err := New (sb .Context (), sb .Address ())
10596+ require .NoError (t , err )
10597+ defer c .Close ()
10598+
10599+ // no exit codes specified, equivalent to [0]
10600+ out := llb .Image ("busybox:latest" )
10601+ out = out .Run (llb .Shlex (`sh -c "exit 0"` )).Root ()
10602+ out = out .Run (llb .Shlex (`sh -c "exit 1"` )).Root ()
10603+ def , err := out .Marshal (sb .Context ())
10604+ require .NoError (t , err )
10605+ _ , err = c .Solve (sb .Context (), def , SolveOpt {}, nil )
10606+ require .Error (t , err )
10607+ require .ErrorContains (t , err , "exit code: 1" )
10608+
10609+ // empty exit codes, equivalent to [0]
10610+ out = llb .Image ("busybox:latest" )
10611+ out = out .Run (llb .Shlex (`sh -c "exit 0"` ), llb .ValidExitCodes ()).Root ()
10612+ def , err = out .Marshal (sb .Context ())
10613+ require .NoError (t , err )
10614+ _ , err = c .Solve (sb .Context (), def , SolveOpt {}, nil )
10615+ require .NoError (t , err )
10616+
10617+ // if we expect non-zero, those non-zero codes should succeed
10618+ out = llb .Image ("busybox:latest" )
10619+ out = out .Run (llb .Shlex (`sh -c "exit 1"` ), llb .ValidExitCodes (1 )).Root ()
10620+ out = out .Run (llb .Shlex (`sh -c "exit 2"` ), llb .ValidExitCodes (2 , 3 )).Root ()
10621+ out = out .Run (llb .Shlex (`sh -c "exit 3"` ), llb .ValidExitCodes (2 , 3 )).Root ()
10622+ def , err = out .Marshal (sb .Context ())
10623+ require .NoError (t , err )
10624+ _ , err = c .Solve (sb .Context (), def , SolveOpt {}, nil )
10625+ require .NoError (t , err )
10626+
10627+ // if we expect non-zero, returning zero should fail
10628+ out = llb .Image ("busybox:latest" )
10629+ out = out .Run (llb .Shlex (`sh -c "exit 0"` ), llb .ValidExitCodes (1 )).Root ()
10630+ def , err = out .Marshal (sb .Context ())
10631+ require .NoError (t , err )
10632+ _ , err = c .Solve (sb .Context (), def , SolveOpt {}, nil )
10633+ require .Error (t , err )
10634+ require .ErrorContains (t , err , "exit code: 0" )
10635+ }
0 commit comments