(t *testing.T)
| 151 | } |
| 152 | |
| 153 | func TestCheckSocketDirWritable(t *testing.T) { |
| 154 | // Happy path: writable directory |
| 155 | tmpDir := t.TempDir() |
| 156 | // Unix socket paths have a max length (~104 bytes on macOS). t.TempDir() |
| 157 | // paths can be very long, so use a short filename for the check. |
| 158 | if err := checkSocketDirWritable(tmpDir); err != nil { |
| 159 | // If t.TempDir is still too long, fallback to /tmp |
| 160 | if strings.Contains(err.Error(), "invalid argument") || strings.Contains(err.Error(), "too long") { |
| 161 | shortDir, err2 := os.MkdirTemp("/tmp", "dg-test-*") |
| 162 | if err2 == nil { |
| 163 | defer func() { _ = os.RemoveAll(shortDir) }() |
| 164 | if err3 := checkSocketDirWritable(shortDir); err3 != nil { |
| 165 | t.Fatalf("expected short directory %s to be writable: %v", shortDir, err3) |
| 166 | } |
| 167 | return |
| 168 | } |
| 169 | } |
| 170 | t.Fatalf("expected directory %s to be writable: %v", tmpDir, err) |
| 171 | } |
| 172 | |
| 173 | // Failure path: non-existent directory |
| 174 | if err := checkSocketDirWritable("/non/existent/path/for/duckgres/test"); err == nil { |
| 175 | t.Fatalf("expected error for non-existent directory") |
| 176 | } |
| 177 | |
| 178 | // Failure path: read-only directory (if we can create one) |
| 179 | roDir := t.TempDir() |
| 180 | if err := os.Chmod(roDir, 0555); err != nil { |
| 181 | t.Fatalf("failed to chmod directory to read-only: %v", err) |
| 182 | } |
| 183 | defer func() { _ = os.Chmod(roDir, 0755) }() // Restore for cleanup |
| 184 | |
| 185 | if err := checkSocketDirWritable(roDir); err == nil { |
| 186 | t.Fatalf("expected error for read-only directory") |
| 187 | } |
| 188 | } |
nothing calls this directly
no test coverage detected