2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-29 16:23:59 +00:00

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

View File

@ -2,7 +2,10 @@ package test_helper
import ( import (
"bytes" "bytes"
"compress/bzip2"
"compress/gzip"
"fmt" "fmt"
"io"
"io/ioutil" "io/ioutil"
"math/rand" "math/rand"
"os" "os"
@ -89,14 +92,28 @@ func RandomReader(seed, size int) *bytes.Reader {
// SetupTarTestFixture extracts the tarFile to outputDir. // SetupTarTestFixture extracts the tarFile to outputDir.
func SetupTarTestFixture(t testing.TB, outputDir, tarFile string) { func SetupTarTestFixture(t testing.TB, outputDir, tarFile string) {
f, err := os.Open(tarFile) input, err := os.Open(tarFile)
defer f.Close() defer input.Close()
OK(t, err) 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.Dir = outputDir
cmd.Stdin = f cmd.Stdin = rd
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr