Fix tests on Windows

This commit is contained in:
Vincent Prouillet 2021-05-16 19:59:56 +02:00
parent 9e0cac6d4d
commit a736d33afb
3 changed files with 13 additions and 10 deletions

View file

@ -2,13 +2,12 @@ use std::collections::HashMap;
use std::path::PathBuf; use std::path::PathBuf;
use std::{fs, io, result}; use std::{fs, io, result};
use crate::global_fns::helpers::search_for_file;
use base64::encode as encode_b64; use base64::encode as encode_b64;
use config::Config;
use sha2::{digest, Sha256, Sha384, Sha512}; use sha2::{digest, Sha256, Sha384, Sha512};
use tera::{from_value, to_value, Function as TeraFn, Result, Value}; use tera::{from_value, to_value, Function as TeraFn, Result, Value};
use config::Config;
use utils::site::resolve_internal_link; use utils::site::resolve_internal_link;
use crate::global_fns::helpers::search_for_file;
fn compute_file_hash<D: digest::Digest>( fn compute_file_hash<D: digest::Digest>(
mut file: fs::File, mut file: fs::File,

View file

@ -145,6 +145,7 @@ mod tests {
use std::fs::{copy, create_dir_all}; use std::fs::{copy, create_dir_all};
use config::Config; use config::Config;
use std::path::Path;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use tempfile::{tempdir, TempDir}; use tempfile::{tempdir, TempDir};
use tera::{to_value, Function}; use tera::{to_value, Function};
@ -177,9 +178,11 @@ mod tests {
// 1. resizing an image in static // 1. resizing an image in static
args.insert("path".to_string(), to_value("static/gutenberg.jpg").unwrap()); args.insert("path".to_string(), to_value("static/gutenberg.jpg").unwrap());
let data = static_fn.call(&args).unwrap().as_object().unwrap().clone(); let data = static_fn.call(&args).unwrap().as_object().unwrap().clone();
let static_path = Path::new("static").join("processed_images");
assert_eq!( assert_eq!(
data["static_path"], data["static_path"],
to_value("static/processed_images/e49f5bd23ec5007c00.jpg").unwrap() to_value(&format!("{}", static_path.join("e49f5bd23ec5007c00.jpg").display())).unwrap()
); );
assert_eq!( assert_eq!(
data["url"], data["url"],
@ -191,7 +194,7 @@ mod tests {
let data = static_fn.call(&args).unwrap().as_object().unwrap().clone(); let data = static_fn.call(&args).unwrap().as_object().unwrap().clone();
assert_eq!( assert_eq!(
data["static_path"], data["static_path"],
to_value("static/processed_images/32454a1e0243976c00.jpg").unwrap() to_value(&format!("{}", static_path.join("32454a1e0243976c00.jpg").display())).unwrap()
); );
assert_eq!( assert_eq!(
data["url"], data["url"],
@ -203,7 +206,7 @@ mod tests {
let data = static_fn.call(&args).unwrap().as_object().unwrap().clone(); let data = static_fn.call(&args).unwrap().as_object().unwrap().clone();
assert_eq!( assert_eq!(
data["static_path"], data["static_path"],
to_value("static/processed_images/074e171855ee541800.jpg").unwrap() to_value(&format!("{}", static_path.join("074e171855ee541800.jpg").display())).unwrap()
); );
assert_eq!( assert_eq!(
data["url"], data["url"],
@ -215,7 +218,7 @@ mod tests {
let data = static_fn.call(&args).unwrap().as_object().unwrap().clone(); let data = static_fn.call(&args).unwrap().as_object().unwrap().clone();
assert_eq!( assert_eq!(
data["static_path"], data["static_path"],
to_value("static/processed_images/c8aaba7b0593a60b00.jpg").unwrap() to_value(&format!("{}", static_path.join("c8aaba7b0593a60b00.jpg").display())).unwrap()
); );
assert_eq!( assert_eq!(
data["url"], data["url"],

View file

@ -610,21 +610,22 @@ mod tests {
let static_fn = LoadData::new(dir.path().to_path_buf()); let static_fn = LoadData::new(dir.path().to_path_buf());
let mut args = HashMap::new(); let mut args = HashMap::new();
let val = if cfg!(windows) { ".hello {}\r\n" } else { ".hello {}\n" };
// 1. relative path in `static` // 1. relative path in `static`
args.insert("path".to_string(), to_value("static/test.css").unwrap()); args.insert("path".to_string(), to_value("static/test.css").unwrap());
let data = static_fn.call(&args).unwrap().as_str().unwrap().to_string(); let data = static_fn.call(&args).unwrap().as_str().unwrap().to_string();
assert_eq!(data, ".hello {}\n"); assert_eq!(data, val);
// 2. relative path in `content` // 2. relative path in `content`
args.insert("path".to_string(), to_value("content/test.css").unwrap()); args.insert("path".to_string(), to_value("content/test.css").unwrap());
let data = static_fn.call(&args).unwrap().as_str().unwrap().to_string(); let data = static_fn.call(&args).unwrap().as_str().unwrap().to_string();
assert_eq!(data, ".hello {}\n"); assert_eq!(data, val);
// 3. path starting with @/ // 3. path starting with @/
args.insert("path".to_string(), to_value("@/test.css").unwrap()); args.insert("path".to_string(), to_value("@/test.css").unwrap());
let data = static_fn.call(&args).unwrap().as_str().unwrap().to_string(); let data = static_fn.call(&args).unwrap().as_str().unwrap().to_string();
assert_eq!(data, ".hello {}\n"); assert_eq!(data, val);
// 4. absolute path does not work // 4. absolute path does not work
args.insert("path".to_string(), to_value("/test.css").unwrap()); args.insert("path".to_string(), to_value("/test.css").unwrap());