提交 e1e9f80b 编写于 作者: W WAKAYAMA Shirou

add Inode test and go fmt

上级 c7ffdfa3
......@@ -5,14 +5,14 @@ import (
)
type DiskUsageStat struct {
Path string `json:"path"`
Total uint64 `json:"total"`
Free uint64 `json:"free"`
Used uint64 `json:"used"`
UsedPercent float64 `json:"usedPercent"`
InodesTotal uint64 `json:"inodesTotal"`
InodesUsed uint64 `json:"inodesUsed"`
InodesFree uint64 `json:"inodesFree"`
Path string `json:"path"`
Total uint64 `json:"total"`
Free uint64 `json:"free"`
Used uint64 `json:"used"`
UsedPercent float64 `json:"usedPercent"`
InodesTotal uint64 `json:"inodesTotal"`
InodesUsed uint64 `json:"inodesUsed"`
InodesFree uint64 `json:"inodesFree"`
InodesUsedPercent float64 `json:"inodesUsedPercent"`
}
......
......@@ -48,13 +48,17 @@ func TestDisk_io_counters(t *testing.T) {
func TestDiskUsageStat_String(t *testing.T) {
v := DiskUsageStat{
Path: "/",
Total: 1000,
Free: 2000,
Used: 3000,
UsedPercent: 50.1,
Path: "/",
Total: 1000,
Free: 2000,
Used: 3000,
UsedPercent: 50.1,
InodesTotal: 4000,
InodesUsed: 5000,
InodesFree: 6000,
InodesUsedPercent: 49.1,
}
e := `{"path":"/","total":1000,"free":2000,"used":3000,"usedPercent":50.1}`
e := `{"path":"/","total":1000,"free":2000,"used":3000,"usedPercent":50.1,"inodesTotal":4000,"inodesUsed":5000,"inodesFree":6000,"inodesUsedPercent":49.1}`
if e != fmt.Sprintf("%v", v) {
t.Errorf("DiskUsageStat string is invalid: %v", v)
}
......
......@@ -14,11 +14,11 @@ func DiskUsage(path string) (*DiskUsageStat, error) {
bsize := stat.Bsize / 512
ret := &DiskUsageStat{
Path: path,
Total: (uint64(stat.Blocks) * uint64(bsize)) >> 1,
Free: (uint64(stat.Bfree) * uint64(bsize)) >> 1,
Path: path,
Total: (uint64(stat.Blocks) * uint64(bsize)) >> 1,
Free: (uint64(stat.Bfree) * uint64(bsize)) >> 1,
InodesTotal: (uint64(stat.Files)),
InodesFree: (uint64(stat.Ffree)),
InodesFree: (uint64(stat.Ffree)),
}
ret.InodesUsed = (ret.InodesTotal - ret.InodesFree)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册