5
5
"context"
6
6
"fmt"
7
7
"io"
8
- "io/ioutil"
9
8
"net/http"
10
9
"os"
11
10
"path/filepath"
@@ -187,9 +186,9 @@ func TestArchiveFailure(t *testing.T) {
187
186
188
187
func TestExtract (t * testing.T ) {
189
188
for _ , test := range ExtractCases {
190
- dir , _ := ioutil . TempDir ("" , "" )
189
+ dir , _ := os . MkdirTemp ("" , "" )
191
190
dir = filepath .Join (dir , "test" )
192
- data , err := ioutil .ReadFile (test .Archive )
191
+ data , err := os .ReadFile (test .Archive )
193
192
if err != nil {
194
193
t .Fatal (err )
195
194
}
@@ -222,8 +221,8 @@ func TestExtract(t *testing.T) {
222
221
}
223
222
224
223
func 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" )
227
226
228
227
b .StartTimer ()
229
228
@@ -244,8 +243,8 @@ func BenchmarkArchive(b *testing.B) {
244
243
}
245
244
246
245
func 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" )
249
248
250
249
b .StartTimer ()
251
250
@@ -266,8 +265,8 @@ func BenchmarkTarBz2(b *testing.B) {
266
265
}
267
266
268
267
func 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" )
271
270
272
271
b .StartTimer ()
273
272
@@ -288,8 +287,8 @@ func BenchmarkTarGz(b *testing.B) {
288
287
}
289
288
290
289
func 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" )
293
292
294
293
b .StartTimer ()
295
294
@@ -319,7 +318,7 @@ func testWalk(t *testing.T, dir string, testFiles Files) {
319
318
} else if info .Mode ()& os .ModeSymlink != 0 {
320
319
files [path ] = "link"
321
320
} else {
322
- data , err := ioutil .ReadFile (filepath .Join (dir , path ))
321
+ data , err := os .ReadFile (filepath .Join (dir , path ))
323
322
require .NoError (t , err )
324
323
files [path ] = strings .TrimSpace (string (data ))
325
324
}
@@ -370,7 +369,7 @@ func TestTarGzMemoryConsumption(t *testing.T) {
370
369
runtime .GC ()
371
370
runtime .ReadMemStats (& m )
372
371
373
- err = extract .Gz (context .Background (), f , tmpDir .String (), nil )
372
+ err = extract .Archive (context .Background (), f , tmpDir .String (), nil )
374
373
require .NoError (t , err )
375
374
376
375
runtime .ReadMemStats (& m2 )
@@ -398,7 +397,7 @@ func TestZipMemoryConsumption(t *testing.T) {
398
397
runtime .GC ()
399
398
runtime .ReadMemStats (& m )
400
399
401
- err = extract .Zip (context .Background (), f , tmpDir .String (), nil )
400
+ err = extract .Archive (context .Background (), f , tmpDir .String (), nil )
402
401
require .NoError (t , err )
403
402
404
403
runtime .ReadMemStats (& m2 )
@@ -407,9 +406,7 @@ func TestZipMemoryConsumption(t *testing.T) {
407
406
heapUsed = 0
408
407
}
409
408
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 )
413
410
}
414
411
415
412
func download (t require.TestingT , url string , file * paths.Path ) error {
0 commit comments