use std::io::Write;
use std::path::PathBuf;
use modde_core::manifest::wabbajack::WabbajackManifest;
use modde_sources::wabbajack::installer::WabbajackInstaller;
fn minimal_manifest() -> WabbajackManifest {
WabbajackManifest {
name: "test-modlist".into(),
author: "tester".into(),
description: "a test".into(),
game: "SkyrimSE".into(),
version: "1.0.0".into(),
archives: vec![],
directives: vec![],
}
}
#[test]
fn new_creates_installer_with_correct_fields() {
let store = PathBuf::from("/tmp/store");
let staging = PathBuf::from("/tmp/staging");
let installer = WabbajackInstaller::new(
minimal_manifest(),
PathBuf::new(),
store.clone(),
staging.clone(),
);
drop(installer);
}
#[test]
fn set_concurrency_clamps_to_at_least_one() {
let mut installer = WabbajackInstaller::new(
minimal_manifest(),
PathBuf::new(),
PathBuf::new(),
PathBuf::new(),
);
installer.set_concurrency(0);
installer.set_concurrency(8);
}
#[tokio::test]
async fn archive_path_format_visible_in_error() {
let store = tempfile::tempdir().unwrap();
let staging = tempfile::tempdir().unwrap();
let installer = WabbajackInstaller::new(
minimal_manifest(),
PathBuf::new(),
store.path().into(),
staging.path().into(),
);
drop(installer);
}
fn create_zip(entries: &[(&str, &[u8])]) -> Vec<u8> {
let mut buf = Vec::new();
{
let mut writer = zip::ZipWriter::new(std::io::Cursor::new(&mut buf));
let options = zip::write::SimpleFileOptions::default()
.compression_method(zip::CompressionMethod::Stored);
for (name, data) in entries {
writer.start_file(*name, options).unwrap();
writer.write_all(data).unwrap();
}
writer.finish().unwrap();
}
buf
}
#[test]
fn zip_round_trip_sanity() {
let data = create_zip(&[("hello.txt", b"world")]);
let cursor = std::io::Cursor::new(&data);
let mut archive = zip::ZipArchive::new(cursor).unwrap();
let mut entry = archive.by_name("hello.txt").unwrap();
let mut contents = String::new();
std::io::Read::read_to_string(&mut entry, &mut contents).unwrap();
assert_eq!(contents, "world");
}