summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorAndreas Hochsteger <andreas.hochsteger@gmail.com>2022-12-29 23:01:05 +0100
committerGitHub <noreply@github.com>2022-12-29 22:01:05 +0000
commite045af5d9c9106594bc2a5f609b14dbc603f7253 (patch)
tree7591781fd92cafd19bd5483b8e1c2fedae7ebc85 /internal
parentf8a636898f316ce0d4a9a12335e9633c218f9e8a (diff)
Add coll.JQ using gojq library (#1585)
* feat: add coll.JQ using gojq library * fix: jq function naming (gojq -> jq) * test: add tests (take from jsonpath_test.go) * chore: add TODO for nil values (are they allowed?) * refactor: use fmt.Errorf instead of errors.Wrapf Co-authored-by: Dave Henderson <dhenderson@gmail.com> * fix: wrong alias for coll.JQ Co-authored-by: Dave Henderson <dhenderson@gmail.com> * docs: add links to JQ Co-authored-by: Dave Henderson <dhenderson@gmail.com> * test: add assertions after json marshal/unmarshal Co-authored-by: Dave Henderson <dhenderson@gmail.com> * refactor: use fmt.Errorf instead of errors.Wrapf Co-authored-by: Dave Henderson <dhenderson@gmail.com> * fix: test syntax and null handling * docs: improve documentation * docs: add blank line * Support cancellation Signed-off-by: Dave Henderson <dhenderson@gmail.com> * Support (almost) all types, not just map[string]interface{} and []interface{} Signed-off-by: Dave Henderson <dhenderson@gmail.com> * add an integration test for coll.JQ Signed-off-by: Dave Henderson <dhenderson@gmail.com> Signed-off-by: Dave Henderson <dhenderson@gmail.com> Co-authored-by: Andreas Hochsteger <andreas.hochsteger@oeamtc.at> Co-authored-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'internal')
-rw-r--r--internal/tests/integration/collection_test.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/internal/tests/integration/collection_test.go b/internal/tests/integration/collection_test.go
index cc83e14d..5175ef64 100644
--- a/internal/tests/integration/collection_test.go
+++ b/internal/tests/integration/collection_test.go
@@ -98,3 +98,8 @@ func TestColl_Pick(t *testing.T) {
func TestColl_Omit(t *testing.T) {
inOutTest(t, `{{ $data := dict "foo" 1 "bar" 2 "baz" 3 }}{{ coll.Omit "foo" "baz" $data }}`, "map[bar:2]")
}
+
+func TestColl_JQ(t *testing.T) {
+ inOutTest(t, `{{ coll.JQ ".foo" (dict "foo" 1 "bar" 2 "baz" 3) }}`, "1")
+ inOutTest(t, `{{ coll.Slice "one" 2 "three" 4.0 | jq ".[2]" }}`, `three`)
+}