| 1 | //go:build !windows |
| 2 | |
| 3 | package main |
| 4 | |
| 5 | import ( |
| 6 | "context" |
| 7 | "os" |
| 8 | "testing" |
| 9 | |
| 10 | "golang.org/x/sys/unix" |
| 11 | ) |
| 12 | |
| 13 | func TestWorkspaceTallyRejectsDirectoriesAndSpecialFiles(t *testing.T) { |
| 14 | base := t.TempDir() |
| 15 | root, err := os.OpenRoot(base) |
| 16 | if err != nil { |
| 17 | t.Fatal(err) |
| 18 | } |
| 19 | defer root.Close() |
| 20 | if err := root.Mkdir("dir", 0700); err != nil { |
| 21 | t.Fatal(err) |
| 22 | } |
| 23 | if err := root.WriteFile("dir/file", []byte("line\n"), 0600); err != nil { |
| 24 | t.Fatal(err) |
| 25 | } |
| 26 | if err := root.Symlink("dir", "linked-dir"); err != nil { |
| 27 | t.Fatal(err) |
| 28 | } |
| 29 | if f, err := openWorkspaceTallyFile(root, "linked-dir/file"); err == nil { |
| 30 | f.Close() |
| 31 | t.Fatal("platform open followed directory symlink") |
| 32 | } |
| 33 | if err := unix.Mkfifo(base+"/fifo", 0600); err != nil { |
| 34 | t.Fatal(err) |
| 35 | } |
| 36 | remaining := int64(100) |
| 37 | if count, partial := workspaceCountFileLines(context.Background(), root, "fifo", &remaining); count != 0 || !partial || remaining != 100 { |
| 38 | t.Fatal("read from a FIFO") |
| 39 | } |
| 40 | } |
| 41 |