Repository navigation
Expand file tree
/
Copy pathdisk_test.go
More file actions
63 lines (55 loc) · 1.74 KB
/
Copy pathdisk_test.go
File metadata and controls
63 lines (55 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package systats
import (
"testing"
"github.com/dhamith93/systats/internal/fileops"
)
func TestParseMounts(t *testing.T) {
content := fileops.ReadFile("./test_files/mounts.txt")
entries := parseMounts(content)
want := []mountEntry{
{device: "sysfs", mountPoint: "/sys", fsType: "sysfs"},
{device: "proc", mountPoint: "/proc", fsType: "proc"},
{device: "udev", mountPoint: "/dev", fsType: "devtmpfs"},
{device: "tmpfs", mountPoint: "/run", fsType: "tmpfs"},
{device: "/dev/sda2", mountPoint: "/", fsType: "ext4"},
{device: "/dev/sda1", mountPoint: "/boot/efi", fsType: "vfat"},
{device: "/dev/sdb1", mountPoint: "/mnt/My Backup Drive", fsType: "ext4"},
}
if len(entries) != len(want) {
t.Fatalf("got %d entries, want %d: %+v", len(entries), len(want), entries)
}
for i, e := range entries {
if e != want[i] {
t.Errorf("entry %d: got %+v, want %+v", i, e, want[i])
}
}
}
func TestUsagePercent(t *testing.T) {
cases := []struct {
used, avail uint64
want string
}{
{used: 50, avail: 50, want: "50%"},
{used: 1, avail: 99, want: "1%"},
{used: 1, avail: 999, want: "1%"},
{used: 999, avail: 1, want: "100%"},
{used: 1, avail: 2, want: "34%"}, // ceil(100/3) = 34, not truncated 33
{used: 0, avail: 0, want: "0%"},
}
for _, c := range cases {
got := usagePercent(c.used, c.avail)
if got != c.want {
t.Errorf("usagePercent(%d, %d) = %q, want %q", c.used, c.avail, got, c.want)
}
}
}
func TestExcludedFsTypesMatchesOldDfExcludeList(t *testing.T) {
for _, fsType := range []string{"tmpfs", "devtmpfs", "udev"} {
if !excludedFsTypes[fsType] {
t.Errorf("expected %q to be excluded (matches old df --exclude-type list)", fsType)
}
}
if excludedFsTypes["ext4"] {
t.Errorf("ext4 should not be excluded")
}
}