Remove io.Writer from fs.File
It was only used in a single test, which now uses plain *os.File instead.
This commit is contained in:
parent
9abef3bf1a
commit
1b20f6beec
4 changed files with 32 additions and 41 deletions
|
@ -252,10 +252,6 @@ func (f fakeFile) Seek(int64, int) (int64, error) {
|
|||
return 0, os.ErrInvalid
|
||||
}
|
||||
|
||||
func (f fakeFile) Write(p []byte) (int, error) {
|
||||
return 0, os.ErrInvalid
|
||||
}
|
||||
|
||||
func (f fakeFile) Read(p []byte) (int, error) {
|
||||
return 0, os.ErrInvalid
|
||||
}
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
package fs
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
import "os"
|
||||
|
||||
// IsRegularFile returns true if fi belongs to a normal file. If fi is nil,
|
||||
// false is returned.
|
||||
|
@ -15,22 +11,3 @@ func IsRegularFile(fi os.FileInfo) bool {
|
|||
|
||||
return fi.Mode()&(os.ModeType|os.ModeCharDevice) == 0
|
||||
}
|
||||
|
||||
// TestTempFile returns a new temporary file, which is removed when cleanup()
|
||||
// is called.
|
||||
func TestTempFile(t testing.TB, prefix string) (File, func()) {
|
||||
f, err := ioutil.TempFile("", prefix)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
cleanup := func() {
|
||||
_ = f.Close()
|
||||
err = Remove(f.Name())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
return f, cleanup
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@ type FS interface {
|
|||
// File is an open file on a file system.
|
||||
type File interface {
|
||||
io.Reader
|
||||
io.Writer
|
||||
io.Closer
|
||||
|
||||
Fd() uintptr
|
||||
|
|
|
@ -3,25 +3,44 @@ package textfile
|
|||
import (
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/restic/restic/internal/fs"
|
||||
)
|
||||
|
||||
func writeTempfile(t testing.TB, data []byte) (fs.File, func()) {
|
||||
f, removeTempfile := fs.TestTempFile(t, "restic-test-textfile-read-")
|
||||
// writeTempfile writes data to a new temporary file and returns its name
|
||||
// and a callback that removes it.
|
||||
func writeTempfile(t testing.TB, data []byte) (string, func()) {
|
||||
t.Helper()
|
||||
|
||||
_, err := f.Write(data)
|
||||
f, err := ioutil.TempFile("", "restic-test-textfile-read-")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
name := f.Name()
|
||||
|
||||
defer func() {
|
||||
closeErr := f.Close()
|
||||
if err == nil && closeErr != nil {
|
||||
err = closeErr
|
||||
}
|
||||
if err != nil {
|
||||
os.Remove(name)
|
||||
t.Fatal(err)
|
||||
}
|
||||
}()
|
||||
|
||||
_, err = f.Write(data)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = f.Close()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return name, func() {
|
||||
err := os.Remove(name)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
return f, removeTempfile
|
||||
}
|
||||
|
||||
func dec(s string) []byte {
|
||||
|
@ -60,10 +79,10 @@ func TestRead(t *testing.T) {
|
|||
want = test.data
|
||||
}
|
||||
|
||||
f, cleanup := writeTempfile(t, test.data)
|
||||
tempname, cleanup := writeTempfile(t, test.data)
|
||||
defer cleanup()
|
||||
|
||||
data, err := Read(f.Name())
|
||||
data, err := Read(tempname)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue