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

  1. use schematics::resources::{Cert, Csr, GitCheckout};
  2. use schematics::schema::SymbolRunner;
  3. use schematics::symbols::Symbol;
  4. use schematics::Setup;
  5. use std::cell::RefCell;
  6. use std::error::Error;
  7. use std::fmt::Debug;
  8. use std::rc::Rc;
  9. struct TestSymbolRunner {
  10. count: Rc<RefCell<usize>>,
  11. }
  12. impl SymbolRunner for TestSymbolRunner {
  13. fn run_symbol<S: Symbol + Debug>(
  14. &self,
  15. _symbol: &S,
  16. _force: bool,
  17. ) -> Result<bool, Box<dyn Error>> {
  18. *self.count.borrow_mut() += 1;
  19. Ok(false)
  20. }
  21. }
  22. #[test]
  23. fn runs_only_once() {
  24. let count = Rc::new(RefCell::new(0));
  25. let runner = TestSymbolRunner {
  26. count: Rc::clone(&count),
  27. };
  28. let mut setup = Setup::new(runner);
  29. assert_eq!(
  30. (setup.add(Csr("somehost")).unwrap().0).0.to_str().unwrap(),
  31. "/etc/ssl/local_certs/somehost.csr",
  32. );
  33. assert_eq!(
  34. (setup.add(Csr("somehost")).unwrap().0).0.to_str().unwrap(),
  35. "/etc/ssl/local_certs/somehost.csr",
  36. );
  37. assert_eq!(*count.borrow(), 2 + 5); // Key and CSR + 5 dirs
  38. }
  39. #[test]
  40. fn can_create_an_acme_cert() {
  41. let count = Rc::new(RefCell::new(0));
  42. let runner = TestSymbolRunner {
  43. count: Rc::clone(&count),
  44. };
  45. let mut setup = Setup::new(runner);
  46. assert_eq!(
  47. (setup.add(Cert("somehost")).unwrap().0).0.to_str().unwrap(),
  48. "/etc/ssl/local_certs/somehost.crt",
  49. );
  50. assert_eq!(*count.borrow(), 15);
  51. }
  52. #[test]
  53. fn can_create_a_git_checkout() {
  54. let count = Rc::new(RefCell::new(0));
  55. let runner = TestSymbolRunner {
  56. count: Rc::clone(&count),
  57. };
  58. let mut setup = Setup::new(runner);
  59. setup
  60. .add(GitCheckout(
  61. "/tmp/somepath".into(),
  62. "/tmp/some_src_repo",
  63. "master",
  64. ))
  65. .unwrap();
  66. assert_eq!(*count.borrow(), 3);
  67. }