From f8d4b7d1c01eecb54edc4169d6b8a0d3c39a730c Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sun, 6 Oct 2019 22:35:05 -0700 Subject: support basic json filtering and selection --- weed/query/json/query_json_test.go | 65 +++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) (limited to 'weed/query/json/query_json_test.go') diff --git a/weed/query/json/query_json_test.go b/weed/query/json/query_json_test.go index 7ad837360..621d4f548 100644 --- a/weed/query/json/query_json_test.go +++ b/weed/query/json/query_json_test.go @@ -58,7 +58,7 @@ func TestGjson(t *testing.T) { projections := []string{"quiz","fruit"} gjson.ForEachLine(data, func(line gjson.Result) bool{ - println(line.String()) + println(line.Raw) println("+++++++++++") results := gjson.GetMany(line.Raw, projections...) for _, result := range results { @@ -71,3 +71,66 @@ func TestGjson(t *testing.T) { } + +func TestJsonQueryRow(t *testing.T) { + + data := ` + { + "fruit": "Bl\"ue", + "size": 6, + "quiz": "green" + } + +` + selections := []string{"fruit", "size"} + + isFiltered, values := QueryJson(data, selections, Query{ + Field: "quiz", + Op: "=", + Value: "green", + }) + + if !isFiltered { + t.Errorf("should have been filtered") + } + + if values == nil { + t.Errorf("values should have been returned") + } + + buf := ToJson(nil, selections, values) + println(string(buf)) + +} + +func TestJsonQueryNumber(t *testing.T) { + + data := ` + { + "fruit": "Bl\"ue", + "size": 6, + "quiz": "green" + } + +` + selections := []string{"fruit", "quiz"} + + isFiltered, values := QueryJson(data, selections, Query{ + Field: "size", + Op: ">=", + Value: "6", + }) + + if !isFiltered { + t.Errorf("should have been filtered") + } + + if values == nil { + t.Errorf("values should have been returned") + } + + buf := ToJson(nil, selections, values) + println(string(buf)) + +} + -- cgit v1.2.3