mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
server: Rename test case expect fields
Signed-off-by: Siyuan Zhang <sizhang@google.com>
This commit is contained in:
parent
c6784a7e82
commit
2f6c84e91d
@ -51,50 +51,51 @@ func TestHealthHandler(t *testing.T) {
|
|||||||
tests := []struct {
|
tests := []struct {
|
||||||
alarms []*pb.AlarmMember
|
alarms []*pb.AlarmMember
|
||||||
healthCheckURL string
|
healthCheckURL string
|
||||||
statusCode int
|
|
||||||
health string
|
expectStatusCode int
|
||||||
|
expectHealth string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
alarms: []*pb.AlarmMember{},
|
alarms: []*pb.AlarmMember{},
|
||||||
healthCheckURL: "/health",
|
healthCheckURL: "/health",
|
||||||
statusCode: http.StatusOK,
|
expectStatusCode: http.StatusOK,
|
||||||
health: "true",
|
expectHealth: "true",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
alarms: []*pb.AlarmMember{{MemberID: uint64(0), Alarm: pb.AlarmType_NOSPACE}},
|
alarms: []*pb.AlarmMember{{MemberID: uint64(0), Alarm: pb.AlarmType_NOSPACE}},
|
||||||
healthCheckURL: "/health",
|
healthCheckURL: "/health",
|
||||||
statusCode: http.StatusServiceUnavailable,
|
expectStatusCode: http.StatusServiceUnavailable,
|
||||||
health: "false",
|
expectHealth: "false",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
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",
|
||||||
statusCode: http.StatusOK,
|
expectStatusCode: http.StatusOK,
|
||||||
health: "true",
|
expectHealth: "true",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
alarms: []*pb.AlarmMember{},
|
alarms: []*pb.AlarmMember{},
|
||||||
healthCheckURL: "/health?exclude=NOSPACE",
|
healthCheckURL: "/health?exclude=NOSPACE",
|
||||||
statusCode: http.StatusOK,
|
expectStatusCode: http.StatusOK,
|
||||||
health: "true",
|
expectHealth: "true",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
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",
|
||||||
statusCode: http.StatusOK,
|
expectStatusCode: http.StatusOK,
|
||||||
health: "true",
|
expectHealth: "true",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
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",
|
||||||
statusCode: http.StatusServiceUnavailable,
|
expectStatusCode: http.StatusServiceUnavailable,
|
||||||
health: "false",
|
expectHealth: "false",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
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",
|
||||||
statusCode: http.StatusOK,
|
expectStatusCode: http.StatusOK,
|
||||||
health: "true",
|
expectHealth: "true",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,7 +105,7 @@ func TestHealthHandler(t *testing.T) {
|
|||||||
HandleMetricsHealth(zap.NewExample(), mux, &fakeServerV2{
|
HandleMetricsHealth(zap.NewExample(), mux, &fakeServerV2{
|
||||||
fakeServer: fakeServer{alarms: tt.alarms},
|
fakeServer: fakeServer{alarms: tt.alarms},
|
||||||
Stats: &fakeStats{},
|
Stats: &fakeStats{},
|
||||||
health: tt.health,
|
health: tt.expectHealth,
|
||||||
})
|
})
|
||||||
ts := httptest.NewServer(mux)
|
ts := httptest.NewServer(mux)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
@ -117,15 +118,15 @@ func TestHealthHandler(t *testing.T) {
|
|||||||
t.Errorf("got nil http response with http request %s in test case #%d", tt.healthCheckURL, i+1)
|
t.Errorf("got nil http response with http request %s in test case #%d", tt.healthCheckURL, i+1)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if res.StatusCode != tt.statusCode {
|
if res.StatusCode != tt.expectStatusCode {
|
||||||
t.Errorf("want statusCode %d but got %d in test case #%d", tt.statusCode, res.StatusCode, i+1)
|
t.Errorf("want statusCode %d but got %d in test case #%d", tt.expectStatusCode, res.StatusCode, i+1)
|
||||||
}
|
}
|
||||||
health, err := parseHealthOutput(res.Body)
|
health, err := parseHealthOutput(res.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("fail parse health check output %v", err)
|
t.Errorf("fail parse health check output %v", err)
|
||||||
}
|
}
|
||||||
if health.Health != tt.health {
|
if health.Health != tt.expectHealth {
|
||||||
t.Errorf("want health %s but got %s", tt.health, health.Health)
|
t.Errorf("want health %s but got %s", tt.expectHealth, health.Health)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user