ml-cellar 0.2.0

CLI of ML model registry for minimum MLOps
Documentation
use assert_cmd::cargo::cargo_bin_cmd;
use std::fs;
use tempfile::tempdir;

/// Test `ml-cellar rack {path}`
/// This test uses `tests/fixtures/test_registry/test_rack/` as test directory
/// The directory `tests/fixtures/test_registry/test_rack/` is the expected output of `ml-cellar rack tests/fixtures/test_registry/test_rack/`.
#[test]
fn test_rack() {
    let temp_dir = tempdir().unwrap();
    let rack_path = temp_dir.path().join("my_rack");

    let mut cmd = cargo_bin_cmd!("ml-cellar");
    cmd.arg("rack").arg(&rack_path);
    cmd.assert().success();

    // Check that the rack directory was created
    assert!(rack_path.is_dir());

    // Check README.md, config.toml, and template.md
    let readme = rack_path.join("README.md");
    let config = rack_path.join("config.toml");
    let template = rack_path.join("template.md");

    assert!(readme.is_file(), "README.md should exist");
    assert!(config.is_file(), "config.toml should exist");
    assert!(template.is_file(), "template.md should exist");

    // Check contents of README.md
    let readme_text = fs::read_to_string(&readme).unwrap();
    assert!(readme_text.contains("my_rack"), "README content is wrong");

    // Check contents of config.toml
    let config_text = fs::read_to_string(&config).unwrap();
    let target_config =
        fs::read_to_string("tests/fixtures/test_registry/test_rack/config.toml").unwrap();

    assert_eq!(
        config_text, target_config,
        "config.toml is \n***\n{} \n*** \n and different from the config file.",
        config_text
    );

    // Check contents of template.md
    let template_text = fs::read_to_string(&template).unwrap();
    let target_template =
        fs::read_to_string("tests/fixtures/test_registry/test_rack/template.md").unwrap();

    assert_eq!(
        template_text, target_template,
        "template.md is \n***\n{} \n*** \n and different from the template file.",
        template_text
    );
}