use server_forge::config::Config;
use server_forge::deployment;
use server_forge::rollback::RollbackManager;
#[test]
fn test_deploy_nginx() {
assert!(deployment::deploy_nginx().is_ok());
let nginx_status = std::process::Command::new("which")
.arg("nginx")
.status()
.unwrap();
assert!(nginx_status.success());
let service_status = std::process::Command::new("systemctl")
.args(&["is-active", "nginx"])
.status()
.unwrap();
assert!(service_status.success());
}
#[test]
fn test_deploy_apache() {
assert!(deployment::deploy_apache().is_ok());
let apache_status = std::process::Command::new("which")
.arg("apache2")
.status()
.unwrap_or_else(|_| {
std::process::Command::new("which")
.arg("httpd")
.status()
.unwrap()
});
assert!(apache_status.success());
let service_status = std::process::Command::new("systemctl")
.args(&["is-active", "apache2"])
.status()
.unwrap_or_else(|_| {
std::process::Command::new("systemctl")
.args(&["is-active", "httpd"])
.status()
.unwrap()
});
assert!(service_status.success());
}
#[test]
fn test_deploy_mysql() {
assert!(deployment::deploy_mysql().is_ok());
let mysql_status = std::process::Command::new("which")
.arg("mysql")
.status()
.unwrap();
assert!(mysql_status.success());
let service_status = std::process::Command::new("systemctl")
.args(&["is-active", "mysql"])
.status()
.unwrap();
assert!(service_status.success());
}
#[test]
fn test_deploy_postgresql() {
assert!(deployment::deploy_postgresql().is_ok());
let psql_status = std::process::Command::new("which")
.arg("psql")
.status()
.unwrap();
assert!(psql_status.success());
let service_status = std::process::Command::new("systemctl")
.args(&["is-active", "postgresql"])
.status()
.unwrap();
assert!(service_status.success());
}
#[test]
fn test_deploy_php() {
let server_role = "web";
assert!(deployment::deploy_php(server_role).is_ok());
let php_status = std::process::Command::new("which")
.arg("php")
.status()
.unwrap();
assert!(php_status.success());
let service_status = std::process::Command::new("systemctl")
.args(&["is-active", "php-fpm"])
.status()
.unwrap();
assert!(service_status.success());
}
#[test]
fn test_deploy_applications() {
let config = Config {
deployed_apps: vec![
String::from("nginx"),
String::from("mysql"),
String::from("php"),
],
..Default::default()
};
let rollback_manager = RollbackManager::new();
assert!(deployment::deploy_applications(&config, &rollback_manager).is_ok());
}