Skip to content

Commit

Permalink
Merge pull request #25 from bkatrenko/migrate_diskchecker_to_sys/unix
Browse files Browse the repository at this point in the history
migrate diskchecker to sys/unix
  • Loading branch information
karthikmuralidharan authored Dec 24, 2019
2 parents 2b759a7 + 848990c commit dd3d2fd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
9 changes: 5 additions & 4 deletions checkers/diskspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,24 @@ import (
"context"
"fmt"
"os"
"syscall"

"github.com/etherlabsio/healthcheck"
"golang.org/x/sys/unix"
)

type diskspace struct {
dir string
threshold uint64
statfs func(string, *syscall.Statfs_t) error
statfs func(string, *unix.Statfs_t) error
}

//Check test if the filesystem disk usage is above threshold
func (ds *diskspace) Check(ctx context.Context) error {
if _, err := os.Stat(ds.dir); err != nil {
return fmt.Errorf("filesystem not found: %v", err)
}
fs := syscall.Statfs_t{}

fs := unix.Statfs_t{}
err := ds.statfs(ds.dir, &fs)
if err != nil {
return fmt.Errorf("error looking for %s filesystem stats: %v", ds.dir, err)
Expand All @@ -41,6 +42,6 @@ func DiskSpace(dir string, threshold uint64) healthcheck.Checker {
return &diskspace{
dir: dir,
threshold: threshold,
statfs: syscall.Statfs,
statfs: unix.Statfs,
}
}
5 changes: 3 additions & 2 deletions checkers/diskspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package checkers
import (
"context"
"fmt"
"syscall"
"testing"

"golang.org/x/sys/unix"
)

func Test_diskspace_Check(t *testing.T) {
Expand Down Expand Up @@ -54,7 +55,7 @@ func Test_diskspace_Check(t *testing.T) {
ds := &diskspace{
dir: tt.dir,
threshold: tt.threshold,
statfs: func(fs string, stat *syscall.Statfs_t) error {
statfs: func(fs string, stat *unix.Statfs_t) error {
stat.Bsize = 1
stat.Bfree = tt.freeBlocks
stat.Blocks = tt.totalBlocks
Expand Down

0 comments on commit dd3d2fd

Please sign in to comment.