oci_spec/runtime/
test.rs

1#[cfg(test)]
2use super::*;
3
4#[test]
5fn serialize_and_deserialize_spec() {
6    let spec: Spec = Default::default();
7    let json_string = serde_json::to_string(&spec).unwrap();
8    let new_spec = serde_json::from_str(&json_string).unwrap();
9    assert_eq!(spec, new_spec);
10}
11
12#[test]
13fn test_linux_device_cgroup_to_string() {
14    let ldc = LinuxDeviceCgroupBuilder::default()
15        .allow(true)
16        .typ(LinuxDeviceType::B)
17        .access("rwm".to_string())
18        .build()
19        .expect("build device cgroup");
20    assert_eq!(ldc.to_string(), "b *:* rwm");
21
22    let ldc = LinuxDeviceCgroupBuilder::default()
23        .allow(true)
24        .typ(LinuxDeviceType::A)
25        .major(1)
26        .minor(9)
27        .access("rwm".to_string())
28        .build()
29        .expect("build device cgroup");
30    assert_eq!(ldc.to_string(), "a 1:9 rwm");
31}
32
33#[test]
34fn test_load_sample_spec() {
35    let fixture_path = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
36        .join("src/runtime/test/fixture/sample.json");
37    let err = Spec::load(fixture_path);
38    assert!(err.is_ok(), "failed to load spec: {err:?}");
39}
40
41#[test]
42fn test_load_sample_windows_spec() {
43    let fixture_path = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
44        .join("src/runtime/test/fixture/sample_windows.json");
45    let err = Spec::load(fixture_path);
46    assert!(err.is_ok(), "failed to load spec: {err:?}");
47}