@@ -54,27 +54,27 @@ var _ = Describe("LRP Utils", func() {
5454
5555 Describe ("HashWithOptions" , func () {
5656 It ("treats semantically identical JSON options as equal regardless of key order" , func () {
57- routeAlpha := routingtable.Route {
57+ routeA := routingtable.Route {
5858 Hostname : "foo.example.com" ,
5959 Options : json .RawMessage (`{"b":2,"a":1}` ),
6060 }
61- routeBeta := routingtable.Route {
61+ routeB := routingtable.Route {
6262 Hostname : "foo.example.com" ,
6363 Options : json .RawMessage (`{"a":1,"b":2}` ),
6464 }
65- Expect (routeAlpha .HashWithOptions ()).To (Equal (routeBeta .HashWithOptions ()))
65+ Expect (routeA .HashWithOptions ()).To (Equal (routeB .HashWithOptions ()))
6666 })
6767
6868 It ("distinguishes routes with different option values" , func () {
69- routeAlpha := routingtable.Route {
69+ routeA := routingtable.Route {
7070 Hostname : "foo.example.com" ,
7171 Options : json .RawMessage (`{"loadbalancing":"hash"}` ),
7272 }
73- routeBeta := routingtable.Route {
73+ routeB := routingtable.Route {
7474 Hostname : "foo.example.com" ,
7575 Options : json .RawMessage (`{"loadbalancing":"round-robin"}` ),
7676 }
77- Expect (routeAlpha .HashWithOptions ()).NotTo (Equal (routeBeta .HashWithOptions ()))
77+ Expect (routeA .HashWithOptions ()).NotTo (Equal (routeB .HashWithOptions ()))
7878 })
7979
8080 It ("distinguishes a route with options from one without" , func () {
@@ -93,6 +93,25 @@ var _ = Describe("LRP Utils", func() {
9393 withEmpty := routingtable.Route {Hostname : "foo.example.com" , Options : json.RawMessage {}}
9494 Expect (withNil .HashWithOptions ()).To (Equal (withEmpty .HashWithOptions ()))
9595 })
96+
97+ It ("falls back to a raw byte comparison when options are not valid JSON" , func () {
98+ routeA := routingtable.Route {
99+ Hostname : "foo.example.com" ,
100+ Options : json .RawMessage (`not-valid-json` ),
101+ }
102+ routeB := routingtable.Route {
103+ Hostname : "foo.example.com" ,
104+ Options : json .RawMessage (`not-valid-json` ),
105+ }
106+ routeC := routingtable.Route {
107+ Hostname : "foo.example.com" ,
108+ Options : json .RawMessage (`also-not-valid-json` ),
109+ }
110+
111+ Expect (func () { routeA .HashWithOptions () }).NotTo (Panic ())
112+ Expect (routeA .HashWithOptions ()).To (Equal (routeB .HashWithOptions ()))
113+ Expect (routeA .HashWithOptions ()).NotTo (Equal (routeC .HashWithOptions ()))
114+ })
96115 })
97116
98117 Describe ("NewEndpointsFromActual" , func () {
0 commit comments