(t *testing.T)
| 374 | } |
| 375 | |
| 376 | func TestNegativeIndex(t *testing.T) { |
| 377 | var input = []byte( |
| 378 | `{ |
| 379 | "apiVersion": "v1", |
| 380 | "kind": "Pod", |
| 381 | "spec": { |
| 382 | "containers": [ |
| 383 | { |
| 384 | "image": "radial/busyboxplus:curl", |
| 385 | "name": "fake0" |
| 386 | }, |
| 387 | { |
| 388 | "image": "radial/busyboxplus:curl", |
| 389 | "name": "fake1" |
| 390 | }, |
| 391 | { |
| 392 | "image": "radial/busyboxplus:curl", |
| 393 | "name": "fake2" |
| 394 | }, |
| 395 | { |
| 396 | "image": "radial/busyboxplus:curl", |
| 397 | "name": "fake3" |
| 398 | }]}}`) |
| 399 | |
| 400 | var data interface{} |
| 401 | err := json.Unmarshal(input, &data) |
| 402 | if err != nil { |
| 403 | t.Fatal(err) |
| 404 | } |
| 405 | |
| 406 | testJSONPath( |
| 407 | []jsonpathTest{ |
| 408 | { |
| 409 | "test containers[0], it equals containers[0]", |
| 410 | `{.spec.containers[0].name}`, |
| 411 | data, |
| 412 | "fake0", |
| 413 | false, |
| 414 | }, |
| 415 | { |
| 416 | "test containers[0:0], it equals the empty set", |
| 417 | `{.spec.containers[0:0].name}`, |
| 418 | data, |
| 419 | "", |
| 420 | false, |
| 421 | }, |
| 422 | { |
| 423 | "test containers[0:-1], it equals containers[0:3]", |
| 424 | `{.spec.containers[0:-1].name}`, |
| 425 | data, |
| 426 | "fake0 fake1 fake2", |
| 427 | false, |
| 428 | }, |
| 429 | { |
| 430 | "test containers[-1:0], expect error", |
| 431 | `{.spec.containers[-1:0].name}`, |
| 432 | data, |
| 433 | "", |
nothing calls this directly
no test coverage detected