Files
restic/internal/fileio/file_windows_test.go
T
Michael Eischer 4d1b9cef63 internal/fileio: extract low-level file I/O from internal/fs
Move TempFile and PreallocateFile into internal/fileio. internal/fs
primarily focuses on converting between data.Node and the actual
filesystem state. Extract the two methods to not pull in unnecessary
dependencies.
2026-06-20 17:48:35 +02:00

36 lines
796 B
Go

package fileio_test
import (
"errors"
"os"
"testing"
"github.com/restic/restic/internal/fileio"
rtest "github.com/restic/restic/internal/test"
)
func TestTempFile(t *testing.T) {
// create two temp files at the same time to check that the
// collision avoidance works
f, err := fileio.TempFile("", "test")
fn := f.Name()
rtest.OK(t, err)
f2, err := fileio.TempFile("", "test")
fn2 := f2.Name()
rtest.OK(t, err)
rtest.Assert(t, fn != fn2, "filenames don't differ %s", fn)
_, err = os.Stat(fn)
rtest.OK(t, err)
_, err = os.Stat(fn2)
rtest.OK(t, err)
rtest.OK(t, f.Close())
rtest.OK(t, f2.Close())
_, err = os.Stat(fn)
rtest.Assert(t, errors.Is(err, os.ErrNotExist), "err %s", err)
_, err = os.Stat(fn2)
rtest.Assert(t, errors.Is(err, os.ErrNotExist), "err %s", err)
}