Fix packer manager test on Windows

This commit is contained in:
Alexander Neumann 2017-01-25 17:51:34 +01:00
parent dceaae33ed
commit 8d6fdb7a3e

View file

@ -47,25 +47,19 @@ func randomID(rd io.Reader) restic.ID {
const maxBlobSize = 1 << 20 const maxBlobSize = 1 << 20
func saveFile(t testing.TB, be Saver, filename string, id restic.ID) { func saveFile(t testing.TB, be Saver, f *os.File, id restic.ID) {
f, err := os.Open(filename)
if err != nil {
t.Fatal(err)
}
h := restic.Handle{Type: restic.DataFile, Name: id.String()} h := restic.Handle{Type: restic.DataFile, Name: id.String()}
t.Logf("save file %v", h) t.Logf("save file %v", h)
if err = be.Save(h, f); err != nil { if err := be.Save(h, f); err != nil {
t.Fatal(err) t.Fatal(err)
} }
if err = f.Close(); err != nil { if err := f.Close(); err != nil {
t.Fatal(err) t.Fatal(err)
} }
err = os.Remove(filename) if err := os.Remove(f.Name()); err != nil {
if err != nil {
t.Fatal(err) t.Fatal(err)
} }
} }
@ -104,8 +98,12 @@ func fillPacks(t testing.TB, rnd *randReader, be Saver, pm *packerManager, buf [
t.Fatal(err) t.Fatal(err)
} }
if _, err = packer.tmpfile.Seek(0, 0); err != nil {
t.Fatal(err)
}
packID := restic.IDFromHash(packer.hw.Sum(nil)) packID := restic.IDFromHash(packer.hw.Sum(nil))
saveFile(t, be, packer.tmpfile.Name(), packID) saveFile(t, be, packer.tmpfile, packID)
} }
return bytes return bytes
@ -121,7 +119,7 @@ func flushRemainingPacks(t testing.TB, rnd *randReader, be Saver, pm *packerMana
bytes += int(n) bytes += int(n)
packID := restic.IDFromHash(packer.hw.Sum(nil)) packID := restic.IDFromHash(packer.hw.Sum(nil))
saveFile(t, be, packer.tmpfile.Name(), packID) saveFile(t, be, packer.tmpfile, packID)
} }
} }