Skip to content

Commit 7560612

Browse files
committed
test(mmds): Add test for string including escapes
test_get_value() lacked coverage for strings. Instead of merely adding a normal string test, adds a test for a string including escapes. Signed-off-by: Takahiro Itazuri <itazur@amazon.com>
1 parent f94dac8 commit 7560612

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/vmm/src/mmds/data_store.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,8 @@ mod tests {
352352
],
353353
"member": false,
354354
"shares_percentage": 12.12,
355-
"balance": -24
355+
"balance": -24,
356+
"json_string": "{\n \"hello\": \"world\"\n}"
356357
}"#;
357358
let data_store: Value = serde_json::from_str(data).unwrap();
358359
mmds.put_data(data_store).unwrap();
@@ -492,6 +493,18 @@ mod tests {
492493
.to_string(),
493494
MmdsDatastoreError::UnsupportedValueType.to_string()
494495
);
496+
497+
// Retrieve a string including escapes.
498+
assert_eq!(
499+
mmds.get_value("/json_string".to_string(), OutputFormat::Json)
500+
.unwrap(),
501+
r#""{\n \"hello\": \"world\"\n}""#
502+
);
503+
assert_eq!(
504+
mmds.get_value("/json_string".to_string(), OutputFormat::Imds)
505+
.unwrap(),
506+
"{\n \"hello\": \"world\"\n}"
507+
)
495508
}
496509

497510
#[test]

0 commit comments

Comments
 (0)