diff --git a/consul/coordinate_endpoint_test.go b/consul/coordinate_endpoint_test.go index a5da3d55d8..c01064180e 100644 --- a/consul/coordinate_endpoint_test.go +++ b/consul/coordinate_endpoint_test.go @@ -3,6 +3,7 @@ package consul import ( "math/rand" "os" + "reflect" "testing" "time" @@ -33,12 +34,7 @@ func getRandomCoordinate() *coordinate.Coordinate { } func coordinatesEqual(a, b *coordinate.Coordinate) bool { - config := coordinate.DefaultConfig() - dist, err := a.DistanceTo(b, config) - if err != nil { - panic(err) - } - return dist < 0.1 + return reflect.DeepEqual(a, b) } func TestCoordinateUpdate(t *testing.T) { diff --git a/consul/fsm_test.go b/consul/fsm_test.go index 92d66a9893..f72a58b8d9 100644 --- a/consul/fsm_test.go +++ b/consul/fsm_test.go @@ -728,6 +728,47 @@ func TestFSM_KVSCheckAndSet(t *testing.T) { } } +func TestFSM_CoordinateUpdate(t *testing.T) { + path, err := ioutil.TempDir("", "fsm") + if err != nil { + t.Fatalf("err: %v", err) + } + defer os.RemoveAll(path) + fsm, err := NewFSM(nil, path, os.Stderr) + if err != nil { + t.Fatalf("err: %v", err) + } + defer fsm.Close() + + nodeName := "Node1" + req := structs.CoordinateUpdateRequest{ + Datacenter: "dc1", + Node: nodeName, + Op: structs.CoordinateSet, + Coord: getRandomCoordinate(), + } + buf, err := structs.Encode(structs.CoordinateRequestType, req) + if err != nil { + t.Fatalf("err: %v", err) + } + resp := fsm.Apply(makeLog(buf)) + if resp != nil { + t.Fatalf("resp: %v", resp) + } + + // Verify key is set + _, d, err := fsm.state.CoordinateGet(nodeName) + if err != nil { + t.Fatalf("err: %v", err) + } + if d == nil { + t.Fatalf("missing") + } + if !coordinatesEqual(req.Coord, d.Coord) { + t.Fatalf("wrong coordinate") + } +} + func TestFSM_SessionCreate_Destroy(t *testing.T) { fsm, err := NewFSM(nil, os.Stderr) if err != nil {