| 1 | package thin |
| 2 | |
| 3 | import ( |
| 4 | "path/filepath" |
| 5 | "strings" |
| 6 | "testing" |
| 7 | |
| 8 | "amadan.net/oficina/equipo/internal/runner" |
| 9 | "amadan.net/oficina/equipo/internal/runner/provider" |
| 10 | ) |
| 11 | |
| 12 | // A Mac has no /proc/self/fd to bind a socket through, so a step's tool |
| 13 | // socket path itself must fit sun_path (104 bytes with its NUL). It goes |
| 14 | // under the scratch root's short t/, in a directory named only by |
| 15 | // MkdirTemp's random number, as s: for a runner user whose home is as |
| 16 | // long as macToolHomeName allows, the longest path still fits. The roots |
| 17 | // are install_mac.go's (~/.local/share/equipo-runner). |
| 18 | func TestToolSocketPathFits(t *testing.T) { |
| 19 | cfg := func(name string) runner.Config { |
| 20 | share := filepath.Join("/Users", name, ".local", "share", "equipo-runner") |
| 21 | return runner.Config{StateDir: filepath.Join(share, "state"), ScratchRoot: filepath.Join(share, "scratch"), WorkspaceRoot: filepath.Join(share, "work")} |
| 22 | } |
| 23 | for _, name := range []string{"paulequipo", strings.Repeat("n", 32), strings.Repeat("n", macToolHomeName)} { |
| 24 | c := cfg(name) |
| 25 | root := macToolRoot(c) |
| 26 | if root != filepath.Join(c.ScratchRoot, "t") { |
| 27 | t.Fatalf("a Mac's tool sockets are under %s, not the scratch root's t/", root) |
| 28 | } |
| 29 | if got := macToolSocketLongest(root); len(got) > provider.MaxDarwinSocketPath { |
| 30 | t.Fatalf("home of %d bytes: %s is %d bytes", len(name), got, len(got)) |
| 31 | } |
| 32 | } |
| 33 | // One byte more no longer fits, and is refused, never cut short. |
| 34 | if got := macToolSocketLongest(macToolRoot(cfg(strings.Repeat("n", macToolHomeName+1)))); len(got) <= provider.MaxDarwinSocketPath { |
| 35 | t.Fatalf("macToolHomeName is not the longest name that fits: %s", got) |
| 36 | } |
| 37 | // The state directory, where Linux puts them, would not fit a long |
| 38 | // name with the Linux names. |
| 39 | if long := filepath.Join(cfg(strings.Repeat("n", 32)).StateDir, "coord-tool-4294967295", "equipo.sock"); len(long) <= provider.MaxDarwinSocketPath { |
| 40 | t.Fatalf("the Linux layout fits after all: %s", long) |
| 41 | } |
| 42 | } |
| 43 | |