Verifies: SYS-REQ-069 [boundary] Set with multi-level path where intermediate levels exist but leaf does not.
(t *testing.T)
| 361 | // Verifies: SYS-REQ-069 [boundary] |
| 362 | // Set with multi-level path where intermediate levels exist but leaf does not. |
| 363 | func TestSetNestedMutation(t *testing.T) { |
| 364 | data := `{"a":{"b":1}}` |
| 365 | got, err := Set([]byte(data), []byte(`"newval"`), "a", "c") |
| 366 | if err != nil { |
| 367 | t.Fatalf("Set nested mutation returned error: %v", err) |
| 368 | } |
| 369 | // The new key "c" should be created inside "a" |
| 370 | val, _, _, err := Get(got, "a", "c") |
| 371 | if err != nil { |
| 372 | t.Fatalf("Get on Set result failed: %v", err) |
| 373 | } |
| 374 | if string(val) != "newval" { |
| 375 | t.Fatalf("Set nested mutation: got %q, want %q", string(val), "newval") |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | // Verifies: SYS-REQ-070 [boundary] |
| 380 | // Set without any path shall return KeyPathNotFoundError. |