1
0
Fork 0
mirror of https://github.com/containers/youki synced 2024-05-21 06:56:06 +02:00
youki/tests/integration_test/src/tests/hostname/mod.rs
Yashodhan 80f1f36ae9
Refactor test dir structure (#2421)
* Move individual rust-oci-tests components in the tests dir

We can use several things from test_framework and even integration_test
for additional tests such as podman rootless and wasm tests

Signed-off-by: Yashodhan Joshi <yjdoc2@gmail.com>

* fix scripts and docs for the new dir structure

Signed-off-by: Yashodhan Joshi <yjdoc2@gmail.com>

---------

Signed-off-by: Yashodhan Joshi <yjdoc2@gmail.com>
2023-10-10 21:00:02 +09:00

52 lines
1.7 KiB
Rust

use oci_spec::runtime::{LinuxBuilder, ProcessBuilder, Spec, SpecBuilder};
use test_framework::{Test, TestGroup, TestResult};
use crate::utils::test_inside_container;
fn create_spec(hostname: &str) -> Spec {
SpecBuilder::default()
.hostname(hostname)
.linux(
// Need to reset the read-only paths
LinuxBuilder::default()
.readonly_paths(vec![])
.build()
.expect("error in building linux config"),
)
.process(
ProcessBuilder::default()
.args(vec!["runtimetest".to_string(), "set_host_name".to_string()])
.build()
.expect("error in creating process config"),
)
.build()
.unwrap()
}
fn hostname_test() -> TestResult {
let spec = create_spec("hostname-specific");
test_inside_container(spec, &|_| {
// As long as the container is created, we expect the hostname to be determined
// by the spec, so nothing to prepare prior.
Ok(())
})
}
fn empty_hostname() -> TestResult {
let spec = create_spec("");
test_inside_container(spec, &|_| {
// As long as the container is created, we expect the hostname to be determined
// by the spec, so nothing to prepare prior.
Ok(())
})
}
pub fn get_hostname_test() -> TestGroup {
let mut test_group = TestGroup::new("set_host_name");
let hostname_test = Test::new("set_host_name_test", Box::new(hostname_test));
let empty_hostname_test = Test::new("set_empty_host_name_test", Box::new(empty_hostname));
test_group.add(vec![Box::new(hostname_test), Box::new(empty_hostname_test)]);
test_group
}