Skip to content

Commit

Permalink
test: add unpack negative tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tangtang95 committed May 18, 2024
1 parent 640c885 commit 979e447
Showing 1 changed file with 44 additions and 3 deletions.
47 changes: 44 additions & 3 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use assert_fs::{
use hex_literal::hex;

#[test]
pub fn not_exists_file() {
pub fn pack_not_exists_file() {
let dir = assert_fs::TempDir::new().unwrap();
iroga_cmd()
.current_dir(dir.path())
Expand All @@ -19,7 +19,7 @@ pub fn not_exists_file() {
}

#[test]
pub fn not_dir() {
pub fn pack_not_dir() {
let dir = assert_fs::TempDir::new().unwrap();
dir.child("not_dir").touch().unwrap();
iroga_cmd()
Expand All @@ -32,7 +32,7 @@ pub fn not_dir() {
}

#[test]
pub fn output_file_already_exists() {
pub fn pack_output_file_already_exists() {
let dir = assert_fs::TempDir::new().unwrap();
dir.child("dir/file.txt").touch().unwrap();
dir.child("dir.iro").touch().unwrap();
Expand Down Expand Up @@ -103,6 +103,47 @@ pub fn pack_multiple_files() {
dir.close().unwrap();
}

#[test]
pub fn unpack_not_exists_file() {
let dir = assert_fs::TempDir::new().unwrap();
iroga_cmd()
.current_dir(dir.path())
.arg("unpack")
.arg(dir.path().join("not_exists_file.iro"))
.assert()
.failure()
.code(1);
assert!(!dir.child("not_exists_file.iro").exists());
}

#[test]
pub fn unpack_not_file() {
let dir = assert_fs::TempDir::new().unwrap();
dir.child("not_file/is_file").touch().unwrap();
iroga_cmd()
.arg("unpack")
.arg(dir.path().join("not_file"))
.assert()
.failure()
.code(1);
assert!(dir.child("not_file").is_dir());
}

#[test]
pub fn unpack_output_path_already_exists() {
let dir = assert_fs::TempDir::new().unwrap();
dir.child("dir/file.txt").touch().unwrap();
dir.child("dir.iro").touch().unwrap();
iroga_cmd()
.current_dir(dir.path())
.arg("unpack")
.arg("dir.iro")
.assert()
.failure()
.code(1)
.stderr(predicates::str::contains("output path already exists"));
}

#[test]
pub fn unpack_single_file() {
let iro_bytes: &[u8] = &hex!(
Expand Down

0 comments on commit 979e447

Please sign in to comment.