mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
server: Run health check tests in subtests
Signed-off-by: Siyuan Zhang <sizhang@google.com>
This commit is contained in:
parent
2f6c84e91d
commit
eed94f6f94
@ -49,6 +49,7 @@ func TestHealthHandler(t *testing.T) {
|
|||||||
// define the input and expected output
|
// define the input and expected output
|
||||||
// input: alarms, and healthCheckURL
|
// input: alarms, and healthCheckURL
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
|
name string
|
||||||
alarms []*pb.AlarmMember
|
alarms []*pb.AlarmMember
|
||||||
healthCheckURL string
|
healthCheckURL string
|
||||||
|
|
||||||
@ -56,42 +57,49 @@ func TestHealthHandler(t *testing.T) {
|
|||||||
expectHealth string
|
expectHealth string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
name: "Healthy if no alarm",
|
||||||
alarms: []*pb.AlarmMember{},
|
alarms: []*pb.AlarmMember{},
|
||||||
healthCheckURL: "/health",
|
healthCheckURL: "/health",
|
||||||
expectStatusCode: http.StatusOK,
|
expectStatusCode: http.StatusOK,
|
||||||
expectHealth: "true",
|
expectHealth: "true",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "Unhealthy if NOSPACE alarm is on",
|
||||||
alarms: []*pb.AlarmMember{{MemberID: uint64(0), Alarm: pb.AlarmType_NOSPACE}},
|
alarms: []*pb.AlarmMember{{MemberID: uint64(0), Alarm: pb.AlarmType_NOSPACE}},
|
||||||
healthCheckURL: "/health",
|
healthCheckURL: "/health",
|
||||||
expectStatusCode: http.StatusServiceUnavailable,
|
expectStatusCode: http.StatusServiceUnavailable,
|
||||||
expectHealth: "false",
|
expectHealth: "false",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "Healthy if NOSPACE alarm is on and excluded",
|
||||||
alarms: []*pb.AlarmMember{{MemberID: uint64(0), Alarm: pb.AlarmType_NOSPACE}},
|
alarms: []*pb.AlarmMember{{MemberID: uint64(0), Alarm: pb.AlarmType_NOSPACE}},
|
||||||
healthCheckURL: "/health?exclude=NOSPACE",
|
healthCheckURL: "/health?exclude=NOSPACE",
|
||||||
expectStatusCode: http.StatusOK,
|
expectStatusCode: http.StatusOK,
|
||||||
expectHealth: "true",
|
expectHealth: "true",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "Healthy if NOSPACE alarm is excluded",
|
||||||
alarms: []*pb.AlarmMember{},
|
alarms: []*pb.AlarmMember{},
|
||||||
healthCheckURL: "/health?exclude=NOSPACE",
|
healthCheckURL: "/health?exclude=NOSPACE",
|
||||||
expectStatusCode: http.StatusOK,
|
expectStatusCode: http.StatusOK,
|
||||||
expectHealth: "true",
|
expectHealth: "true",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "Healthy if multiple NOSPACE alarms are on and excluded",
|
||||||
alarms: []*pb.AlarmMember{{MemberID: uint64(1), Alarm: pb.AlarmType_NOSPACE}, {MemberID: uint64(2), Alarm: pb.AlarmType_NOSPACE}, {MemberID: uint64(3), Alarm: pb.AlarmType_NOSPACE}},
|
alarms: []*pb.AlarmMember{{MemberID: uint64(1), Alarm: pb.AlarmType_NOSPACE}, {MemberID: uint64(2), Alarm: pb.AlarmType_NOSPACE}, {MemberID: uint64(3), Alarm: pb.AlarmType_NOSPACE}},
|
||||||
healthCheckURL: "/health?exclude=NOSPACE",
|
healthCheckURL: "/health?exclude=NOSPACE",
|
||||||
expectStatusCode: http.StatusOK,
|
expectStatusCode: http.StatusOK,
|
||||||
expectHealth: "true",
|
expectHealth: "true",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "Unhealthy if NOSPACE alarms is excluded and CORRUPT is on",
|
||||||
alarms: []*pb.AlarmMember{{MemberID: uint64(0), Alarm: pb.AlarmType_NOSPACE}, {MemberID: uint64(1), Alarm: pb.AlarmType_CORRUPT}},
|
alarms: []*pb.AlarmMember{{MemberID: uint64(0), Alarm: pb.AlarmType_NOSPACE}, {MemberID: uint64(1), Alarm: pb.AlarmType_CORRUPT}},
|
||||||
healthCheckURL: "/health?exclude=NOSPACE",
|
healthCheckURL: "/health?exclude=NOSPACE",
|
||||||
expectStatusCode: http.StatusServiceUnavailable,
|
expectStatusCode: http.StatusServiceUnavailable,
|
||||||
expectHealth: "false",
|
expectHealth: "false",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "Unhealthy if both NOSPACE and CORRUPT are on and excluded",
|
||||||
alarms: []*pb.AlarmMember{{MemberID: uint64(0), Alarm: pb.AlarmType_NOSPACE}, {MemberID: uint64(1), Alarm: pb.AlarmType_CORRUPT}},
|
alarms: []*pb.AlarmMember{{MemberID: uint64(0), Alarm: pb.AlarmType_NOSPACE}, {MemberID: uint64(1), Alarm: pb.AlarmType_CORRUPT}},
|
||||||
healthCheckURL: "/health?exclude=NOSPACE&exclude=CORRUPT",
|
healthCheckURL: "/health?exclude=NOSPACE&exclude=CORRUPT",
|
||||||
expectStatusCode: http.StatusOK,
|
expectStatusCode: http.StatusOK,
|
||||||
@ -100,7 +108,7 @@ func TestHealthHandler(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i, tt := range tests {
|
for i, tt := range tests {
|
||||||
func() {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
HandleMetricsHealth(zap.NewExample(), mux, &fakeServerV2{
|
HandleMetricsHealth(zap.NewExample(), mux, &fakeServerV2{
|
||||||
fakeServer: fakeServer{alarms: tt.alarms},
|
fakeServer: fakeServer{alarms: tt.alarms},
|
||||||
@ -128,7 +136,7 @@ func TestHealthHandler(t *testing.T) {
|
|||||||
if health.Health != tt.expectHealth {
|
if health.Health != tt.expectHealth {
|
||||||
t.Errorf("want health %s but got %s", tt.expectHealth, health.Health)
|
t.Errorf("want health %s but got %s", tt.expectHealth, health.Health)
|
||||||
}
|
}
|
||||||
}()
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user