()
| 233 | }, |
| 234 | "data2": [ |
| 235 | 1,2,3 |
| 236 | ] |
| 237 | }, |
| 238 | "myref": { |
| 239 | "data": "test" |
| 240 | } |
| 241 | }); |
| 242 | |
| 243 | assert_eq!( |
| 244 | fetch_reference_value(&json, &Some("/test/data1/value".into()))?, |
| 245 | Value::Number(serde_json::Number::from(42)) |
| 246 | ); |
| 247 | |
| 248 | assert_eq!(fetch_reference_value(&json, &Some("/test/data1".into()))?, json!({ "value": 42 })); |
| 249 | |
| 250 | let path: &str = "/test/not_existing_path"; |
| 251 | let failed_test = fetch_reference_value(&json, &Some(path.into())); |
| 252 | let err = failed_test.expect_err("Should be an error"); |
| 253 | assert_eq!( |
| 254 | err.to_string(), |
| 255 | "Key `not_existing_path` was not found in json part `{\"data1\":{\"value\":42},\"data2\":[1,2,3]}`." |
| 256 | ); |
| 257 | |
| 258 | Ok(()) |
| 259 | } |
| 260 | |
| 261 | #[test] |
| 262 | fn resolve_refs_test_0() -> Result<(), anyhow::Error> { |
| 263 | let json = json!({ |
| 264 | "test": { |
| 265 | "$ref": "#/myref" |
| 266 | }, |
| 267 | "myref": { |
| 268 | "data": "test" |
| 269 | } |
nothing calls this directly
no test coverage detected