MCPcopy Index your code
hub / github.com/cli/cli / TestStartSSHServerFailure

Function TestStartSSHServerFailure

internal/codespaces/rpc/invoker_test.go:284–314  ·  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

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

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