MCPcopy
hub / github.com/cli/cli / TestStartSSHServerFailure

Function TestStartSSHServerFailure

internal/codespaces/rpc/invoker_test.go:283–313  ·  view source on GitHub ↗

Test that the RPC invoker returns an error when the SSH server fails to start

(t *testing.T)

Source from the content-addressed store, hash-verified

281
282// Test that the RPC invoker returns an error when the SSH server fails to start
283func TestStartSSHServerFailure(t *testing.T) {
284 resp := ssh.StartRemoteServerResponse{
285 ServerPort: strconv.Itoa(1234),
286 User: "test",
287 Message: "error message",
288 Result: false,
289 }
290
291 server := newMockServer()
292 server.StartRemoteServerAsyncFunc = func(context.Context, *ssh.StartRemoteServerRequest) (*ssh.StartRemoteServerResponse, error) {
293 return &resp, nil
294 }
295
296 invoker, stop, err := createTestInvoker(t, server)
297 if err != nil {
298 t.Fatalf("error connecting to internal server: %v", err)
299 }
300 defer stop()
301
302 errorMessage := fmt.Sprintf("failed to start SSH server: %s", resp.Message)
303 port, user, err := invoker.StartSSHServer(context.Background())
304 if err.Error() != errorMessage {
305 t.Fatalf("expected %v, got %v", errorMessage, err)
306 }
307 if port != 0 {
308 t.Fatalf("expected %d, got %d", 0, port)
309 }
310 if user != "" {
311 t.Fatalf("expected %s, got %s", "", user)
312 }
313}

Callers

nothing calls this directly

Calls 4

newMockServerFunction · 0.85
createTestInvokerFunction · 0.85
StartSSHServerMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected