MemFSTest.Statfs
parent
ee4f4770b6
commit
284ddf44b0
|
@ -28,6 +28,12 @@ import (
|
|||
"github.com/jacobsa/syncutil"
|
||||
)
|
||||
|
||||
// The capacities of the file system, as reported to statfs(2).
|
||||
const (
|
||||
Capacity_Bytes = 1 << 50
|
||||
Capacity_Files = 1 << 30
|
||||
)
|
||||
|
||||
type memFS struct {
|
||||
fuseutil.NotImplementedFileSystem
|
||||
|
||||
|
|
|
@ -1614,3 +1614,27 @@ func (t *MemFSTest) RenameNonExistentFile() {
|
|||
err = os.Rename(path.Join(t.Dir, "foo"), path.Join(t.Dir, "bar"))
|
||||
ExpectThat(err, Error(HasSubstr("no such file")))
|
||||
}
|
||||
|
||||
func (t *MemFSTest) Statfs() {
|
||||
var err error
|
||||
var stat syscall.Statfs_t
|
||||
|
||||
// Write a few bytes of file content.
|
||||
const content = "taco"
|
||||
|
||||
err = ioutil.WriteFile(path.Join(t.Dir, "foo"), []byte(content), 0400)
|
||||
AssertEq(nil, err)
|
||||
|
||||
// Stat the file system.
|
||||
err = syscall.Statfs(t.Dir, &stat)
|
||||
AssertEq(nil, err)
|
||||
|
||||
ExpectEq(1, stat.Bsize)
|
||||
|
||||
ExpectEq(memfs.Capacity_Bytes, stat.Blocks)
|
||||
ExpectEq(memfs.Capacity_Bytes-len(content), stat.Bfree)
|
||||
ExpectEq(stat.Bfree, stat.Bavail)
|
||||
|
||||
ExpectEq(memfs.Capacity_Files, stat.Files)
|
||||
ExpectEq(memfs.Capacity_Files-2, stat.Ffree)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue