Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/holger

server/repository/znippy-rust/tests/plugin_read_view.rs

//! Holger rust backend serve test through a REAL compressed archive built with the
//! cargo plugin. Proves `fetch` resolves crate coords via the typed rust view —
//! a hyphenated crate name + pre-release version, where a naive `rsplit_once('-')`
//! on the `.crate` filename mis-splits.

use std::fs;

use repository_znippy_rust::RustRepoZnippy;
use traits::{ArtifactId, RepositoryBackendTrait};
use znippy_common::plugin::PluginRegistry;
use znippy_common::plugins::cargo_native::CargoPlugin;
use znippy_compress::compress_dir;

#[test]
fn rust_backend_serves_hyphenated_prerelease_via_view() {
    let src = tempfile::tempdir().unwrap();
    let out = tempfile::tempdir().unwrap();

    // Hyphenated name + rc version: `serde-derive-1.0.0-rc.1.crate`.
    let bytes_a = b"serde-derive real crate payload".to_vec();
    fs::write(src.path().join("serde-derive-1.0.0-rc.1.crate"), &bytes_a).unwrap();
    let bytes_b = b"tokio crate payload".to_vec();
    fs::write(src.path().join("tokio-1.38.0.crate"), &bytes_b).unwrap();

    let archive = out.path().join("rust.znippy");
    compress_dir(
        &src.path().to_path_buf(),
        &archive,
        false,
        Some(&PluginRegistry::with_plugin(Box::new(CargoPlugin::new()))),
        None,
        None,
    )
    .expect("compress_dir with cargo plugin");

    let repo = RustRepoZnippy::with_archive("rust".into(), archive).unwrap();

    // fetch via the view → exact bytes for the hyphenated/rc coord.
    let id = ArtifactId {
        namespace: None,
        name: "serde-derive".into(),
        version: "1.0.0-rc.1".into(),
    };
    assert_eq!(
        repo.fetch(&id).unwrap().as_deref(),
        Some(bytes_a.as_slice())
    );

    let tid = ArtifactId {
        namespace: None,
        name: "tokio".into(),
        version: "1.38.0".into(),
    };
    assert_eq!(
        repo.fetch(&tid).unwrap().as_deref(),
        Some(bytes_b.as_slice())
    );

    // Absent → None.
    let absent = ArtifactId {
        namespace: None,
        name: "serde-derive".into(),
        version: "2.0.0".into(),
    };
    assert_eq!(repo.fetch(&absent).unwrap(), None);
}