MCPcopy Index your code
hub / github.com/coder/coder / setupSocketServer

Function setupSocketServer

cli/sync_test.go:22–48  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

20// Returns the socket path and a cleanup function. The path should be passed to
21// sync commands via the --socket-path flag.
22func 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
50func TestSyncCommands_Golden(t *testing.T) {
51 t.Parallel()

Callers 1

TestSyncCommands_GoldenFunction · 0.85

Calls 7

CloseMethod · 0.95
AgentSocketPathFunction · 0.92
NewServerFunction · 0.92
WithPathFunction · 0.92
MkdirAllMethod · 0.80
HelperMethod · 0.65
RemoveMethod · 0.65

Tested by

no test coverage detected