forked from TrueCloudLab/restic
Add simple test for fs.TempFile on windows
This commit is contained in:
parent
9a3f1a9703
commit
4077a81b34
1 changed files with 35 additions and 0 deletions
35
internal/fs/file_windows_test.go
Normal file
35
internal/fs/file_windows_test.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
package fs_test
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/restic/restic/internal/fs"
|
||||
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 := fs.TempFile("", "test")
|
||||
fn := f.Name()
|
||||
rtest.OK(t, err)
|
||||
f2, err := fs.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)
|
||||
}
|
Loading…
Reference in a new issue