MCPcopy
hub / github.com/cli/cli / createTestInvoker

Function createTestInvoker

internal/codespaces/rpc/invoker_test.go:59–86  ·  view source on GitHub ↗

createTestInvoker is the main test setup function. It returns an Invoker using the provided mockServer, as well as a shutdown function. The Invoker does not need to be closed directly, that will be handled by the shutdown function.

(t *testing.T, server *mockServer)

Source from the content-addressed store, hash-verified

57// createTestInvoker is the main test setup function. It returns an Invoker using the provided mockServer, as well as a shutdown function.
58// The Invoker does not need to be closed directly, that will be handled by the shutdown function.
59func createTestInvoker(t *testing.T, server *mockServer) (Invoker, func(), error) {
60 listener, err := net.Listen("tcp", "127.0.0.1:16634")
61 if err != nil {
62 return nil, nil, fmt.Errorf("failed to listen: %w", err)
63 }
64
65 ctx, cancel := context.WithCancel(context.Background())
66 ch := make(chan error)
67 go func() { ch <- runTestGrpcServer(ctx, listener, server) }()
68
69 close := func() {
70 cancel()
71 <-ch
72 listener.Close()
73 }
74
75 // Create a new invoker with a mock port forwarder
76 invoker, err := CreateInvoker(context.Background(), rpctest.PortForwarder{})
77 if err != nil {
78 close()
79 return nil, nil, fmt.Errorf("error connecting to internal server: %w", err)
80 }
81
82 return invoker, func() {
83 invoker.Close()
84 close()
85 }, nil
86}
87
88// Test that the RPC invoker notifies the codespace of client activity on connection
89func verifyNotifyCodespaceOfClientActivity(t *testing.T, server *mockServer) {

Calls 4

runTestGrpcServerFunction · 0.85
CreateInvokerFunction · 0.85
ErrorfMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected