Fixed StatFSTest.CapacityAndFreeSpace on Linux.
parent
ca114f296a
commit
be680e1860
|
@ -16,6 +16,7 @@ package statfs_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"regexp"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/jacobsa/fuse/fuseops"
|
"github.com/jacobsa/fuse/fuseops"
|
||||||
|
@ -23,6 +24,13 @@ import (
|
||||||
. "github.com/jacobsa/ogletest"
|
. "github.com/jacobsa/ogletest"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Sample output:
|
||||||
|
//
|
||||||
|
// Filesystem 1024-blocks Used Available Capacity iused ifree %iused Mounted on
|
||||||
|
// fake@bucket 32 16 16 50% 0 0 100% /Users/jacobsa/tmp/mp
|
||||||
|
//
|
||||||
|
var gDfOutputRegexp = regexp.MustCompile(`^\S+\s+(\d+)\s+(\d+)\s+(\d+)\s+\d+%\s+\d+\s+\d+\s+\d+%.*$`)
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
// Helpers
|
// Helpers
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -17,12 +17,20 @@ package statfs_test
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
|
"regexp"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/jacobsa/fuse/fuseops"
|
"github.com/jacobsa/fuse/fuseops"
|
||||||
. "github.com/jacobsa/ogletest"
|
. "github.com/jacobsa/ogletest"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Sample output:
|
||||||
|
//
|
||||||
|
// Filesystem 1K-blocks Used Available Use% Mounted on
|
||||||
|
// some_fuse_file_system 512 64 384 15% /tmp/sample_test001288095
|
||||||
|
//
|
||||||
|
var gDfOutputRegexp = regexp.MustCompile(`^\S+\s+(\d+)\s+(\d+)\s+(\d+)\s+\d+%.*$`)
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
// Tests
|
// Tests
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -21,7 +21,6 @@ import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -44,13 +43,6 @@ func TestStatFS(t *testing.T) { RunTests(t) }
|
||||||
// system's. The output is not guaranteed to have resolution greater than 2^10
|
// system's. The output is not guaranteed to have resolution greater than 2^10
|
||||||
// (1 KiB).
|
// (1 KiB).
|
||||||
func df(dir string) (capacity, used, available uint64, err error) {
|
func df(dir string) (capacity, used, available uint64, err error) {
|
||||||
// Sample output:
|
|
||||||
//
|
|
||||||
// Filesystem 1024-blocks Used Available Capacity iused ifree %iused Mounted on
|
|
||||||
// fake@bucket 32 16 16 50% 0 0 100% /Users/jacobsa/tmp/mp
|
|
||||||
//
|
|
||||||
re := regexp.MustCompile(`^\S+\s+(\d+)\s+(\d+)\s+(\d+)\s+\d+%\s+\d+\s+\d+\s+\d+%.*$`)
|
|
||||||
|
|
||||||
// Call df with a block size of 1024 and capture its output.
|
// Call df with a block size of 1024 and capture its output.
|
||||||
cmd := exec.Command("df", dir)
|
cmd := exec.Command("df", dir)
|
||||||
cmd.Env = []string{"BLOCKSIZE=1024"}
|
cmd.Env = []string{"BLOCKSIZE=1024"}
|
||||||
|
@ -67,7 +59,7 @@ func df(dir string) (capacity, used, available uint64, err error) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
submatches := re.FindSubmatch(line)
|
submatches := gDfOutputRegexp.FindSubmatch(line)
|
||||||
if submatches == nil {
|
if submatches == nil {
|
||||||
err = fmt.Errorf("Unable to parse line: %q", line)
|
err = fmt.Errorf("Unable to parse line: %q", line)
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue