Skip to content

Commit

Permalink
feat: Add: 1.separate ut for Windows and Unix.
Browse files Browse the repository at this point in the history
Signed-off-by: photowey <[email protected]>
  • Loading branch information
photowey committed Jul 18, 2024
1 parent 4f992e0 commit f42bc3b
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 49 deletions.
6 changes: 5 additions & 1 deletion crates/env/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ use crate::env;
// ----------------------------------------------------------------

#[cfg(test)]
mod env_tests;
#[cfg(unix)]
mod env_unix_tests;
#[cfg(test)]
#[cfg(windows)]
mod env_windows_test;

// ----------------------------------------------------------------

Expand Down
80 changes: 80 additions & 0 deletions crates/env/src/tests/env_unix_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright © 2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// tests/env_unix_tests

#![allow(unused_imports)]

// @formatter:off
// ----------------------------------------------------------------

#[rustfmt::skip]
mod imports {
pub use omigacore::collection::table::{Table, Value};

pub use crate::env::Environment;
pub use crate::env::standard::StandardEnvironment;
pub use crate::reader::registry::ConfigReaderRegistry;
pub use crate::reader::toml::TomlConfigReader;

}

// @formatter:on
// ----------------------------------------------------------------

#[test]
#[cfg(unix)]
fn test_standard_environment_builder_os_unix() {
let rvt = StandardEnvironment::builder()
.with_table(Table::new())
.with_registry(Box::new(ConfigReaderRegistry::default()))
.with_reader(Box::new(TomlConfigReader::default()))
.with_path("./testdata".to_string())
.with_paths(vec!["./configs".to_string()])
.with_config("omiga".to_string())
.with_configs(vec!["application".to_string()])
.with_profile("dev".to_string())
.with_profiles(vec!["test".to_string()])
.with_format("toml".to_string())
.with_formats(vec!["toml".to_string()])
.with_formats(vec!["toml".to_string(), "toml".to_string()])
.with_search_path("/opt/app/configs".to_string())
.with_search_paths(vec!["/data/configs".to_string()])
.build();

assert!(rvt.is_ok());
}

// ----------------------------------------------------------------

#[test]
#[cfg(unix)]
fn test_standard_environment_os_unix() {
let rvt = StandardEnvironment::builder()
.with_table(Table::new())
.with_registry(Box::new(ConfigReaderRegistry::default()))
.with_reader(Box::new(TomlConfigReader::default()))
.with_path("./testdata".to_string())
.with_config("omiga".to_string())
.with_profile("dev".to_string())
.with_format("toml".to_string())
.with_search_path("/opt/app/configs".to_string())
.build();

let environment = rvt.unwrap();

assert!(environment.get("JAVA_HOME").is_ok());
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,23 @@
* limitations under the License.
*/

// tests/env_tests
// tests/env_windows_test

#![allow(unused_imports)]

// ----------------------------------------------------------------

use omigacore::collection::table::{Table, Value};
use imports::*;

#[rustfmt::skip]
mod imports {
pub use omigacore::collection::table::{Table, Value};

use crate::env::standard::StandardEnvironment;
use crate::env::Environment;
use crate::reader::registry::ConfigReaderRegistry;
use crate::reader::toml::TomlConfigReader;
pub use crate::env::Environment;
pub use crate::env::standard::StandardEnvironment;
pub use crate::reader::registry::ConfigReaderRegistry;
pub use crate::reader::toml::TomlConfigReader;
}

// ----------------------------------------------------------------

Expand All @@ -50,29 +57,6 @@ fn test_standard_environment_builder_os_windows() {
assert!(rvt.is_ok());
}

#[test]
#[cfg(unix)]
fn test_standard_environment_builder_os_unix() {
let rvt = StandardEnvironment::builder()
.with_table(Table::new())
.with_registry(Box::new(ConfigReaderRegistry::default()))
.with_reader(Box::new(TomlConfigReader::default()))
.with_path("./testdata".to_string())
.with_paths(vec!["./configs".to_string()])
.with_config("omiga".to_string())
.with_configs(vec!["application".to_string()])
.with_profile("dev".to_string())
.with_profiles(vec!["test".to_string()])
.with_format("toml".to_string())
.with_formats(vec!["toml".to_string()])
.with_formats(vec!["toml".to_string(), "toml".to_string()])
.with_search_path("/opt/app/configs".to_string())
.with_search_paths(vec!["/data/configs".to_string()])
.build();

assert!(rvt.is_ok());
}

// ----------------------------------------------------------------

#[test]
Expand Down Expand Up @@ -100,25 +84,6 @@ fn test_standard_environment_os_windows() {
);
}

#[test]
#[cfg(unix)]
fn test_standard_environment_os_unix() {
let rvt = StandardEnvironment::builder()
.with_table(Table::new())
.with_registry(Box::new(ConfigReaderRegistry::default()))
.with_reader(Box::new(TomlConfigReader::default()))
.with_path("./testdata".to_string())
.with_config("omiga".to_string())
.with_profile("dev".to_string())
.with_format("toml".to_string())
.with_search_path("/opt/app/configs".to_string())
.build();

let environment = rvt.unwrap();

assert!(environment.get("JAVA_HOME").is_ok());
}

#[test]
#[cfg(windows)]
fn test_standard_environment_os_unix() {
Expand Down

0 comments on commit f42bc3b

Please sign in to comment.