Skip to content

Commit 6ae32a0

Browse files
feat: add query options option (#18)
add query options option
1 parent c1ea01a commit 6ae32a0

File tree

4 files changed

+52
-16
lines changed

4 files changed

+52
-16
lines changed

.github/workflows/pull_request.yaml

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,5 @@ jobs:
6161
id: changes
6262
run: |
6363
echo "::set-output name=changes::$(git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep 'go.mod\|.go$' | grep -v _test.go$ | xargs)"
64-
dry_run:
65-
runs-on: ubuntu-latest
66-
needs: release_check
67-
if: ${{needs.release_check.outputs.changes}}
68-
outputs:
69-
version: ${{ steps.release.outputs.version }}
70-
steps:
71-
- uses: actions/checkout@master
72-
- uses: go-semantic-release/action@v1
73-
id: release
74-
with:
75-
github-token: ${{ secrets.GITHUB_TOKEN }}
76-
allow-initial-development-versions: true
77-
force-bump-patch-version: true
78-
dry: true
64+
echo "${{ steps.changes.outputs.changes}}"
65+

.github/workflows/push_main.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ jobs:
7171
verbose: true
7272
release_check:
7373
runs-on: ubuntu-latest
74+
needs: [test, lint]
7475
outputs:
7576
changes: ${{ steps.changes.outputs.changes}}
7677
steps:
@@ -89,7 +90,7 @@ jobs:
8990
outputs:
9091
version: ${{ steps.release.outputs.version }}
9192
steps:
92-
- uses: actions/checkout@master
93+
- uses: actions/checkout@v2
9394
- uses: go-semantic-release/action@v1
9495
id: release
9596
with:

options.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package jsonpath
22

33
import (
4+
"github.com/evilmonkeyinc/jsonpath/option"
45
"github.com/evilmonkeyinc/jsonpath/script"
56
)
67

@@ -27,3 +28,13 @@ func ScriptEngine(engine script.Engine) Option {
2728
return nil
2829
})
2930
}
31+
32+
// QueryOptions allows you to set the query options for the JSONPath selector
33+
func QueryOptions(options *option.QueryOptions) Option {
34+
return OptionFunction(func(selector *Selector) error {
35+
if selector.Options == nil {
36+
selector.Options = options
37+
}
38+
return nil
39+
})
40+
}

options_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"testing"
66

7+
"github.com/evilmonkeyinc/jsonpath/option"
78
"github.com/stretchr/testify/assert"
89
)
910

@@ -71,3 +72,39 @@ func Test_ScriptEngine(t *testing.T) {
7172
})
7273

7374
}
75+
76+
func Test_QueryOptions(t *testing.T) {
77+
78+
t.Run("first", func(t *testing.T) {
79+
80+
input := &option.QueryOptions{AllowMapReferenceByIndex: true, AllowStringReferenceByIndex: true}
81+
option := QueryOptions(input)
82+
selector := &Selector{}
83+
84+
err := option.Apply(selector)
85+
assert.Nil(t, err)
86+
assert.Equal(t, input, selector.Options)
87+
88+
})
89+
t.Run("second", func(t *testing.T) {
90+
91+
input1 := &option.QueryOptions{AllowMapReferenceByIndex: true, AllowStringReferenceByIndex: true}
92+
input2 := &option.QueryOptions{AllowMapReferenceByIndex: false, AllowStringReferenceByIndex: false}
93+
94+
option1 := QueryOptions(input1)
95+
option2 := QueryOptions(input2)
96+
97+
selector := &Selector{}
98+
99+
err := option1.Apply(selector)
100+
assert.Nil(t, err)
101+
102+
err = option2.Apply(selector)
103+
assert.Nil(t, err)
104+
105+
assert.Equal(t, input1, selector.Options)
106+
assert.NotEqual(t, input2, selector.Options)
107+
108+
})
109+
110+
}

0 commit comments

Comments
 (0)