MCPcopy
hub / github.com/ContainerSSH/ContainerSSH / NewTestServer

Function NewTestServer

internal/sshserver/NewTestServer.go:16–48  ·  view source on GitHub ↗

NewTestServer is a simplified API to start and stop a test server.

(t *testing.T, handler Handler, logger log.Logger, config *config2.SSHConfig)

Source from the content-addressed store, hash-verified

14
15// NewTestServer is a simplified API to start and stop a test server.
16func NewTestServer(t *testing.T, handler Handler, logger log.Logger, config *config2.SSHConfig) TestServer {
17 if config == nil {
18 config = &config2.SSHConfig{}
19 structutils.Defaults(config)
20 }
21
22 port := test.GetNextPort(t, "SSH")
23 config.Listen = fmt.Sprintf("127.0.0.1:%d", port)
24 if err := config.GenerateHostKey(); err != nil {
25 panic(err)
26 }
27 svc, err := New(*config, handler, logger)
28 if err != nil {
29 panic(err)
30 }
31 lifecycle := service.NewLifecycle(svc)
32 started := make(chan struct{})
33 lifecycle.OnRunning(
34 func(s service.Service, l service.Lifecycle) {
35 started <- struct{}{}
36 })
37
38 t.Cleanup(func() {
39 lifecycle.Stop(context.Background())
40 _ = lifecycle.Wait()
41 })
42
43 return &testServerImpl{
44 config: *config,
45 lifecycle: lifecycle,
46 started: started,
47 }
48}

Callers 11

createTestServerFunction · 0.92
TestAuthGSSAPIFunction · 0.92
TestKeepAliveFunction · 0.92
TestProperShutdownFunction · 0.92

Calls 9

OnRunningMethod · 0.95
StopMethod · 0.95
WaitMethod · 0.95
DefaultsFunction · 0.92
GetNextPortFunction · 0.92
NewLifecycleFunction · 0.92
GenerateHostKeyMethod · 0.80
CleanupMethod · 0.80
NewFunction · 0.70

Tested by 6

createTestServerFunction · 0.74
TestAuthGSSAPIFunction · 0.74
TestKeepAliveFunction · 0.74
TestProperShutdownFunction · 0.74