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

Function Test_InitServices

services_test.go:202–327  ·  services_test.go::Test_InitServices
(t *testing.T)

Source from the content-addressed store, hash-verified

200}
201
202func 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)

Callers

nothing calls this directly

Calls 11

HooksMethod · 0.95
SetOutputFunction · 0.92
newStateFunction · 0.85
newHooksFunction · 0.85
withCapturedLogOutputFunction · 0.85
ContainsMethod · 0.80
NewFunction · 0.70
NewMethod · 0.65
StringMethod · 0.65
LoadMethod · 0.65

Tested by

no test coverage detected