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

Function Test_StartServices

services_test.go:329–419  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

327}
328
329func Test_StartServices(t *testing.T) {
330 t.Run("no-services", func(t *testing.T) {
331 app := &App{
332 configured: Config{
333 Services: []Service{},
334 },
335 state: newState(),
336 }
337
338 err := app.startServices(context.Background())
339 require.NoError(t, err)
340 require.Zero(t, app.state.ServicesLen())
341 })
342
343 t.Run("successful-start", func(t *testing.T) {
344 app := &App{
345 configured: Config{
346 Services: []Service{
347 &mockService{name: "dep1"},
348 &mockService{name: "dep2"},
349 },
350 },
351 state: newState(),
352 }
353
354 err := app.startServices(context.Background())
355 require.NoError(t, err)
356 require.Equal(t, 2, app.state.ServicesLen())
357 })
358
359 t.Run("failed-start", func(t *testing.T) {
360 app := &App{
361 configured: Config{
362 Services: []Service{
363 &mockService{name: "dep1", startError: errors.New(startErrorMessage + " 1")},
364 &mockService{name: "dep2", startError: errors.New(startErrorMessage + " 2")},
365 &mockService{name: "dep3"},
366 },
367 },
368 state: newState(),
369 }
370
371 err := app.startServices(context.Background())
372 require.Error(t, err)
373 require.Contains(t, err.Error(), startErrorMessage+" 1")
374 require.Contains(t, err.Error(), startErrorMessage+" 2")
375 require.Equal(t, 1, app.state.ServicesLen())
376 })
377
378 t.Run("context", func(t *testing.T) {
379 t.Run("already-canceled", func(t *testing.T) {
380 app := &App{
381 configured: Config{
382 Services: []Service{
383 &mockService{name: "dep1"},
384 },
385 },
386 state: newState(),

Callers

nothing calls this directly

Calls 6

startServicesMethod · 0.95
newStateFunction · 0.85
ServicesLenMethod · 0.80
ContainsMethod · 0.80
NewMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected