Skip to content

Commit d1c6732

Browse files
committed
Fix a bug which causes us to return no results in JSON
1 parent 30dc937 commit d1c6732

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

query/query.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff 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

query/query_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ package query
1919
import (
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

330333
func getProperty(properties []*graph.Property, prop string) []byte {

0 commit comments

Comments
 (0)