MCPcopy
hub / github.com/ContainerSSH/ContainerSSH / runRequest

Function runRequest

http/integration_test.go:320–373  ·  view source on GitHub ↗
(
	clientConfig config.HTTPClientConfiguration,
	serverConfig config.HTTPServerConfiguration,
	t *testing.T,
	message string,
)

Source from the content-addressed store, hash-verified

318}
319
320func runRequest(
321 clientConfig config.HTTPClientConfiguration,
322 serverConfig config.HTTPServerConfiguration,
323 t *testing.T,
324 message string,
325) (Response, int, error) {
326 response := Response{}
327 logger := log.NewTestLogger(t)
328 client, err := http2.NewClient(clientConfig, logger)
329 if err != nil {
330 return response, 0, fmt.Errorf("failed to create client (%w)", err)
331 }
332
333 ready := make(chan bool, 1)
334 server, err := http2.NewServer(
335 "HTTP",
336 serverConfig,
337 http2.NewServerHandler(&handler{}, logger),
338 logger,
339 func(_ string) {
340
341 },
342 )
343 if err != nil {
344 return response, 0, fmt.Errorf("failed to create server (%w)", err)
345 }
346 lifecycle := service.NewLifecycle(server)
347 lifecycle.OnRunning(func(s service.Service, l service.Lifecycle) {
348 ready <- true
349 })
350
351 errorChannel := make(chan error, 2)
352 responseStatus := 0
353 go func() {
354 if err := lifecycle.Run(); err != nil {
355 errorChannel <- err
356 }
357 close(errorChannel)
358 }()
359 <-ready
360 if responseStatus, err = client.Post(
361 "",
362 &Request{Message: message},
363 &response,
364 ); err != nil {
365 lifecycle.Stop(context.Background())
366 return response, 0, err
367 }
368 lifecycle.Stop(context.Background())
369 if err, ok := <-errorChannel; ok {
370 return response, 0, err
371 }
372 return response, responseStatus, nil
373}

Callers 5

TestUnencryptedFunction · 0.85
TestUnencryptedFailureFunction · 0.85
TestEncryptedFunction · 0.85

Calls 7

OnRunningMethod · 0.95
RunMethod · 0.95
PostMethod · 0.95
StopMethod · 0.95
NewTestLoggerFunction · 0.92
NewLifecycleFunction · 0.92
ErrorfMethod · 0.65

Tested by

no test coverage detected