feat: Migrate SAL to Cargo workspace
Some checks failed
Rhai Tests / Run Rhai Tests (push) Has been cancelled
Rhai Tests / Run Rhai Tests (pull_request) Has been cancelled

- Migrate individual modules to independent crates
- Refactor dependencies for improved modularity
- Update build system and testing infrastructure
- Update documentation to reflect new structure
This commit is contained in:
Mahmoud-Emad
2025-06-24 12:39:18 +03:00
parent 8012a66250
commit e125bb6511
54 changed files with 1196 additions and 1582 deletions

View File

@@ -4,7 +4,7 @@ use sal_virt::nerdctl::{Container, NerdctlError};
fn test_container_creation() {
// Test creating a new container
let result = Container::new("test-container");
match result {
Ok(container) => {
assert_eq!(container.name, "test-container");
@@ -25,7 +25,7 @@ fn test_container_creation() {
fn test_container_from_image() {
// Test creating a container from an image
let result = Container::from_image("test-container", "alpine:latest");
match result {
Ok(container) => {
assert_eq!(container.name, "test-container");
@@ -45,7 +45,7 @@ fn test_container_from_image() {
#[test]
fn test_container_builder_pattern() {
let result = Container::from_image("test-app", "nginx:alpine");
match result {
Ok(container) => {
// Test builder pattern methods
@@ -60,18 +60,27 @@ fn test_container_builder_pattern() {
.with_restart_policy("always")
.with_health_check("curl -f http://localhost/ || exit 1")
.with_detach(true);
// Verify configuration
assert_eq!(configured_container.name, "test-app");
assert_eq!(configured_container.image, Some("nginx:alpine".to_string()));
assert_eq!(configured_container.ports, vec!["8080:80"]);
assert_eq!(configured_container.volumes, vec!["/host/data:/app/data"]);
assert_eq!(configured_container.env_vars.get("ENV_VAR"), Some(&"test_value".to_string()));
assert_eq!(configured_container.network, Some("test-network".to_string()));
assert_eq!(
configured_container.env_vars.get("ENV_VAR"),
Some(&"test_value".to_string())
);
assert_eq!(
configured_container.network,
Some("test-network".to_string())
);
assert_eq!(configured_container.network_aliases, vec!["app-alias"]);
assert_eq!(configured_container.cpu_limit, Some("0.5".to_string()));
assert_eq!(configured_container.memory_limit, Some("512m".to_string()));
assert_eq!(configured_container.restart_policy, Some("always".to_string()));
assert_eq!(
configured_container.restart_policy,
Some("always".to_string())
);
assert!(configured_container.health_check.is_some());
assert!(configured_container.detach);
}
@@ -88,17 +97,15 @@ fn test_container_builder_pattern() {
#[test]
fn test_container_reset() {
let result = Container::from_image("test-container", "alpine:latest");
match result {
Ok(container) => {
// Configure the container
let configured = container
.with_port("8080:80")
.with_env("TEST", "value");
let configured = container.with_port("8080:80").with_env("TEST", "value");
// Reset should clear configuration but keep name and image
let reset_container = configured.reset();
assert_eq!(reset_container.name, "test-container");
assert_eq!(reset_container.image, Some("alpine:latest".to_string()));
assert!(reset_container.ports.is_empty());
@@ -120,7 +127,7 @@ fn test_nerdctl_error_types() {
// Test that our error types work correctly
let error = NerdctlError::CommandFailed("Test error".to_string());
assert!(matches!(error, NerdctlError::CommandFailed(_)));
let error_msg = format!("{}", error);
assert!(error_msg.contains("Test error"));
}
@@ -128,7 +135,7 @@ fn test_nerdctl_error_types() {
#[test]
fn test_container_multiple_ports_and_volumes() {
let result = Container::from_image("multi-config", "nginx:latest");
match result {
Ok(container) => {
let configured = container
@@ -138,15 +145,19 @@ fn test_container_multiple_ports_and_volumes() {
.with_volume("/data2:/app/data2")
.with_env("VAR1", "value1")
.with_env("VAR2", "value2");
assert_eq!(configured.ports.len(), 2);
assert!(configured.ports.contains(&"8080:80".to_string()));
assert!(configured.ports.contains(&"8443:443".to_string()));
assert_eq!(configured.volumes.len(), 2);
assert!(configured.volumes.contains(&"/data1:/app/data1".to_string()));
assert!(configured.volumes.contains(&"/data2:/app/data2".to_string()));
assert!(configured
.volumes
.contains(&"/data1:/app/data1".to_string()));
assert!(configured
.volumes
.contains(&"/data2:/app/data2".to_string()));
assert_eq!(configured.env_vars.len(), 2);
assert_eq!(configured.env_vars.get("VAR1"), Some(&"value1".to_string()));
assert_eq!(configured.env_vars.get("VAR2"), Some(&"value2".to_string()));