mirror of https://github.com/status-im/consul.git
test: add additional http status code assertions in coordinate HTTP API tests (#6410)
When this test flakes sometimes this happens: --- FAIL: TestCoordinate_Node (1.69s) panic: interface conversion: interface {} is nil, not structs.Coordinates [recovered] FAIL github.com/hashicorp/consul/agent 19.999s Exit code: 1 panic: interface conversion: interface {} is nil, not structs.Coordinates [recovered] panic: interface conversion: interface {} is nil, not structs.Coordinates There is definitely a bug lurking, but the code seems to imply this can only return nil on 404. The tests previously were not checking the status code. The underlying cause of the flake is unknown, but this should turn the failure into a more normal test failure.
This commit is contained in:
parent
00aa108490
commit
d979d8c239
|
@ -63,6 +63,10 @@ func TestCoordinate_Datacenters(t *testing.T) {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if resp.Code != http.StatusOK {
|
||||||
|
t.Fatalf("bad: %v", resp.Code)
|
||||||
|
}
|
||||||
|
|
||||||
maps := obj.([]structs.DatacenterMap)
|
maps := obj.([]structs.DatacenterMap)
|
||||||
if len(maps) != 1 ||
|
if len(maps) != 1 ||
|
||||||
maps[0].Datacenter != "dc1" ||
|
maps[0].Datacenter != "dc1" ||
|
||||||
|
@ -87,6 +91,10 @@ func TestCoordinate_Nodes(t *testing.T) {
|
||||||
r.Fatalf("err: %v", err)
|
r.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if resp.Code != http.StatusOK {
|
||||||
|
r.Fatalf("bad: %v", resp.Code)
|
||||||
|
}
|
||||||
|
|
||||||
// Check that coordinates are empty before registering a node
|
// Check that coordinates are empty before registering a node
|
||||||
coordinates, ok := obj.(structs.Coordinates)
|
coordinates, ok := obj.(structs.Coordinates)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -144,6 +152,10 @@ func TestCoordinate_Nodes(t *testing.T) {
|
||||||
r.Fatalf("err: %v", err)
|
r.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if resp.Code != http.StatusOK {
|
||||||
|
r.Fatalf("bad: %v", resp.Code)
|
||||||
|
}
|
||||||
|
|
||||||
coordinates, ok := obj.(structs.Coordinates)
|
coordinates, ok := obj.(structs.Coordinates)
|
||||||
if !ok {
|
if !ok {
|
||||||
r.Fatalf("expected: structs.Coordinates, received: %+v", obj)
|
r.Fatalf("expected: structs.Coordinates, received: %+v", obj)
|
||||||
|
@ -163,6 +175,10 @@ func TestCoordinate_Nodes(t *testing.T) {
|
||||||
r.Fatalf("err: %v", err)
|
r.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if resp.Code != http.StatusOK {
|
||||||
|
r.Fatalf("bad: %v", resp.Code)
|
||||||
|
}
|
||||||
|
|
||||||
coordinates, ok := obj.(structs.Coordinates)
|
coordinates, ok := obj.(structs.Coordinates)
|
||||||
if !ok {
|
if !ok {
|
||||||
r.Fatalf("expected: structs.Coordinates, received: %+v", obj)
|
r.Fatalf("expected: structs.Coordinates, received: %+v", obj)
|
||||||
|
@ -180,6 +196,10 @@ func TestCoordinate_Nodes(t *testing.T) {
|
||||||
r.Fatalf("err: %v", err)
|
r.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if resp.Code != http.StatusOK {
|
||||||
|
r.Fatalf("bad: %v", resp.Code)
|
||||||
|
}
|
||||||
|
|
||||||
coordinates, ok := obj.(structs.Coordinates)
|
coordinates, ok := obj.(structs.Coordinates)
|
||||||
if !ok {
|
if !ok {
|
||||||
r.Fatalf("expected: structs.Coordinates, received: %+v", obj)
|
r.Fatalf("expected: structs.Coordinates, received: %+v", obj)
|
||||||
|
@ -220,6 +240,7 @@ func TestCoordinate_Node(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.Code != http.StatusNotFound {
|
if resp.Code != http.StatusNotFound {
|
||||||
t.Fatalf("bad: %v", resp.Code)
|
t.Fatalf("bad: %v", resp.Code)
|
||||||
}
|
}
|
||||||
|
@ -269,6 +290,10 @@ func TestCoordinate_Node(t *testing.T) {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if resp.Code != http.StatusOK {
|
||||||
|
t.Fatalf("bad: %v", resp.Code)
|
||||||
|
}
|
||||||
|
|
||||||
coordinates := obj.(structs.Coordinates)
|
coordinates := obj.(structs.Coordinates)
|
||||||
if len(coordinates) != 1 ||
|
if len(coordinates) != 1 ||
|
||||||
coordinates[0].Node != "foo" {
|
coordinates[0].Node != "foo" {
|
||||||
|
@ -294,6 +319,10 @@ func TestCoordinate_Node(t *testing.T) {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if resp.Code != http.StatusOK {
|
||||||
|
t.Fatalf("bad: %v", resp.Code)
|
||||||
|
}
|
||||||
|
|
||||||
coordinates = obj.(structs.Coordinates)
|
coordinates = obj.(structs.Coordinates)
|
||||||
if len(coordinates) != 1 || coordinates[0].Node != "foo" {
|
if len(coordinates) != 1 || coordinates[0].Node != "foo" {
|
||||||
t.Fatalf("bad: %v", coordinates)
|
t.Fatalf("bad: %v", coordinates)
|
||||||
|
@ -342,6 +371,11 @@ func TestCoordinate_Update(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if resp.Code != http.StatusOK {
|
||||||
|
t.Fatalf("bad: %v", resp.Code)
|
||||||
|
}
|
||||||
|
|
||||||
time.Sleep(300 * time.Millisecond)
|
time.Sleep(300 * time.Millisecond)
|
||||||
|
|
||||||
// Query back and check the coordinates are present.
|
// Query back and check the coordinates are present.
|
||||||
|
|
Loading…
Reference in New Issue