Skip to content

Commit 4c777d6

Browse files
authored
feat: add github action validators, ToString(), cleanup interface (#7)
* chore: ToString() added which effectively pretty-prints (formats) the original jsonpath * chore: add test.yaml * chore: grammar * chore: adjust on * chore: clone with submodules
1 parent 1eac720 commit 4c777d6

File tree

10 files changed

+371
-51
lines changed

10 files changed

+371
-51
lines changed

.github/workflows/test.yaml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Test
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
types:
8+
- opened
9+
- edited
10+
- synchronize
11+
- reopened
12+
13+
jobs:
14+
build:
15+
name: Conventional pull request names
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
19+
- uses: amannn/action-semantic-pull-request@0723387faaf9b38adef4775cd42cfd5155ed6017 # v5.5.3
20+
env:
21+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22+
build-test:
23+
name: Build & Test
24+
if: ${{ github.event.pull_request.draft == false }}
25+
runs-on: ubuntu-latest
26+
steps:
27+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
28+
with:
29+
submodules: true
30+
- name: Set up Go
31+
uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
32+
with:
33+
go-version-file: "go.mod"
34+
- name: Set up Node
35+
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
36+
with:
37+
node-version: "18.x"
38+
registry-url: "https://registry.npmjs.org"
39+
- name: Set up gotestfmt
40+
run: go install github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@latest
41+
- name: Build
42+
run: go build ./...
43+
- run: go test -json -v -p 1 ./... | gotestfmt

integration_test.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,17 @@ func TestJSONPathComplianceTestSuite(t *testing.T) {
5454
// Test case for a valid selector
5555
jp, err := jsonpath.NewPath(test.Selector)
5656
if test.InvalidSelector {
57-
require.Error(t, err, "Expected an error for invalid selector, but got none")
57+
require.Error(t, err, "Expected an error for invalid selector, but got none for path", jp.String())
5858
return
5959
} else {
60-
require.NoError(t, err, "Failed to parse JSONPath selector")
60+
require.NoError(t, err, "Failed to parse JSONPath selector", jp.String())
6161
}
62+
63+
// expect stability of ToString()
64+
stringified := jp.String()
65+
recursive, err := jsonpath.NewPath(stringified)
66+
require.NoError(t, err, "Failed to parse recursive JSONPath selector. expected=%s got=%s", test.Selector, jp.String())
67+
require.Equal(t, stringified, recursive.String(), "JSONPath selector does not match test case")
6268
// interface{} to yaml.Node
6369
toYAML := func(i interface{}) *yaml.Node {
6470
o, err := yaml.Marshal(i)

0 commit comments

Comments
 (0)