| 1 | package diskusage |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | ) |
| 6 | |
| 7 | func TestUsageTempDir(t *testing.T) { |
| 8 | info, err := Usage(t.TempDir()) |
| 9 | if err != nil { |
| 10 | t.Fatal(err) |
| 11 | } |
| 12 | if info.Total == 0 || info.Free > info.Total { |
| 13 | t.Fatalf("ruimte free=%d total=%d reserved=%d", info.Free, info.Total, info.Reserved) |
| 14 | } |
| 15 | if info.Used()+info.Free+info.Reserved != info.Total { |
| 16 | t.Fatalf("used %d + free %d + reserved %d != total %d", info.Used(), info.Free, info.Reserved, info.Total) |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | func TestUsedClamps(t *testing.T) { |
| 21 | if (Info{Free: 30, Total: 10}).Used() != 0 { |
| 22 | t.Fatal("overvol") |
| 23 | } |
| 24 | if (Info{Free: 4, Reserved: 1, Total: 10}).Used() != 5 { |
| 25 | t.Fatal("reserved") |
| 26 | } |
| 27 | } |