(t *testing.T)
| 327 | } |
| 328 | |
| 329 | func 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(), |
nothing calls this directly
no test coverage detected