tests: use internal bzip2/gzip implementation

This commit is contained in:
Alexander Neumann 2015-08-19 21:00:17 +02:00
parent 7079e46642
commit b8c0935f8a
1 changed files with 21 additions and 4 deletions

View File

@ -2,7 +2,10 @@ package test_helper
import (
"bytes"
"compress/bzip2"
"compress/gzip"
"fmt"
"io"
"io/ioutil"
"math/rand"
"os"
@ -89,14 +92,28 @@ func RandomReader(seed, size int) *bytes.Reader {
// SetupTarTestFixture extracts the tarFile to outputDir.
func SetupTarTestFixture(t testing.TB, outputDir, tarFile string) {
f, err := os.Open(tarFile)
defer f.Close()
input, err := os.Open(tarFile)
defer input.Close()
OK(t, err)
cmd := exec.Command("tar", "xzf", "-")
var rd io.Reader
switch filepath.Ext(tarFile) {
case ".gz":
r, err := gzip.NewReader(input)
OK(t, err)
defer r.Close()
rd = r
case ".bzip2":
rd = bzip2.NewReader(input)
default:
rd = input
}
cmd := exec.Command("tar", "xf", "-")
cmd.Dir = outputDir
cmd.Stdin = f
cmd.Stdin = rd
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr