Skip to content

Commit

Permalink
fix(test): add magic number check on image tests
Browse files Browse the repository at this point in the history
Signed-off-by: WoodenMaiden <[email protected]>
  • Loading branch information
WoodenMaiden committed Oct 24, 2023
1 parent 7aba762 commit 1e8b62b
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions initramfs/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ impl Image {
#[cfg(test)]
mod test {
use std::env;
use std::io;
use std::io::Read;
use std::{error::Error, result::Result};

use super::Image;
Expand Down Expand Up @@ -211,12 +213,6 @@ mod test {
assert_eq!(image2.tag(), "latest");
}

#[test]
pub fn invalid_image_name() {
let image = Image::new("invalid_image_name");
assert!(image.is_err());
}

#[test]
pub fn test_initramfs_export() {
// setup
Expand Down Expand Up @@ -249,11 +245,21 @@ mod test {
)
.is_ok());

let generated_file = File::open(&generated_filename);

assert!(std::path::Path::new(&generated_filename).exists());
assert!(File::open(&generated_filename).is_ok());
assert!(generated_file.is_ok());

let magic_number = generated_file
.unwrap()
.bytes()
.take(2)
.map(|b| b.unwrap())
.collect::<Vec<u8>>();

let kind = infer::get_from_path(&generated_filename).unwrap().unwrap();
assert_eq!(kind.matcher_type(), infer::MatcherType::Archive);
assert_eq!(magic_number, &[0x1F, 0x8b]);

// clean
files.iter().for_each(|f| std::fs::remove_file(f).unwrap());
Expand Down

0 comments on commit 1e8b62b

Please sign in to comment.