Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion firecracker-pilot/guestvm-tools/sci/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ fn main() {
}
}
if ok {
let overlay_dirs = vec![
let overlay_dirs = [
defaults::OVERLAY_ROOT,
defaults::OVERLAY_UPPER,
defaults::OVERLAY_WORK
Expand Down
46 changes: 2 additions & 44 deletions firecracker-pilot/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn load_config() -> Config<'static> {
config_from_str(&full_yaml)
}

fn config_from_str(input: &str) -> Config<'static> {
pub fn config_from_str(input: &str) -> Config<'static> {
// Parse into a generic YAML to remove duplicate keys

let yaml = yaml_rust::YamlLoader::load_from_str(input).unwrap();
Expand All @@ -92,7 +92,7 @@ fn config_from_str(input: &str) -> Config<'static> {
serde_yaml::from_str(content).unwrap()
}

fn config_file(program: &str) -> String {
pub fn config_file(program: &str) -> String {
format!("{}/{}.yaml", get_flakes_dir(), program)
}

Expand Down Expand Up @@ -199,45 +199,3 @@ impl Default for CacheType {
Self::Writeback
}
}

#[cfg(test)]
mod test {
use crate::config::config_file;

use super::config_from_str;

#[test]
fn simple_config() {
let cfg = config_from_str(
r#"vm:
name: JoJo
host_app_path: /myapp
include:
tar: ~
"#,
);
assert_eq!(cfg.vm.name, "JoJo");
}

#[test]
fn combine_configs() {
let cfg = config_from_str(
r#"vm:
name: JoJo
host_app_path: /myapp
include:
tar: ~
vm:
name: Dio
host_app_path: /other
"#,
);
assert_eq!(cfg.vm.name, "Dio");
}

#[test]
fn test_program_config_file() {
let config_file = config_file("app");
assert_eq!("/usr/share/flakes/app.yaml", config_file);
}
}
3 changes: 3 additions & 0 deletions firecracker-pilot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
#[macro_use]
extern crate log;

#[cfg(test)]
pub mod tests;

use std::process::{ExitCode, Termination};

use config::config;
Expand Down
60 changes: 60 additions & 0 deletions firecracker-pilot/src/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// Copyright (c) 2022 Elektrobit Automotive GmbH
//
// This file is part of flake-pilot
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
use crate::config::config_file;
use crate::config::config_from_str;

#[test]
fn simple_config() {
let cfg = config_from_str(
r#"vm:
name: JoJo
host_app_path: /myapp
include:
tar: ~
"#,
);
assert_eq!(cfg.vm.name, "JoJo");
}

#[test]
fn combine_configs() {
let cfg = config_from_str(
r#"vm:
name: JoJo
host_app_path: /myapp
include:
tar: ~
vm:
name: Dio
host_app_path: /other
"#,
);
assert_eq!(cfg.vm.name, "Dio");
}

#[test]
fn test_program_config_file() {
let config_file = config_file("app");
assert_eq!("/usr/share/flakes/app.yaml", config_file);
}
44 changes: 2 additions & 42 deletions podman-pilot/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fn load_config() -> Config<'static> {

}

fn config_from_str(input: &str) -> Config<'static> {
pub fn config_from_str(input: &str) -> Config<'static> {
// Parse into a generic YAML to remove duplicate keys

let yaml = yaml_rust::YamlLoader::load_from_str(input).unwrap();
Expand All @@ -89,7 +89,7 @@ fn config_from_str(input: &str) -> Config<'static> {
serde_yaml::from_str(content).unwrap()
}

fn config_file(program: &str) -> String {
pub fn config_file(program: &str) -> String {
format!("{}/{}.yaml", get_flakes_dir(), program)
}

Expand Down Expand Up @@ -199,43 +199,3 @@ pub struct RuntimeSection<'a> {
#[serde(default)]
pub podman: Option<Vec<&'a str>>,
}

#[cfg(test)]
mod test {
use crate::config::config_file;

use super::config_from_str;

#[test]
fn simple_config() {
let cfg = config_from_str(
r#"container:
name: JoJo
host_app_path: /myapp
include:
tar: ~
"#);
assert_eq!(cfg.container.name, "JoJo");
}

#[test]
fn combine_configs() {
let cfg = config_from_str(
r#"container:
name: JoJo
host_app_path: /myapp
include:
tar: ~
container:
name: Dio
host_app_path: /other
"#);
assert_eq!(cfg.container.name, "Dio");
}

#[test]
fn test_program_config_file() {
let config_file = config_file(&"app".to_string());
assert_eq!("/usr/share/flakes/app.yaml", config_file);
}
}
35 changes: 35 additions & 0 deletions podman-pilot/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
//
use crate::app_path::program_abs_path;
use crate::app_path::basename;
use crate::config::config_file;
use crate::config::config_from_str;

#[test]
fn test_program_abs_path() {
Expand All @@ -35,3 +37,36 @@ fn test_basename() {
let base_name = basename(&"/some/name".to_string());
assert_eq!("name", base_name);
}

#[test]
fn simple_config() {
let cfg = config_from_str(
r#"container:
name: JoJo
host_app_path: /myapp
include:
tar: ~
"#);
assert_eq!(cfg.container.name, "JoJo");
}

#[test]
fn combine_configs() {
let cfg = config_from_str(
r#"container:
name: JoJo
host_app_path: /myapp
include:
tar: ~
container:
name: Dio
host_app_path: /other
"#);
assert_eq!(cfg.container.name, "Dio");
}

#[test]
fn test_program_config_file() {
let config_file = config_file(&"app".to_string());
assert_eq!("/usr/share/flakes/app.yaml", config_file);
}