aoc-toolkit 0.1.0-alpha.4

A toolkit for solving Advent of Code problems
Documentation
use super::*;

const EXTENSION_ID: &str = "abcdefghijklmnopabcdefghijklmnop";

#[test]
fn registration_lifecycle() {
    let directory = tempfile::tempdir().unwrap();
    let executable = directory.path().join("aoc");

    fs::write(&executable, b"").unwrap();

    let directory = directory.path();

    assert_eq!(
        status_at(directory, &executable).unwrap(),
        RegistrationStatus::Missing
    );

    let path = install_at(directory, &executable, EXTENSION_ID).unwrap();

    assert!(path.is_file());

    assert_eq!(
        status_at(directory, &executable).unwrap(),
        RegistrationStatus::Registered
    );

    assert_eq!(
        install_at(directory, &executable, EXTENSION_ID,).unwrap(),
        path
    );

    assert!(uninstall_at(directory, &executable).unwrap());
    assert!(!path.exists());

    assert!(!uninstall_at(directory, &executable).unwrap());
}

#[test]
fn rejects_conflicting_registration() {
    let directory = tempfile::tempdir().unwrap();
    let executable = directory.path().join("aoc");
    let other = directory.path().join("other");

    fs::write(&executable, b"").unwrap();
    fs::write(&other, b"").unwrap();

    let directory = directory.path();

    let path = install_at(directory, &executable, EXTENSION_ID).unwrap();

    let original = fs::read(&path).unwrap();

    assert!(install_at(directory, &other, EXTENSION_ID,).is_err());

    assert!(uninstall_at(directory, &other).is_err());

    assert_eq!(fs::read(&path).unwrap(), original);
}

#[test]
fn rejects_invalid_extension_id() {
    let directory = tempfile::tempdir().unwrap();
    let executable = directory.path().join("aoc");

    fs::write(&executable, b"").unwrap();

    assert!(install_at(directory.path(), &executable, "invalid",).is_err());

    assert!(!manifest_path(directory.path()).exists());
}