Home / Function/ Test_InitServices() — fiber Function Reference

Test_InitServices() — fiber Function Reference

Architecture documentation for the Test_InitServices() function in services_test.go from the fiber codebase.

Entity Profile

Dependency Diagram

graph TD
  201ab49a_98ed_2956_e1ca_f48bc6badc6e["Test_InitServices()"]
  a3b050d2_f10a_df85_e082_e3ac664a6a6c["services_test.go"]
  201ab49a_98ed_2956_e1ca_f48bc6badc6e -->|defined in| a3b050d2_f10a_df85_e082_e3ac664a6a6c
  style 201ab49a_98ed_2956_e1ca_f48bc6badc6e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

services_test.go lines 129–216

func Test_InitServices(t *testing.T) {
	t.Run("no-services", func(t *testing.T) {
		app := &App{configured: Config{}}
		require.NotPanics(t, app.initServices)
	})

	t.Run("start/success", func(t *testing.T) {
		// Initialize the app using the struct and defining the state and hooks manually,
		// because we are not checking the shutdown hooks in this test.
		app := &App{
			configured: Config{
				Services: []Service{
					&mockService{name: "dep1"},
					&mockService{name: "dep2"},
				},
			},
			state: newState(),
		}

		app.hooks = newHooks(app)

		require.NotPanics(t, app.initServices)
	})

	t.Run("start/error", func(t *testing.T) {
		// Initialize the app using the struct and defining the state and hooks manually,
		// because we are not checking the shutdown hooks in this test.
		app := &App{
			configured: Config{
				Services: []Service{
					&mockService{name: "dep1", startError: errors.New(startErrorMessage + " 1")},
					&mockService{name: "dep2", startError: errors.New(startErrorMessage + " 2")},
					&mockService{name: "dep3"},
				},
			},
			state: newState(),
		}

		app.hooks = newHooks(app)

		require.Panics(t, app.initServices)
	})

	t.Run("shutdown-hooks/success", func(t *testing.T) {
		// Initialize the app using the New function to verify that the shutdown hooks are registered
		// and the app mutex is not causing a deadlock.
		app := New(Config{
			Services: []Service{&mockService{name: "dep1"}},
		})

		require.NotPanics(t, app.initServices)

		type stringsLogger struct {
			strings.Builder
		}

		var buf stringsLogger
		log.SetOutput(&buf)

		app.Hooks().executeOnPostShutdownHooks(nil)

		require.NotContains(t, buf.String(), "failed to call post shutdown hook:")
	})

	t.Run("shutdown-hooks/error", func(t *testing.T) {
		// Initialize the app using the New function to verify that the shutdown hooks are registered
		// and the app mutex is not causing a deadlock.
		app := New(Config{
			Services: []Service{
				&mockService{name: "dep1"},
				&mockService{name: "dep2", terminateError: errors.New(terminateErrorMessage + " 2")},
			},
		})

		require.NotPanics(t, app.initServices)

		type stringsLogger struct {
			strings.Builder
		}

		var buf stringsLogger

Domain

Subdomains

Defined In

Frequently Asked Questions

What does Test_InitServices() do?
Test_InitServices() is a function in the fiber codebase, defined in services_test.go.
Where is Test_InitServices() defined?
Test_InitServices() is defined in services_test.go at line 129.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free