Skip to content
Snippets Groups Projects
Unverified Commit d1c6732d authored by Manish R Jain's avatar Manish R Jain
Browse files

Fix a bug which causes us to return no results in JSON

parent 30dc9371
No related branches found
No related tags found
No related merge requests found
......@@ -247,15 +247,19 @@ func (g *SubGraph) ToJson(l *Latency) (js []byte, rerr error) {
log.Fatal("We don't currently support more than 1 uid at root.")
}
ival := r[0]
var m map[string]interface{}
if ival != nil {
m = ival.(map[string]interface{})
} else {
m = make(map[string]interface{})
// r is a map, and we don't know it's key. So iterate over it, even though it only has 1 result.
for _, ival := range r {
var m map[string]interface{}
if ival != nil {
m = ival.(map[string]interface{})
} else {
m = make(map[string]interface{})
}
m["server_latency"] = l.ToMap()
return json.Marshal(m)
}
m["server_latency"] = l.ToMap()
return json.Marshal(m)
log.Fatal("Runtime should never reach here.")
return []byte(""), fmt.Errorf("Runtime should never reach here.")
}
// This function performs a binary search on the uids slice and returns the
......
......@@ -19,9 +19,9 @@ package query
import (
"bytes"
"encoding/gob"
"fmt"
"io/ioutil"
"os"
"strings"
"testing"
"time"
......@@ -324,7 +324,10 @@ func TestToJson(t *testing.T) {
if err != nil {
t.Error(err)
}
fmt.Printf(string(js))
s := string(js)
if !strings.Contains(s, "Michonne") {
t.Errorf("Unable to find Michonne in this result: %v", s)
}
}
func getProperty(properties []*graph.Property, prop string) []byte {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment