Skip to content

Commit

Permalink
refactor: imtegration test to use a temp dir for output file
Browse files Browse the repository at this point in the history
  • Loading branch information
josecelano committed Oct 9, 2024
1 parent fc38b74 commit 8e1678a
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/target
be2json
output.json
output.json
80 changes: 78 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ thiserror = "1.0.64"

[dev-dependencies]
assert_cmd = "2.0"
tempfile = "3.13.0"
1 change: 0 additions & 1 deletion output.json

This file was deleted.

2 changes: 2 additions & 0 deletions project-words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ llee
llleee
spame
spamee
tempdir
tempfile
thiserror
8 changes: 4 additions & 4 deletions src/parsers/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use std::io::{self, Read};

use crate::rw::{byte_reader::ByteReader, writer::Writer};

/* todo:
- Optimize UTF-8 conversion. Try to convert to string partially or parts and
stop converting if we reach a point when input is not valid UTF-8 anymore.
This way we don't consume more memory.
/* todo: Optimize UTF-8 conversion. Try to convert to string partially and stop
converting if we reach a point when input is not valid UTF-8 anymore. This
way we don't consume more memory and we can print the bytes directly to the
output from that point on.
*/

use core::str;
Expand Down
14 changes: 11 additions & 3 deletions tests/integration.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
use assert_cmd::Command;
use std::fs;
use tempfile::tempdir;

#[test]
fn test_from_file() {
let temp_dir = tempdir().unwrap();

let output_file = temp_dir.path().join("output.json");

let mut cmd = Command::cargo_bin("torrust-bencode2json").unwrap();

cmd.arg("-i")
.arg("tests/fixtures/sample.bencode")
.arg("-o")
.arg("output.json")
.arg(output_file.to_str().unwrap())
.assert()
.success();

// todo: check contents
// Read the file. It should contain: ["spam"]
let output_content = fs::read_to_string(output_file).expect("Failed to read output file");

assert_eq!(output_content.trim(), r#"["spam"]"#);
}

#[test]
Expand Down

0 comments on commit 8e1678a

Please sign in to comment.