MCPcopy
hub / github.com/gofiber/fiber / startTestServerWithPort

Function startTestServerWithPort

client/client_test.go:29–60  ·  view source on GitHub ↗
(t *testing.T, beforeStarting func(app *fiber.App))

Source from the content-addressed store, hash-verified

27)
28
29func startTestServerWithPort(t *testing.T, beforeStarting func(app *fiber.App)) (app *fiber.App, addr string) { //nolint:nonamedreturns // gocritic unnamedResult requires explicit result names for clarity when returning app and address
30 t.Helper()
31
32 app = fiber.New()
33
34 if beforeStarting != nil {
35 beforeStarting(app)
36 }
37
38 addrChan := make(chan string)
39 errChan := make(chan error, 1)
40 go func(server *fiber.App) {
41 err := server.Listen(":0", fiber.ListenConfig{
42 DisableStartupMessage: true,
43 ListenerAddrFunc: func(addr net.Addr) {
44 addrChan <- addr.String()
45 },
46 })
47 if err != nil {
48 errChan <- err
49 }
50 }(app)
51
52 select {
53 case addr = <-addrChan:
54 return app, addr
55 case err := <-errChan:
56 t.Fatalf("Failed to start test server: %v", err)
57 }
58
59 return nil, ""
60}
61
62func Test_New_With_Client(t *testing.T) {
63 t.Parallel()

Callers 11

Test_GetFunction · 0.85
Test_HeadFunction · 0.85
Test_PostFunction · 0.85
Test_PutFunction · 0.85
Test_DeleteFunction · 0.85
Test_OptionsFunction · 0.85
Test_PatchFunction · 0.85
Test_QueryFunction · 0.85
Test_Client_UserAgentFunction · 0.85

Calls 4

ListenMethod · 0.80
NewMethod · 0.65
StringMethod · 0.65
FatalfMethod · 0.65

Tested by

no test coverage detected