Skip to content

Commit

Permalink
feature(53): Remove unused service from pkg/pathfinder
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelWritesCode committed Oct 1, 2023
1 parent 0bc216b commit d0b93b1
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 68 deletions.
13 changes: 0 additions & 13 deletions pkg/pathfinder/jsonpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@ import (

"github.com/antchfx/jsonquery"
"github.com/oliveagle/jsonpath"
"github.com/pawelWritesCode/qjson"
"github.com/tidwall/gjson"
)

// QJSONFinder represents implementation of JSON path from https://github.com/pawelWritesCode/qjson library
type QJSONFinder struct{}

// OliveagleJSONFinder represents implementation of JSON path from https://github.com/oliveagle/jsonpath library
type OliveagleJSONFinder struct{}

Expand All @@ -33,10 +29,6 @@ type DynamicJSONPathFinder struct {
antchfxJSONQuery AntchfxJSONQueryFinder
}

func NewQJSONFinder() QJSONFinder {
return QJSONFinder{}
}

func NewOliveagleJSONFinder() OliveagleJSONFinder {
return OliveagleJSONFinder{}
}
Expand All @@ -53,11 +45,6 @@ func NewDynamicJSONPathFinder(gjson GJSONFinder, oliveagleJSONFinder OliveagleJS
return &DynamicJSONPathFinder{gjson: gjson, oliveagleJSONFinder: oliveagleJSONFinder, antchfxJSONQuery: antchfxJSONQuery}
}

// Find obtains data from jsonBytes according to given expr valid with pawelWritesCode/qjson library
func (Q QJSONFinder) Find(expr string, jsonBytes []byte) (any, error) {
return qjson.Resolve(expr, jsonBytes)
}

// Find obtains data from jsonBytes according to given expr.
// It accepts expr in format acceptable by tidwall/gjson, oliveagle/jsonpath or antchfx/jsonquery libraries.
func (d DynamicJSONPathFinder) Find(expr string, jsonBytes []byte) (any, error) {
Expand Down
55 changes: 0 additions & 55 deletions pkg/pathfinder/jsonpath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,61 +47,6 @@ var jsonBytes = []byte(`{
"expensive": 10
}`)

func TestQJSONFinder_Find(t *testing.T) {
type args struct {
expr string
jsonBytes []byte
}
tests := []struct {
name string
args args
want any
wantErr bool
}{
{name: "no expression", args: args{
expr: "",
jsonBytes: []byte(""),
}, want: nil, wantErr: true},
{name: "no jsonBytes", args: args{
expr: "data",
jsonBytes: []byte(""),
}, want: nil, wantErr: true},
{name: "expression points to nothing", args: args{
expr: "data",
jsonBytes: jsonBytes,
}, want: nil, wantErr: true},
{name: "successful fetch data #1", args: args{
expr: "store.book[0].category",
jsonBytes: jsonBytes,
}, want: any("reference"), wantErr: false},
{name: "successful fetch data #2", args: args{
expr: "store.book[1].price",
jsonBytes: jsonBytes,
}, want: any(float64(12.99)), wantErr: false},
{name: "successful fetch data #3", args: args{
expr: "store.book[2].available",
jsonBytes: jsonBytes,
}, want: any(true), wantErr: false},
{name: "successful fetch data #4", args: args{
expr: "store.bicycle",
jsonBytes: jsonBytes,
}, want: any(map[string]any{"color": "red", "price": float64(19.95)}), wantErr: false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Q := QJSONFinder{}
got, err := Q.Find(tt.args.expr, tt.args.jsonBytes)
if (err != nil) != tt.wantErr {
t.Errorf("Find() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("Find() got = %v, want %v", got, tt.want)
}
})
}
}

func TestOliveagleJSONFInder_Find(t *testing.T) {
type args struct {
expr string
Expand Down

0 comments on commit d0b93b1

Please sign in to comment.