示例#1
0
func TestMultipleRegistrations(t *testing.T) {
	testcases := []struct {
		name    string         // component
		checker health.Checker // health checker
	}{
		{"component-alive", healthy},
		{"component-up", healthy},
		{"component-failed", failed},
		{"component-dead", failed},
		{"component-ok", healthy},
	}

	for _, tc := range testcases {
		health.Register(tc.name, tc.checker)
	}
	assert.Len(t, health.Components(), len(testcases)) // all registered

	all := health.RunChecks()

	for _, tc := range testcases {
		assert.Contains(t, health.Components(), tc.name)
		_, found := all[tc.name]
		assert.True(t, found)
		assert.EqualValues(t, all[tc.name], tc.checker.Check(), tc.name)
	}

	teardown()
}
示例#2
0
func TestDeregisterHealthCheck(t *testing.T) {
	health.Register(COMPONENT, healthy)
	health.Unregister(COMPONENT)
	assert.Len(t, health.Components(), 0)
	assert.NotContains(t, health.Components(), COMPONENT)
	all := health.RunChecks()
	assert.Len(t, all, 0)

	teardown()
}
示例#3
0
func TestRegisterFunc(t *testing.T) {
	health.RegisterFunc(COMPONENT, alwaysFailing)
	assert.Len(t, health.Components(), 1)
	assert.Contains(t, health.Components(), COMPONENT)
	all := health.RunChecks()

	status, found := all[COMPONENT]
	assert.True(t, found)
	assert.EqualValues(t, status, alwaysFailing())

	teardown()
}
示例#4
0
func TestRegisterDuplicateHealthCheck(t *testing.T) {
	health.Register(COMPONENT, healthy)
	health.RegisterFunc(COMPONENT, alwaysFailing) // replace with failing health check
	assert.Len(t, health.Components(), 1)
	assert.Contains(t, health.Components(), COMPONENT)
	all := health.RunChecks()

	status, found := all[COMPONENT]
	assert.True(t, found)
	assert.EqualValues(t, status, alwaysFailing())

	teardown()
}
示例#5
0
// testify.TestSuite could be used to get automatic teardown cleanup after tests
func teardown() { // clear all components from health check set
	for _, c := range health.Components() {
		health.Unregister(c)
	}
}