@@ -35,10 +35,8 @@ import (
3535
3636func TestBuildJailedRootHandler_Isolated (t * testing.T ) {
3737 internal .RequiresIsolation (t )
38- dir , err := ioutil .TempDir ("" , "TestBuildJailedRootHandler" )
39- require .NoError (t , err , "failed to create temporary directory" )
38+ dir := t .TempDir ()
4039
41- defer os .RemoveAll (dir )
4240 kernelImagePath := filepath .Join (dir , "kernel-image" )
4341 kernelImageFd , err := os .OpenFile (kernelImagePath , os .O_CREATE , 0600 )
4442 require .NoError (t , err , "failed to create kernel image" )
@@ -107,12 +105,11 @@ func TestMkdirAllWithPermissions_Isolated(t *testing.T) {
107105 // requires isolation so we can change uid/gid of files
108106 internal .RequiresIsolation (t )
109107
110- tmpdir , err := ioutil .TempDir ("" , "TestMkdirAllWithPermissions" )
111- require .NoError (t , err , "failed to create temporary directory" )
108+ tmpdir := t .TempDir ()
112109
113110 existingPath := filepath .Join (tmpdir , "exists" )
114111 existingMode := os .FileMode (0700 )
115- err = os .Mkdir (existingPath , existingMode )
112+ err : = os .Mkdir (existingPath , existingMode )
116113 require .NoError (t , err , "failed to create existing part of test directory" )
117114
118115 nonExistingPath := filepath .Join (existingPath , "nonexistent" )
@@ -139,9 +136,7 @@ func TestBindMountToJail_Isolated(t *testing.T) {
139136 // The user must be root to call chown.
140137 internal .RequiresIsolation (t )
141138
142- dir , err := ioutil .TempDir ("" , t .Name ())
143- require .NoError (t , err )
144- defer os .RemoveAll (dir )
139+ dir := t .TempDir ()
145140
146141 f , err := os .Create (filepath .Join (dir , "src1" ))
147142 require .NoError (t , err )
@@ -196,13 +191,12 @@ func TestFifoHandler_Isolated(t *testing.T) {
196191 for _ , tc := range testcases {
197192 tc := tc
198193 t .Run (tc .name , func (t * testing.T ) {
199- dir , err := ioutil .TempDir ("" , testNameToVMID (t .Name ()))
200- require .NoError (t , err )
194+ dir := t .TempDir ()
201195
202196 logPath := filepath .Join (dir , tc .logPath )
203197 metricsPath := filepath .Join (dir , tc .metricsPath )
204198
205- err = os .MkdirAll (filepath .Dir (logPath ), 0750 )
199+ err : = os .MkdirAll (filepath .Dir (logPath ), 0750 )
206200 require .NoError (t , err )
207201 err = ioutil .WriteFile (logPath , []byte ("log" ), 0644 )
208202 require .NoError (t , err )
0 commit comments