-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add smoke test for "nydus-image inspect"
We use the output result of request_mode for verification. In ./tests/texture/image-inspect/*.result, there stores the output result of executing cmd `nydus-image inspect -B ./tests/texture/bootstrap/image_v2.boot -R *` with `nydus-image` that has not been refactored. Then we load the result and compare them with result using the refactored `nydus-image` to do the smoke test. Signed-off-by: YushuoEdge <[email protected]>
- Loading branch information
1 parent
c4b51fa
commit 2ab5550
Showing
5 changed files
with
235 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
use nydus_utils::exec; | ||
use serde_json::Value::{self, Null}; | ||
use std::{fs::File, io::Read}; | ||
|
||
pub fn test_image_inspect_cmd(cmd: &str, bootstrap_path: &str) { | ||
let nydus_image = | ||
std::env::var("NYDUS_IMAGE").unwrap_or_else(|_| String::from("./target/debug/nydus-image")); | ||
|
||
let output = exec( | ||
format!("{} inspect -B {} -R {}", nydus_image, bootstrap_path, cmd).as_str(), | ||
true, | ||
b"", | ||
) | ||
.unwrap(); | ||
let mut expected = String::new(); | ||
|
||
let mut texture = File::open(format!("./tests/texture/image-inspect/{}.result", cmd)).unwrap(); | ||
texture.read_to_string(&mut expected).unwrap(); | ||
is_right(cmd, output, expected); | ||
} | ||
|
||
fn is_right(cmd: &str, output: String, expected: String) { | ||
match cmd { | ||
"stats" => is_right_stats(output, expected), | ||
"prefetch" => is_right_prefetch(output, expected), | ||
"blobs" => is_right_blobs(output, expected), | ||
_ => println!("This cmd is not supported now!"), | ||
} | ||
} | ||
|
||
fn is_right_stats(output: String, expected: String) { | ||
let output_value: Value = serde_json::from_str(output.as_str()).unwrap(); | ||
let expected_value: Value = serde_json::from_str(expected.as_str()).unwrap(); | ||
assert_eq!( | ||
output_value["inodes_count".to_string()], | ||
expected_value["inodes_count".to_string()] | ||
); | ||
} | ||
|
||
fn is_right_prefetch(output: String, expected: String) { | ||
let output_value: Vec<Value> = serde_json::from_str(output.as_str()).unwrap(); | ||
let expected_value: Vec<Value> = serde_json::from_str(expected.as_str()).unwrap(); | ||
|
||
assert_eq!(output_value.len(), expected_value.len()); | ||
for index in 0..expected_value.len() { | ||
let expected_v = expected_value.get(index).unwrap(); | ||
let mut matched = false; | ||
for output_v in output_value.iter() { | ||
if output_v["inode"] == expected_v["inode"] { | ||
assert_eq!(output_v["path"], expected_v["path"]); | ||
matched = true; | ||
break; | ||
} | ||
} | ||
assert!(matched); | ||
} | ||
} | ||
|
||
fn is_right_blobs(output: String, expected: String) { | ||
let output_value: Vec<Value> = serde_json::from_str(output.as_str()).unwrap(); | ||
let expected_value: Vec<Value> = serde_json::from_str(expected.as_str()).unwrap(); | ||
|
||
assert_eq!(output_value.len(), expected_value.len()); | ||
for index in 0..expected_value.len() { | ||
let expected_v = expected_value.get(index).unwrap(); | ||
let mut matched = false; | ||
for output_v in output_value.iter() { | ||
if output_v["blob_id"] == expected_v["blob_id"] { | ||
if expected_v["compressed_size"] == Null { | ||
assert_eq!(0_i32, output_v["compressed_size"]); | ||
} else { | ||
assert_eq!(expected_v["compressed_size"], output_v["compressed_size"]) | ||
} | ||
|
||
if expected_v["decompressed_size"] == Null { | ||
assert_eq!(0_i32, output_v["decompressed_size"]); | ||
} else { | ||
assert_eq!( | ||
expected_v["decompressed_size"], | ||
output_v["decompressed_size"] | ||
); | ||
} | ||
|
||
assert_eq!(expected_v["readahead_offset"], output_v["readahead_offset"]); | ||
assert_eq!(expected_v["readahead_size"], output_v["readahead_size"]); | ||
|
||
matched = true; | ||
break; | ||
} | ||
} | ||
|
||
assert!(matched); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
[ | ||
{ | ||
"blob_id":"7fe907a0c9c7f35538f23f40baae5f2e8d148a3a6186f0f443f62d04b5e2d731", | ||
"compressed_size":null, | ||
"decompressed_size":null, | ||
"readahead_offset":0, | ||
"readahead_size":0 | ||
}, | ||
{ | ||
"blob_id":"c7f5eac86f051f76ac2e73a04972d3b7c68df2f35f024210176396146528af49", | ||
"compressed_size":null, | ||
"decompressed_size":null, | ||
"readahead_offset":0, | ||
"readahead_size":0 | ||
}, | ||
{ | ||
"blob_id":"69413c426fe9a8ccda13b6fa0ff714d888c658c619d02f1919816c874dd58f3b", | ||
"compressed_size":null, | ||
"decompressed_size":null, | ||
"readahead_offset":0, | ||
"readahead_size":0 | ||
}, | ||
{ | ||
"blob_id":"6c43518f1a9a0ad1bfeece04a47aec7ea7c4eb548b9611d72c7c65be304d12e2", | ||
"compressed_size":null, | ||
"decompressed_size":null, | ||
"readahead_offset":0, | ||
"readahead_size":0 | ||
}, | ||
{ | ||
"blob_id":"c9cab663e59704f082a1f8884b84597fe413c02b513faf29f468e020b8fc4e73", | ||
"compressed_size":null, | ||
"decompressed_size":null, | ||
"readahead_offset":0, | ||
"readahead_size":0 | ||
}, | ||
{ | ||
"blob_id":"fdd69d7b4b1323933ba02f1b5283af3f1725c4438f5e160abe5d8de91450171a", | ||
"compressed_size":null, | ||
"decompressed_size":null, | ||
"readahead_offset":0, | ||
"readahead_size":0 | ||
}, | ||
{ | ||
"blob_id":"556d1d13c5dd752ca8713f77fdbf8cb90d14d2f5c1d16cfdfa82d371c698fe0f", | ||
"compressed_size":null, | ||
"decompressed_size":null, | ||
"readahead_offset":0, | ||
"readahead_size":0 | ||
}, | ||
{ | ||
"blob_id":"5162ec807e5c3d98819913d9453bb72311815126effe9438e7928360694df46f", | ||
"compressed_size":null, | ||
"decompressed_size":null, | ||
"readahead_offset":0, | ||
"readahead_size":0 | ||
}, | ||
{ | ||
"blob_id":"55095f163928ef439f65f3273358ced8f79a275fff83a4d843ebf4f155b145aa", | ||
"compressed_size":null, | ||
"decompressed_size":null, | ||
"readahead_offset":0, | ||
"readahead_size":0 | ||
}, | ||
{ | ||
"blob_id":"16c95369ce1f06d73a71f83dbf1749a3b4779c818132465c3277aca1de64c411", | ||
"compressed_size":null, | ||
"decompressed_size":null, | ||
"readahead_offset":0, | ||
"readahead_size":0 | ||
}, | ||
{ | ||
"blob_id":"8b83283b43ce86cd2b394d1f6a8176fed66223e057fb87de7e57bcd7325a2142", | ||
"compressed_size":null, | ||
"decompressed_size":null, | ||
"readahead_offset":0, | ||
"readahead_size":0 | ||
}, | ||
{ | ||
"blob_id":"c9b22bc8909a271b762a7f4492a3d257eeb01741a105a639a64132f505b316ea", | ||
"compressed_size":null, | ||
"decompressed_size":null, | ||
"readahead_offset":0, | ||
"readahead_size":0 | ||
}, | ||
{ | ||
"blob_id":"cc3c05c66ca02f1e145c842fd13d210ce05a482700ff5e80222957c27c7ec2f0", | ||
"compressed_size":null, | ||
"decompressed_size":null, | ||
"readahead_offset":0, | ||
"readahead_size":0 | ||
}, | ||
{ | ||
"blob_id":"0ef1b08e3b4010d5cd634cf509d0043dc6d0944f643a4fa4348efc65210f0d2b", | ||
"compressed_size":null, | ||
"decompressed_size":null, | ||
"readahead_offset":0, | ||
"readahead_size":0 | ||
}, | ||
{ | ||
"blob_id":"073c6c98265ed3c848f2c856af0eddf5b8ddcb36407d418059452be32d654952", | ||
"compressed_size":null, | ||
"decompressed_size":null, | ||
"readahead_offset":0, | ||
"readahead_size":0 | ||
}, | ||
{ | ||
"blob_id":"b0f406bbb861055ce702c3b4e529ce4d29e504db91db58cf992cbd8c3d260518", | ||
"compressed_size":null, | ||
"decompressed_size":null, | ||
"readahead_offset":0, | ||
"readahead_size":0 | ||
}, | ||
{ | ||
"blob_id":"475690527e1a4e4dac7be65ac66346e5e82597a83aedf4693fdd383a325ad209", | ||
"compressed_size":null, | ||
"decompressed_size":null, | ||
"readahead_offset":0, | ||
"readahead_size":0 | ||
}, | ||
{ | ||
"blob_id":"fc877ac9133dd30ba549aabb6a605e37317a8ef7a2f2fd91a2b85e6fd85280a6", | ||
"compressed_size":null, | ||
"decompressed_size":null, | ||
"readahead_offset":0, | ||
"readahead_size":0 | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[{"inode":1,"path":"/"}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"inodes_count":43082} |