55 "context"
66 "fmt"
77 "io"
8- "io/ioutil"
98 "net/http"
109 "os"
1110 "path/filepath"
@@ -187,9 +186,9 @@ func TestArchiveFailure(t *testing.T) {
187186
188187func TestExtract (t * testing.T ) {
189188 for _ , test := range ExtractCases {
190- dir , _ := ioutil . TempDir ("" , "" )
189+ dir , _ := os . MkdirTemp ("" , "" )
191190 dir = filepath .Join (dir , "test" )
192- data , err := ioutil .ReadFile (test .Archive )
191+ data , err := os .ReadFile (test .Archive )
193192 if err != nil {
194193 t .Fatal (err )
195194 }
@@ -222,8 +221,8 @@ func TestExtract(t *testing.T) {
222221}
223222
224223func BenchmarkArchive (b * testing.B ) {
225- dir , _ := ioutil . TempDir ("" , "" )
226- data , _ := ioutil .ReadFile ("testdata/archive.tar.bz2" )
224+ dir , _ := os . MkdirTemp ("" , "" )
225+ data , _ := os .ReadFile ("testdata/archive.tar.bz2" )
227226
228227 b .StartTimer ()
229228
@@ -244,8 +243,8 @@ func BenchmarkArchive(b *testing.B) {
244243}
245244
246245func BenchmarkTarBz2 (b * testing.B ) {
247- dir , _ := ioutil . TempDir ("" , "" )
248- data , _ := ioutil .ReadFile ("testdata/archive.tar.bz2" )
246+ dir , _ := os . MkdirTemp ("" , "" )
247+ data , _ := os .ReadFile ("testdata/archive.tar.bz2" )
249248
250249 b .StartTimer ()
251250
@@ -266,8 +265,8 @@ func BenchmarkTarBz2(b *testing.B) {
266265}
267266
268267func BenchmarkTarGz (b * testing.B ) {
269- dir , _ := ioutil . TempDir ("" , "" )
270- data , _ := ioutil .ReadFile ("testdata/archive.tar.gz" )
268+ dir , _ := os . MkdirTemp ("" , "" )
269+ data , _ := os .ReadFile ("testdata/archive.tar.gz" )
271270
272271 b .StartTimer ()
273272
@@ -288,8 +287,8 @@ func BenchmarkTarGz(b *testing.B) {
288287}
289288
290289func BenchmarkZip (b * testing.B ) {
291- dir , _ := ioutil . TempDir ("" , "" )
292- data , _ := ioutil .ReadFile ("testdata/archive.zip" )
290+ dir , _ := os . MkdirTemp ("" , "" )
291+ data , _ := os .ReadFile ("testdata/archive.zip" )
293292
294293 b .StartTimer ()
295294
@@ -319,7 +318,7 @@ func testWalk(t *testing.T, dir string, testFiles Files) {
319318 } else if info .Mode ()& os .ModeSymlink != 0 {
320319 files [path ] = "link"
321320 } else {
322- data , err := ioutil .ReadFile (filepath .Join (dir , path ))
321+ data , err := os .ReadFile (filepath .Join (dir , path ))
323322 require .NoError (t , err )
324323 files [path ] = strings .TrimSpace (string (data ))
325324 }
@@ -370,7 +369,7 @@ func TestTarGzMemoryConsumption(t *testing.T) {
370369 runtime .GC ()
371370 runtime .ReadMemStats (& m )
372371
373- err = extract .Gz (context .Background (), f , tmpDir .String (), nil )
372+ err = extract .Archive (context .Background (), f , tmpDir .String (), nil )
374373 require .NoError (t , err )
375374
376375 runtime .ReadMemStats (& m2 )
@@ -398,7 +397,7 @@ func TestZipMemoryConsumption(t *testing.T) {
398397 runtime .GC ()
399398 runtime .ReadMemStats (& m )
400399
401- err = extract .Zip (context .Background (), f , tmpDir .String (), nil )
400+ err = extract .Archive (context .Background (), f , tmpDir .String (), nil )
402401 require .NoError (t , err )
403402
404403 runtime .ReadMemStats (& m2 )
@@ -407,9 +406,7 @@ func TestZipMemoryConsumption(t *testing.T) {
407406 heapUsed = 0
408407 }
409408 fmt .Println ("Heap memory used during the test:" , heapUsed )
410- // the .zip file require random access, so the full io.Reader content must be cached, since
411- // the test file is 130MB, that's the reason for the high memory consumed.
412- require .True (t , heapUsed < 250000000 , "heap consumption should be less than 250M but is %d" , heapUsed )
409+ require .True (t , heapUsed < 10000000 , "heap consumption should be less than 10M but is %d" , heapUsed )
413410}
414411
415412func download (t require.TestingT , url string , file * paths.Path ) error {
0 commit comments