File tree Expand file tree Collapse file tree 2 files changed +17
-10
lines changed Expand file tree Collapse file tree 2 files changed +17
-10
lines changed Original file line number Diff line number Diff line change @@ -247,15 +247,19 @@ func (g *SubGraph) ToJson(l *Latency) (js []byte, rerr error) {
247247 log .Fatal ("We don't currently support more than 1 uid at root." )
248248 }
249249
250- ival := r [0 ]
251- var m map [string ]interface {}
252- if ival != nil {
253- m = ival .(map [string ]interface {})
254- } else {
255- m = make (map [string ]interface {})
250+ // r is a map, and we don't know it's key. So iterate over it, even though it only has 1 result.
251+ for _ , ival := range r {
252+ var m map [string ]interface {}
253+ if ival != nil {
254+ m = ival .(map [string ]interface {})
255+ } else {
256+ m = make (map [string ]interface {})
257+ }
258+ m ["server_latency" ] = l .ToMap ()
259+ return json .Marshal (m )
256260 }
257- m [ "server_latency" ] = l . ToMap ( )
258- return json . Marshal ( m )
261+ log . Fatal ( "Runtime should never reach here." )
262+ return [] byte ( "" ), fmt . Errorf ( "Runtime should never reach here." )
259263}
260264
261265// This function performs a binary search on the uids slice and returns the
Original file line number Diff line number Diff line change @@ -19,9 +19,9 @@ package query
1919import (
2020 "bytes"
2121 "encoding/gob"
22- "fmt"
2322 "io/ioutil"
2423 "os"
24+ "strings"
2525 "testing"
2626 "time"
2727
@@ -324,7 +324,10 @@ func TestToJson(t *testing.T) {
324324 if err != nil {
325325 t .Error (err )
326326 }
327- fmt .Printf (string (js ))
327+ s := string (js )
328+ if ! strings .Contains (s , "Michonne" ) {
329+ t .Errorf ("Unable to find Michonne in this result: %v" , s )
330+ }
328331}
329332
330333func getProperty (properties []* graph.Property , prop string ) []byte {
You can’t perform that action at this time.
0 commit comments