Download this file
| 1 | //go:build linux |
| 2 | |
| 3 | package assetcache |
| 4 | |
| 5 | import ( |
| 6 | "path/filepath" |
| 7 | "testing" |
| 8 | ) |
| 9 | |
| 10 | // TestStatfsReportsTheTempDir is the acceptance test for the real FS: it asks |
| 11 | // the kernel about a real directory. |
| 12 | func TestStatfsReportsTheTempDir(t *testing.T) { |
| 13 | total, free, err := Statfs.Space(t.TempDir()) |
| 14 | if err != nil { |
| 15 | t.Fatal(err) |
| 16 | } |
| 17 | if total == 0 { |
| 18 | t.Fatal("total = 0, want the filesystem's size") |
| 19 | } |
| 20 | if free > total { |
| 21 | t.Fatalf("free %d > total %d", free, total) |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | // TestStatfsFailsOnAMissingDirectory asks the kernel about a directory that |
| 26 | // does not exist: the real FS returns the error and no totals. |
| 27 | func TestStatfsFailsOnAMissingDirectory(t *testing.T) { |
| 28 | total, free, err := Statfs.Space(filepath.Join(t.TempDir(), "missing")) |
| 29 | if err == nil { |
| 30 | t.Fatal("Space of a missing directory succeeded") |
| 31 | } |
| 32 | if total != 0 || free != 0 { |
| 33 | t.Fatalf("Space of a missing directory = %d, %d, want 0, 0 with the error", total, free) |
| 34 | } |
| 35 | } |
| 36 | |