(t *testing.T)
| 136 | } |
| 137 | |
| 138 | func TestStructInput(t *testing.T) { |
| 139 | |
| 140 | storeData := store{ |
| 141 | Name: "jsonpath", |
| 142 | Book: []book{ |
| 143 | {"reference", "Nigel Rees", "Sayings of the Centurey", 8.95}, |
| 144 | {"fiction", "Evelyn Waugh", "Sword of Honour", 12.99}, |
| 145 | {"fiction", "Herman Melville", "Moby Dick", 8.99}, |
| 146 | }, |
| 147 | Bicycle: []bicycle{ |
| 148 | {"red", 19.95, true}, |
| 149 | {"green", 20.01, false}, |
| 150 | }, |
| 151 | Labels: map[string]int{ |
| 152 | "engieer": 10, |
| 153 | "web/html": 15, |
| 154 | "k8s-app": 20, |
| 155 | }, |
| 156 | Employees: map[empName]job{ |
| 157 | "jason": "manager", |
| 158 | "dan": "clerk", |
| 159 | }, |
| 160 | } |
| 161 | |
| 162 | storeTests := []jsonpathTest{ |
| 163 | {"plain", "hello jsonpath", nil, "hello jsonpath", false}, |
| 164 | {"recursive", "{..}", []int{1, 2, 3}, "[1 2 3]", false}, |
| 165 | {"filter", "{[?(@<5)]}", []int{2, 6, 3, 7}, "2 3", false}, |
| 166 | {"quote", `{"{"}`, nil, "{", false}, |
| 167 | {"union", "{[1,3,4]}", []int{0, 1, 2, 3, 4}, "1 3 4", false}, |
| 168 | {"array", "{[0:2]}", []string{"Monday", "Tudesday"}, "Monday Tudesday", false}, |
| 169 | {"variable", "hello {.Name}", storeData, "hello jsonpath", false}, |
| 170 | {"dict/", "{$.Labels.web/html}", storeData, "15", false}, |
| 171 | {"dict/", "{$.Employees.jason}", storeData, "manager", false}, |
| 172 | {"dict/", "{$.Employees.dan}", storeData, "clerk", false}, |
| 173 | {"dict-", "{.Labels.k8s-app}", storeData, "20", false}, |
| 174 | {"nest", "{.Bicycle[*].Color}", storeData, "red green", false}, |
| 175 | {"allarray", "{.Book[*].Author}", storeData, "Nigel Rees Evelyn Waugh Herman Melville", false}, |
| 176 | {"allfileds", "{.Bicycle.*}", storeData, "{red 19.95 true} {green 20.01 false}", false}, |
| 177 | {"recurfileds", "{..Price}", storeData, "8.95 12.99 8.99 19.95 20.01", false}, |
| 178 | {"lastarray", "{.Book[-1:]}", storeData, |
| 179 | "{Category: fiction, Author: Herman Melville, Title: Moby Dick, Price: 8.99}", false}, |
| 180 | {"recurarray", "{..Book[2]}", storeData, |
| 181 | "{Category: fiction, Author: Herman Melville, Title: Moby Dick, Price: 8.99}", false}, |
| 182 | {"bool", "{.Bicycle[?(@.IsNew==true)]}", storeData, "{red 19.95 true}", false}, |
| 183 | } |
| 184 | testJSONPath(storeTests, false, t) |
| 185 | |
| 186 | missingKeyTests := []jsonpathTest{ |
| 187 | {"nonexistent field", "{.hello}", storeData, "", false}, |
| 188 | } |
| 189 | testJSONPath(missingKeyTests, true, t) |
| 190 | |
| 191 | failStoreTests := []jsonpathTest{ |
| 192 | {"invalid identifier", "{hello}", storeData, "unrecognized identifier hello", false}, |
| 193 | {"nonexistent field", "{.hello}", storeData, "hello is not found", false}, |
| 194 | {"invalid array", "{.Labels[0]}", storeData, "map[string]int is not array or slice", false}, |
| 195 | {"invalid filter operator", "{.Book[?(@.Price<>10)]}", storeData, "unrecognized filter operator <>", false}, |
nothing calls this directly
no test coverage detected