1
0
Fork 0
mirror of https://github.com/containers/youki synced 2024-05-10 01:26:14 +02:00
youki/tests/contest/contest/src/tests/hostname/mod.rs
Toru Komatsu 464344923f
Name the test tools `contest` (#2486)
* Name the test tools `contest`

Signed-off-by: utam0k <k0ma@utam0k.jp>

* Address the feedbacks

Signed-off-by: utam0k <k0ma@utam0k.jp>

* Fix a build error

Signed-off-by: utam0k <k0ma@utam0k.jp>

* Fix a workflow

Signed-off-by: utam0k <k0ma@utam0k.jp>

* Address the feedbacks

Signed-off-by: utam0k <k0ma@utam0k.jp>

---------

Signed-off-by: utam0k <k0ma@utam0k.jp>
2024-01-12 14:28:47 +05:30

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
}