forked from PaesslerAG/jsonpath
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjsonpath_match_path_test.go
More file actions
45 lines (38 loc) · 878 Bytes
/
Copy pathjsonpath_match_path_test.go
File metadata and controls
45 lines (38 loc) · 878 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package jsonpath
import (
"encoding/json"
"fmt"
"github.com/stretchr/testify/assert"
"io/ioutil"
"testing"
)
func setup(file string) map[string]interface{} {
raw, _ := ioutil.ReadFile(file)
var data map[string]interface{}
json.Unmarshal(raw, &data)
return data
}
func TestMatchedPath(t *testing.T) {
data := setup("petstore.json")
result, err := Get("$.paths.*.*.parameters[*]", data)
if (err != nil) {
fmt.Println(err.Error())
}
switch res := result.(type) {
case []interface{}:
pathValues, _ := result.([]interface{})
for _, pathValue := range pathValues {
pv, ok := pathValue.(PathValue)
assert.True(t, ok)
fmt.Println(pv.Path)
fmt.Println(pv.Value)
}
case interface{}:
pv, ok := result.(*PathValue)
assert.True(t, ok)
fmt.Println(pv.Path)
fmt.Println(pv.Value)
default:
fmt.Errorf("Unknown type %T of result", res)
}
}