@@ -194,7 +194,8 @@ func nerdctlSetup(testCase *test.Case, t *testing.T) test.Command {
194194			testCase .Env ["DOCKER_CONFIG" ] =  testCase .Data .TempDir ()
195195			testCase .Env ["NERDCTL_TOML" ] =  filepath .Join (testCase .Data .TempDir (), "nerdctl.toml" )
196196			dt .WithConfig (HostsDir , test .ConfigValue (testCase .Data .TempDir ()))
197- 			dt .WithConfig (DataRoot , test .ConfigValue (testCase .Data .TempDir ()))
197+ 			// Setting data root is more trouble than anything and does not significantly increase isolation 
198+ 			// dt.WithConfig(DataRoot, test.ConfigValue(testCase.Data.TempDir())) 
198199		}
199200		testUtilBase  =  testutil .NewBaseWithNamespace (t , pvNamespace )
200201		if  testUtilBase .Target  ==  testutil .Docker  {
@@ -237,12 +238,28 @@ func nerdctlSetup(testCase *test.Case, t *testing.T) test.Command {
237238	}
238239
239240	// If we were in a custom namespace, not inherited - make sure we clean up the namespace 
240- 	// FIXME: this is broken, and custom namespaces are not cleaned properly 
241241	if  testUtilBase .Target  ==  testutil .Nerdctl  &&  pvNamespace  !=  ""  &&  ! inherited  {
242242		cleanup  :=  func () {
243- 			cl  :=  baseCommand .Clone ()
244- 			cl .WithArgs ("namespace" , "remove" , pvNamespace )
245- 			cl .Run (nil )
243+ 			// Stop all containers, then prune everything 
244+ 			containerList  :=  baseCommand .Clone ()
245+ 			containerList .WithArgs ("ps" , "-q" )
246+ 			containerList .Run (& test.Expected {
247+ 				Output : func (stdout  string , info  string , t  * testing.T ) {
248+ 					if  stdout  !=  ""  {
249+ 						containerRm  :=  baseCommand .Clone ()
250+ 						containerRm .WithArgs ("rm" , "-f" , stdout )
251+ 						containerRm .Run (& test.Expected {})
252+ 					}
253+ 				},
254+ 			})
255+ 
256+ 			systemPrune  :=  baseCommand .Clone ()
257+ 			systemPrune .WithArgs ("system" , "prune" , "-f" , "--all" , "--volumes" )
258+ 			systemPrune .Run (& test.Expected {})
259+ 
260+ 			cleanNamespace  :=  baseCommand .Clone ()
261+ 			cleanNamespace .WithArgs ("namespace" , "remove" , pvNamespace )
262+ 			cleanNamespace .Run (nil )
246263		}
247264		cleanup ()
248265		t .Cleanup (cleanup )
0 commit comments