Skip to content

Commit b42cd63

Browse files
committed
Fix temp dir name and create test output dir
Correct a typo in the test temp directory name (sed_tests -> sen_tests) and ensure the directory is created before tests write output files. Updated the helper and multiple tests to reuse a dir variable and call fs::create_dir_all(&dir). This prevents failures when the temp directory does not exist and keeps test file paths consistent.
1 parent 97a3da8 commit b42cd63

1 file changed

Lines changed: 22 additions & 8 deletions

File tree

src/crypto.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ mod tests {
211211

212212
/// Helper: create a temp keyfile with given content
213213
fn create_temp_keyfile(name: &str, content: &[u8]) -> PathBuf {
214-
let dir = std::env::temp_dir().join("sed_tests");
214+
let dir = std::env::temp_dir().join("sen_tests");
215215
fs::create_dir_all(&dir).unwrap();
216216
let path = dir.join(name);
217217
let mut file = fs::File::create(&path).unwrap();
@@ -229,7 +229,9 @@ mod tests {
229229
#[test]
230230
fn test_encrypt_decrypt_roundtrip() {
231231
let keyfile = create_random_keyfile("test_roundtrip.key");
232-
let output = std::env::temp_dir().join("sen_tests").join("roundtrip.sen");
232+
let dir = std::env::temp_dir().join("sen_tests");
233+
fs::create_dir_all(&dir).unwrap();
234+
let output = dir.join("roundtrip.sen");
233235
let content = "Hello, SEN! This is a test document.\nLine 2.\n";
234236

235237
encrypt_file(content, &keyfile, &output).expect("Encryption should succeed");
@@ -255,7 +257,9 @@ mod tests {
255257
fn test_wrong_keyfile_fails() {
256258
let keyfile1 = create_random_keyfile("test_wrong_key1.key");
257259
let keyfile2 = create_random_keyfile("test_wrong_key2.key");
258-
let output = std::env::temp_dir().join("sen_tests").join("wrong_key.sen");
260+
let dir = std::env::temp_dir().join("sen_tests");
261+
fs::create_dir_all(&dir).unwrap();
262+
let output = dir.join("wrong_key.sen");
259263

260264
encrypt_file("Secret data", &keyfile1, &output).unwrap();
261265

@@ -271,7 +275,9 @@ mod tests {
271275
#[test]
272276
fn test_invalid_magic_number() {
273277
let keyfile = create_random_keyfile("test_magic.key");
274-
let output = std::env::temp_dir().join("sen_tests").join("bad_magic.sen");
278+
let dir = std::env::temp_dir().join("sen_tests");
279+
fs::create_dir_all(&dir).unwrap();
280+
let output = dir.join("bad_magic.sen");
275281

276282
// Write a file with wrong magic number
277283
let mut data = vec![0u8; 100];
@@ -289,7 +295,9 @@ mod tests {
289295
#[test]
290296
fn test_corrupted_file_too_short() {
291297
let keyfile = create_random_keyfile("test_corrupt.key");
292-
let output = std::env::temp_dir().join("sen_tests").join("corrupt.sen");
298+
let dir = std::env::temp_dir().join("sen_tests");
299+
fs::create_dir_all(&dir).unwrap();
300+
let output = dir.join("corrupt.sen");
293301

294302
// Write a file that's too short (just magic + partial salt)
295303
let mut data = vec![0u8; 10];
@@ -307,7 +315,9 @@ mod tests {
307315
#[test]
308316
fn test_empty_keyfile_rejected() {
309317
let keyfile = create_temp_keyfile("test_empty.key", b"");
310-
let output = std::env::temp_dir().join("sen_tests").join("empty_key.sen");
318+
let dir = std::env::temp_dir().join("sen_tests");
319+
fs::create_dir_all(&dir).unwrap();
320+
let output = dir.join("empty_key.sen");
311321

312322
let result = encrypt_file("test", &keyfile, &output);
313323
assert!(matches!(result, Err(CryptoError::KeyfileError(_))));
@@ -319,7 +329,9 @@ mod tests {
319329
#[test]
320330
fn test_empty_content_roundtrip() {
321331
let keyfile = create_random_keyfile("test_empty_content.key");
322-
let output = std::env::temp_dir().join("sen_tests").join("empty_content.sen");
332+
let dir = std::env::temp_dir().join("sen_tests");
333+
fs::create_dir_all(&dir).unwrap();
334+
let output = dir.join("empty_content.sen");
323335

324336
encrypt_file("", &keyfile, &output).expect("Encrypting empty content should succeed");
325337
let decrypted = decrypt_file(&keyfile, &output).expect("Decrypting should succeed");
@@ -333,7 +345,9 @@ mod tests {
333345
#[test]
334346
fn test_large_content_roundtrip() {
335347
let keyfile = create_random_keyfile("test_large.key");
336-
let output = std::env::temp_dir().join("sen_tests").join("large.sen");
348+
let dir = std::env::temp_dir().join("sen_tests");
349+
fs::create_dir_all(&dir).unwrap();
350+
let output = dir.join("large.sen");
337351
let content = "A".repeat(100_000); // 100KB content
338352

339353
encrypt_file(&content, &keyfile, &output).unwrap();

0 commit comments

Comments
 (0)