...
This commit is contained in:
76
src/virt/nerdctl/container_test.rs
Normal file
76
src/virt/nerdctl/container_test.rs
Normal file
@@ -0,0 +1,76 @@
|
||||
// File: /root/code/git.ourworld.tf/herocode/sal/src/virt/nerdctl/container_test.rs
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::super::container_types::{Container, ContainerStatus, ResourceUsage};
|
||||
use super::super::NerdctlError;
|
||||
use std::error::Error;
|
||||
|
||||
#[test]
|
||||
fn test_container_builder_pattern() {
|
||||
// Create a container with builder pattern
|
||||
let container = Container::new("test-container").unwrap()
|
||||
.with_port("8080:80")
|
||||
.with_volume("/tmp:/data")
|
||||
.with_env("TEST_ENV", "test_value")
|
||||
.with_detach(true);
|
||||
|
||||
// Verify container properties
|
||||
assert_eq!(container.name, "test-container");
|
||||
assert_eq!(container.ports.len(), 1);
|
||||
assert_eq!(container.ports[0], "8080:80");
|
||||
assert_eq!(container.volumes.len(), 1);
|
||||
assert_eq!(container.volumes[0], "/tmp:/data");
|
||||
assert_eq!(container.env_vars.len(), 1);
|
||||
assert_eq!(container.env_vars.get("TEST_ENV").unwrap(), "test_value");
|
||||
assert_eq!(container.detach, true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_container_from_image() {
|
||||
// Create a container from image
|
||||
let container = Container::from_image("test-container", "alpine:latest").unwrap();
|
||||
|
||||
// Verify container properties
|
||||
assert_eq!(container.name, "test-container");
|
||||
assert_eq!(container.image.as_ref().unwrap(), "alpine:latest");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_container_health_check() {
|
||||
// Create a container with health check
|
||||
let container = Container::new("test-container").unwrap()
|
||||
.with_health_check("curl -f http://localhost/ || exit 1");
|
||||
|
||||
// Verify health check
|
||||
assert!(container.health_check.is_some());
|
||||
let health_check = container.health_check.unwrap();
|
||||
assert_eq!(health_check.cmd, "curl -f http://localhost/ || exit 1");
|
||||
assert!(health_check.interval.is_none());
|
||||
assert!(health_check.timeout.is_none());
|
||||
assert!(health_check.retries.is_none());
|
||||
assert!(health_check.start_period.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_container_health_check_options() {
|
||||
// Create a container with health check options
|
||||
let container = Container::new("test-container").unwrap()
|
||||
.with_health_check_options(
|
||||
"curl -f http://localhost/ || exit 1",
|
||||
Some("30s"),
|
||||
Some("10s"),
|
||||
Some(3),
|
||||
Some("5s")
|
||||
);
|
||||
|
||||
// Verify health check options
|
||||
assert!(container.health_check.is_some());
|
||||
let health_check = container.health_check.unwrap();
|
||||
assert_eq!(health_check.cmd, "curl -f http://localhost/ || exit 1");
|
||||
assert_eq!(health_check.interval.as_ref().unwrap(), "30s");
|
||||
assert_eq!(health_check.timeout.as_ref().unwrap(), "10s");
|
||||
assert_eq!(health_check.retries.unwrap(), 3);
|
||||
assert_eq!(health_check.start_period.as_ref().unwrap(), "5s");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user