(t *testing.T)
| 200 | } |
| 201 | |
| 202 | func Test_InitServices(t *testing.T) { |
| 203 | t.Parallel() |
| 204 | |
| 205 | t.Run("no-services", func(t *testing.T) { |
| 206 | app := &App{configured: Config{}} |
| 207 | require.NotPanics(t, app.initServices) |
| 208 | }) |
| 209 | |
| 210 | t.Run("start/success", func(t *testing.T) { |
| 211 | // Initialize the app using the struct and defining the state and hooks manually, |
| 212 | // because we are not checking the shutdown hooks in this test. |
| 213 | app := &App{ |
| 214 | configured: Config{ |
| 215 | Services: []Service{ |
| 216 | &mockService{name: "dep1"}, |
| 217 | &mockService{name: "dep2"}, |
| 218 | }, |
| 219 | }, |
| 220 | state: newState(), |
| 221 | } |
| 222 | |
| 223 | app.hooks = newHooks(app) |
| 224 | |
| 225 | require.NotPanics(t, app.initServices) |
| 226 | }) |
| 227 | |
| 228 | t.Run("start/error", func(t *testing.T) { |
| 229 | // Initialize the app using the struct and defining the state and hooks manually, |
| 230 | // because we are not checking the shutdown hooks in this test. |
| 231 | app := &App{ |
| 232 | configured: Config{ |
| 233 | Services: []Service{ |
| 234 | &mockService{name: "dep1", startError: errors.New(startErrorMessage + " 1")}, |
| 235 | &mockService{name: "dep2", startError: errors.New(startErrorMessage + " 2")}, |
| 236 | &mockService{name: "dep3"}, |
| 237 | }, |
| 238 | }, |
| 239 | state: newState(), |
| 240 | } |
| 241 | |
| 242 | app.hooks = newHooks(app) |
| 243 | |
| 244 | require.Panics(t, app.initServices) |
| 245 | }) |
| 246 | |
| 247 | t.Run("shutdown-hooks/success", func(t *testing.T) { |
| 248 | // Initialize the app using the New function to verify that the shutdown hooks are registered |
| 249 | // and the app mutex is not causing a deadlock. |
| 250 | app := New(Config{ |
| 251 | Services: []Service{&mockService{name: "dep1"}}, |
| 252 | }) |
| 253 | |
| 254 | require.NotPanics(t, app.initServices) |
| 255 | |
| 256 | var buf stringsLogger |
| 257 | log.SetOutput(&buf) |
| 258 | |
| 259 | app.Hooks().executeOnPostShutdownHooks(nil) |
nothing calls this directly
no test coverage detected