mirror of
https://github.com/Drop-OSS/drop.git
synced 2026-07-25 09:14:54 +10:00
feat: add tests
This commit is contained in:
@@ -2,9 +2,9 @@
|
||||
#![feature(impl_trait_in_bindings)]
|
||||
|
||||
pub mod file_utils;
|
||||
pub mod manifest;
|
||||
pub mod ssl;
|
||||
pub mod versions;
|
||||
pub mod manifest;
|
||||
pub mod vm;
|
||||
|
||||
extern crate libarchive_drop;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use rcgen::{
|
||||
CertificateParams, DistinguishedName, Error, IsCa, KeyPair, KeyUsagePurpose, PublicKeyData, SubjectPublicKeyInfo
|
||||
CertificateParams, DistinguishedName, Error, IsCa, KeyPair, KeyUsagePurpose, PublicKeyData,
|
||||
SubjectPublicKeyInfo,
|
||||
};
|
||||
use ring::rand::SystemRandom;
|
||||
use ring::signature::{EcdsaKeyPair, VerificationAlgorithm};
|
||||
@@ -42,8 +43,7 @@ pub fn generate_client_certificate(
|
||||
root_ca: String,
|
||||
root_ca_private: String,
|
||||
) -> Result<Vec<String>, rcgen::Error> {
|
||||
let root_key_pair =
|
||||
KeyPair::from_pem(&root_ca_private)?;
|
||||
let root_key_pair = KeyPair::from_pem(&root_ca_private)?;
|
||||
let certificate_params = CertificateParams::from_ca_cert_pem(&root_ca)?;
|
||||
let root_ca = CertificateParams::self_signed(certificate_params, &root_key_pair)?;
|
||||
|
||||
|
||||
@@ -1,11 +1,45 @@
|
||||
use std::path::PathBuf;
|
||||
#![cfg(test)]
|
||||
extern crate test_generator;
|
||||
|
||||
use crate::versions::create_backend_constructor;
|
||||
use std::path::Path;
|
||||
|
||||
#[tokio::test]
|
||||
pub async fn test_7z_list() {
|
||||
let zip_path = "/home/decduck/Dev/droplet/assets/TheGame.zip";
|
||||
let mut backend = create_backend_constructor(&PathBuf::from(zip_path)).unwrap()().unwrap();
|
||||
let files = backend.list_files().await.unwrap();
|
||||
tokio::fs::write("./test.txt", format!("{:?}", files)).await.unwrap();
|
||||
use serde_json::json;
|
||||
use test_generator::test_resources;
|
||||
use tokio::{fs::File, io::AsyncWriteExt};
|
||||
|
||||
use crate::manifest::generate_manifest_rusty;
|
||||
|
||||
#[test_resources("testfiles/**/*.7z")]
|
||||
fn manifest_gen(resource: &str) {
|
||||
let runtime = tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
.expect("failed to create tokio runtime");
|
||||
|
||||
runtime.block_on(async move {
|
||||
let filepath = Path::new(resource);
|
||||
let manifest = generate_manifest_rusty(
|
||||
&filepath,
|
||||
|_| {},
|
||||
|message| {
|
||||
println!("({}) {}", filepath.display(), message);
|
||||
},
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.expect(&format!(
|
||||
"failed to generate manifest for {}",
|
||||
filepath.display()
|
||||
));
|
||||
|
||||
let mut output_path = filepath.to_path_buf();
|
||||
output_path.set_extension("json");
|
||||
|
||||
let mut file = File::create(output_path)
|
||||
.await
|
||||
.expect("failed to open output path");
|
||||
file.write_all(json!(manifest).to_string().as_bytes())
|
||||
.await
|
||||
.expect("failed to write output");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::{path::PathBuf, task::Poll};
|
||||
|
||||
use anyhow::{anyhow};
|
||||
use anyhow::anyhow;
|
||||
use async_trait::async_trait;
|
||||
use libarchive_drop::{
|
||||
archive::{Entry, FileType, ReadCompression, ReadFormat},
|
||||
|
||||
@@ -48,10 +48,7 @@ pub fn create_backend_constructor<'a>(
|
||||
}));
|
||||
};
|
||||
|
||||
let file_extension = path
|
||||
.extension()
|
||||
.map(|v| v.to_str())
|
||||
.flatten()?;
|
||||
let file_extension = path.extension().map(|v| v.to_str()).flatten()?;
|
||||
|
||||
if SUPPORTED_FILE_EXTENSIONS
|
||||
.iter()
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
#[cfg(unix)]
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
use std::{
|
||||
io::SeekFrom,
|
||||
path::PathBuf,
|
||||
};
|
||||
use std::{io::SeekFrom, path::PathBuf};
|
||||
|
||||
use anyhow::anyhow;
|
||||
use async_trait::async_trait;
|
||||
@@ -17,7 +14,10 @@ pub struct PathVersionBackend {
|
||||
pub base_dir: PathBuf,
|
||||
}
|
||||
|
||||
use crate::versions::{_list_files, types::{MinimumFileObject, VersionBackend, VersionFile}};
|
||||
use crate::versions::{
|
||||
_list_files,
|
||||
types::{MinimumFileObject, VersionBackend, VersionFile},
|
||||
};
|
||||
|
||||
#[async_trait]
|
||||
impl VersionBackend for PathVersionBackend {
|
||||
@@ -34,7 +34,10 @@ impl VersionBackend for PathVersionBackend {
|
||||
self.peek_file(
|
||||
relative
|
||||
.to_str()
|
||||
.ok_or(anyhow!("Could not parse path: {}", relative.to_string_lossy()))?
|
||||
.ok_or(anyhow!(
|
||||
"Could not parse path: {}",
|
||||
relative.to_string_lossy()
|
||||
))?
|
||||
.to_owned(),
|
||||
)
|
||||
.await?,
|
||||
|
||||
@@ -13,7 +13,6 @@ pub struct VersionFile {
|
||||
pub trait MinimumFileObject: AsyncRead + Send + Unpin {}
|
||||
impl<T: AsyncRead + Send + Unpin> MinimumFileObject for T {}
|
||||
|
||||
|
||||
#[async_trait]
|
||||
pub trait VersionBackend {
|
||||
fn require_whole_files(&self) -> bool;
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
|
||||
Reference in New Issue
Block a user