A library for writing host-specific, single-binary configuration management and deployment tools
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
1.7 KiB

use schematics::resources::{Cert, Csr, GitCheckout};
use schematics::schema::SymbolRunner;
use schematics::symbols::Symbol;
use schematics::Setup;
use std::cell::RefCell;
use std::error::Error;
use std::fmt::Debug;
use std::rc::Rc;
struct TestSymbolRunner {
count: Rc<RefCell<usize>>,
}
impl SymbolRunner for TestSymbolRunner {
fn run_symbol<S: Symbol + Debug>(
&self,
_symbol: &S,
_force: bool,
) -> Result<bool, Box<dyn Error>> {
*self.count.borrow_mut() += 1;
Ok(false)
}
}
#[test]
fn runs_only_once() {
let count = Rc::new(RefCell::new(0));
let runner = TestSymbolRunner {
count: Rc::clone(&count),
};
let mut setup = Setup::new(runner);
assert_eq!(
(setup.add(Csr("somehost")).unwrap().0).0.to_str().unwrap(),
"/etc/ssl/local_certs/somehost.csr",
);
assert_eq!(
(setup.add(Csr("somehost")).unwrap().0).0.to_str().unwrap(),
"/etc/ssl/local_certs/somehost.csr",
);
assert_eq!(*count.borrow(), 2 + 5); // Key and CSR + 5 dirs
}
#[test]
fn can_create_an_acme_cert() {
let count = Rc::new(RefCell::new(0));
let runner = TestSymbolRunner {
count: Rc::clone(&count),
};
let mut setup = Setup::new(runner);
assert_eq!(
(setup.add(Cert("somehost")).unwrap().0).0.to_str().unwrap(),
"/etc/ssl/local_certs/somehost.crt",
);
assert_eq!(*count.borrow(), 15);
}
#[test]
fn can_create_a_git_checkout() {
let count = Rc::new(RefCell::new(0));
let runner = TestSymbolRunner {
count: Rc::clone(&count),
};
let mut setup = Setup::new(runner);
setup
.add(GitCheckout(
"/tmp/somepath".into(),
"/tmp/some_src_repo",
"master",
))
.unwrap();
assert_eq!(*count.borrow(), 3);
}