Home / Function/ Test_HealthCheck_Custom() — fiber Function Reference

Test_HealthCheck_Custom() — fiber Function Reference

Architecture documentation for the Test_HealthCheck_Custom() function in healthcheck_test.go from the fiber codebase.

Entity Profile

Dependency Diagram

graph TD
  eaed5afb_df1b_1c61_228f_5b9b90874a15["Test_HealthCheck_Custom()"]
  06fd3a09_de22_eff7_9240_dbc4380b44fd["healthcheck_test.go"]
  eaed5afb_df1b_1c61_228f_5b9b90874a15 -->|defined in| 06fd3a09_de22_eff7_9240_dbc4380b44fd
  b84cfa43_3829_3325_7bf1_bf0168edaf69["shouldGiveOK()"]
  eaed5afb_df1b_1c61_228f_5b9b90874a15 -->|calls| b84cfa43_3829_3325_7bf1_bf0168edaf69
  39ed6e88_2b54_5567_940e_8e84f06cd1ad["shouldGiveStatus()"]
  eaed5afb_df1b_1c61_228f_5b9b90874a15 -->|calls| 39ed6e88_2b54_5567_940e_8e84f06cd1ad
  style eaed5afb_df1b_1c61_228f_5b9b90874a15 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

middleware/healthcheck/healthcheck_test.go lines 72–119

func Test_HealthCheck_Custom(t *testing.T) {
	t.Parallel()

	app := fiber.New()
	c1 := make(chan struct{}, 1)
	app.Get("/live", New(Config{
		Probe: func(_ fiber.Ctx) bool {
			return true
		},
	}))
	app.Get("/ready", New(Config{
		Probe: func(_ fiber.Ctx) bool {
			select {
			case <-c1:
				return true
			default:
				return false
			}
		},
	}))
	app.Get(StartupEndpoint, New(Config{
		Probe: func(_ fiber.Ctx) bool {
			return false
		},
	}))

	// Setup custom liveness and readiness probes to simulate application health status
	// Live should return 200 with GET request
	shouldGiveOK(t, app, "/live")
	// Live should return 404 with POST request
	req, err := app.Test(httptest.NewRequest(fiber.MethodPost, "/live", http.NoBody))
	require.NoError(t, err)
	require.Equal(t, fiber.StatusMethodNotAllowed, req.StatusCode)

	// Ready should return 404 with POST request
	req, err = app.Test(httptest.NewRequest(fiber.MethodPost, "/ready", http.NoBody))
	require.NoError(t, err)
	require.Equal(t, fiber.StatusMethodNotAllowed, req.StatusCode)

	// Ready should return 503 with GET request before the channel is closed
	shouldGiveStatus(t, app, "/ready", fiber.StatusServiceUnavailable)

	shouldGiveStatus(t, app, "/startupz", fiber.StatusServiceUnavailable)

	// Ready should return 200 with GET request after the channel is closed
	c1 <- struct{}{}
	shouldGiveOK(t, app, "/ready")
}

Domain

Subdomains

Frequently Asked Questions

What does Test_HealthCheck_Custom() do?
Test_HealthCheck_Custom() is a function in the fiber codebase, defined in middleware/healthcheck/healthcheck_test.go.
Where is Test_HealthCheck_Custom() defined?
Test_HealthCheck_Custom() is defined in middleware/healthcheck/healthcheck_test.go at line 72.
What does Test_HealthCheck_Custom() call?
Test_HealthCheck_Custom() calls 2 function(s): shouldGiveOK, shouldGiveStatus.

Analyze Your Own Codebase

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

Try Supermodel Free