feat: add tests

This commit is contained in:
DecDuck
2026-03-02 22:09:22 +11:00
parent f5c4cbe18f
commit 4cdcc38349
43 changed files with 190 additions and 59 deletions
+42
View File
@@ -0,0 +1,42 @@
name: Rust CI
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
env:
CARGO_TERM_COLOR: always
jobs:
ci:
name: Build, Test, Lint
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Check formatting
run: cargo fmt --all -- --check
- name: Run Clippy (lint)
run: cargo clippy --all-targets --all-features -- -D warnings
- name: Run tests
run: cargo test --all-features --all --verbose
+89 -35
View File
@@ -61,8 +61,8 @@ version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "965c2d33e53cb6b267e148a4cb0760bc01f4904c1cd4bb4002a085bb016d1490"
dependencies = [
"proc-macro2",
"quote",
"proc-macro2 1.0.94",
"quote 1.0.40",
"syn 2.0.117",
"synstructure 0.13.1",
]
@@ -73,8 +73,8 @@ version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3109e49b1e4909e9db6515a30c633684d68cdeaa252f215214cb4fa1a5bfee2c"
dependencies = [
"proc-macro2",
"quote",
"proc-macro2 1.0.94",
"quote 1.0.40",
"syn 2.0.117",
"synstructure 0.13.1",
]
@@ -85,8 +85,8 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b18050c2cd6fe86c3a76584ef5e0baf286d038cda203eb6223df2cc413565f7"
dependencies = [
"proc-macro2",
"quote",
"proc-macro2 1.0.94",
"quote 1.0.40",
"syn 2.0.117",
]
@@ -96,8 +96,8 @@ version = "0.1.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb"
dependencies = [
"proc-macro2",
"quote",
"proc-macro2 1.0.94",
"quote 1.0.40",
"syn 2.0.117",
]
@@ -242,8 +242,8 @@ version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0"
dependencies = [
"proc-macro2",
"quote",
"proc-macro2 1.0.94",
"quote 1.0.40",
"syn 2.0.117",
]
@@ -265,6 +265,7 @@ dependencies = [
"serde_json",
"sha2",
"speedometer",
"test-generator",
"time",
"tokio",
"uuid",
@@ -293,8 +294,8 @@ version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4"
dependencies = [
"proc-macro2",
"quote",
"proc-macro2 1.0.94",
"quote 1.0.40",
"syn 1.0.109",
"synstructure 0.12.6",
]
@@ -353,8 +354,8 @@ version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650"
dependencies = [
"proc-macro2",
"quote",
"proc-macro2 1.0.94",
"quote 1.0.40",
"syn 2.0.117",
]
@@ -427,6 +428,12 @@ version = "0.32.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e629b9b98ef3dd8afe6ca2bd0f89306cec16d43d907889945bc5d6687f2f13c7"
[[package]]
name = "glob"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280"
[[package]]
name = "hex"
version = "0.4.3"
@@ -637,6 +644,15 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
[[package]]
name = "proc-macro2"
version = "0.4.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759"
dependencies = [
"unicode-xid 0.1.0",
]
[[package]]
name = "proc-macro2"
version = "1.0.94"
@@ -646,13 +662,22 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "0.6.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1"
dependencies = [
"proc-macro2 0.4.30",
]
[[package]]
name = "quote"
version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
dependencies = [
"proc-macro2",
"proc-macro2 1.0.94",
]
[[package]]
@@ -747,8 +772,8 @@ version = "1.0.228"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
dependencies = [
"proc-macro2",
"quote",
"proc-macro2 1.0.94",
"quote 1.0.40",
"syn 2.0.117",
]
@@ -806,14 +831,25 @@ dependencies = [
"failure",
]
[[package]]
name = "syn"
version = "0.15.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5"
dependencies = [
"proc-macro2 0.4.30",
"quote 0.6.13",
"unicode-xid 0.1.0",
]
[[package]]
name = "syn"
version = "1.0.109"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
dependencies = [
"proc-macro2",
"quote",
"proc-macro2 1.0.94",
"quote 1.0.40",
"unicode-ident",
]
@@ -823,8 +859,8 @@ version = "2.0.117"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99"
dependencies = [
"proc-macro2",
"quote",
"proc-macro2 1.0.94",
"quote 1.0.40",
"unicode-ident",
]
@@ -834,10 +870,10 @@ version = "0.12.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f"
dependencies = [
"proc-macro2",
"quote",
"proc-macro2 1.0.94",
"quote 1.0.40",
"syn 1.0.109",
"unicode-xid",
"unicode-xid 0.2.6",
]
[[package]]
@@ -846,11 +882,23 @@ version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971"
dependencies = [
"proc-macro2",
"quote",
"proc-macro2 1.0.94",
"quote 1.0.40",
"syn 2.0.117",
]
[[package]]
name = "test-generator"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b23be2add79223226e1cb6446cb3e37506a5927089870687a0f1149bb7a073a"
dependencies = [
"glob",
"proc-macro2 0.4.30",
"quote 0.6.13",
"syn 0.15.44",
]
[[package]]
name = "thiserror"
version = "1.0.69"
@@ -875,8 +923,8 @@ version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
dependencies = [
"proc-macro2",
"quote",
"proc-macro2 1.0.94",
"quote 1.0.40",
"syn 2.0.117",
]
@@ -886,8 +934,8 @@ version = "2.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d"
dependencies = [
"proc-macro2",
"quote",
"proc-macro2 1.0.94",
"quote 1.0.40",
"syn 2.0.117",
]
@@ -943,8 +991,8 @@ version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af407857209536a95c8e56f8231ef2c2e2aff839b22e07a1ffcbc617e9db9fa5"
dependencies = [
"proc-macro2",
"quote",
"proc-macro2 1.0.94",
"quote 1.0.40",
"syn 2.0.117",
]
@@ -960,6 +1008,12 @@ version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
[[package]]
name = "unicode-xid"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
[[package]]
name = "unicode-xid"
version = "0.2.6"
@@ -1023,7 +1077,7 @@ version = "0.2.106"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48cb0d2638f8baedbc542ed444afc0644a29166f1595371af4fecf8ce1e7eeb3"
dependencies = [
"quote",
"quote 1.0.40",
"wasm-bindgen-macro-support",
]
@@ -1034,8 +1088,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cefb59d5cd5f92d9dcf80e4683949f15ca4b511f4ac0a6e14d4e1ac60c6ecd40"
dependencies = [
"bumpalo",
"proc-macro2",
"quote",
"proc-macro2 1.0.94",
"quote 1.0.40",
"syn 2.0.117",
"wasm-bindgen-shared",
]
+1
View File
@@ -31,6 +31,7 @@ futures = "0.3.31"
getrandom = "0.3.4"
libarchive-drop = { version = "*", path = "./libarchive-rust" }
speedometer = "0.2.2"
test-generator = "0.3.1"
[dependencies.x509-parser]
version = "0.17.0"
+1 -1
View File
@@ -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;
+3 -3
View File
@@ -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)?;
+42 -8
View File
@@ -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},
+1 -4
View File
@@ -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?,
-1
View File
@@ -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;
+1
View File
@@ -0,0 +1 @@
Binary file not shown.
Binary file not shown.