setupSocketServer creates an agentsocket server at a temporary path for testing. Returns the socket path and a cleanup function. The path should be passed to sync commands via the --socket-path flag.
(t *testing.T)
| 20 | // Returns the socket path and a cleanup function. The path should be passed to |
| 21 | // sync commands via the --socket-path flag. |
| 22 | func setupSocketServer(t *testing.T) (path string, cleanup func()) { |
| 23 | t.Helper() |
| 24 | |
| 25 | // Use a temporary socket path for each test |
| 26 | socketPath := testutil.AgentSocketPath(t) |
| 27 | |
| 28 | // Create parent directory if needed. Not necessary on Windows because named pipes live in an abstract namespace |
| 29 | // not tied to any real files. |
| 30 | if runtime.GOOS != "windows" { |
| 31 | parentDir := filepath.Dir(socketPath) |
| 32 | err := os.MkdirAll(parentDir, 0o700) |
| 33 | require.NoError(t, err, "create socket directory") |
| 34 | } |
| 35 | |
| 36 | server, err := agentsocket.NewServer( |
| 37 | slog.Make().Leveled(slog.LevelDebug), |
| 38 | agentsocket.WithPath(socketPath), |
| 39 | ) |
| 40 | require.NoError(t, err, "create socket server") |
| 41 | |
| 42 | // Return cleanup function |
| 43 | return socketPath, func() { |
| 44 | err := server.Close() |
| 45 | require.NoError(t, err, "close socket server") |
| 46 | _ = os.Remove(socketPath) |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | func TestSyncCommands_Golden(t *testing.T) { |
| 51 | t.Parallel() |
no test coverage detected