-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
491 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Generated by Cargo | ||
# will have compiled files and executables | ||
debug/ | ||
target/ | ||
|
||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries | ||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html | ||
Cargo.lock | ||
|
||
# These are backup files generated by rustfmt | ||
**/*.rs.bk | ||
|
||
# MSVC Windows builds of rustc generate these, which store debugging information | ||
*.pdb | ||
|
||
# Added by cargo | ||
/target | ||
|
||
# Editor Configs | ||
.idea/ | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[package] | ||
name = "isotoenv" | ||
version = "0.1.0" | ||
edition = "2021" | ||
description = "A library for creating an openQA test environment on a designated target" | ||
readme = "README.md" | ||
repository = "https://github.com/os-autoinst/isotest-ng/tree/main/isotoenv" | ||
license = "GPL-2.0" | ||
|
||
[dependencies] | ||
log = "0.4.22" | ||
env_logger = { version = "0.11.5", optional = true } | ||
|
||
[dev-dependencies] | ||
|
||
[features] | ||
# Feature to enable default logging configuration | ||
default-logging = ["env_logger"] |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# isotoenv | ||
|
||
Set up a [openQA](https://open.qa) test environment on a remote worker. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
//! This module defines custom error types to be returned by `isototest`. | ||
//! These types are thematically split into submodules. | ||
pub mod util_errors; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//! This module defines and implements error type which refer to the supporting util of this library. | ||
//! This means functionality like logging and similar supporting functionality, which do not necessarily | ||
//! impact the core functionality of this library itself. | ||
use std::fmt; | ||
|
||
#[derive(Debug)] | ||
#[cfg(feature = "default-logging")] | ||
pub enum LoggingError { | ||
LoggingInitError(String), | ||
InvalidLogLevelError(String), | ||
} | ||
|
||
#[cfg(feature = "default-logging")] | ||
impl fmt::Display for LoggingError { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
LoggingError::LoggingInitError(msg) => { | ||
write!(f, "[error] Logging initialization failed: '{}'", msg) | ||
} | ||
LoggingError::InvalidLogLevelError(msg) => { | ||
write!(f, "[error] Invalid log level: '{}'", msg) | ||
} | ||
} | ||
} | ||
} | ||
|
||
#[cfg(feature = "default-logging")] | ||
impl std::error::Error for LoggingError {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//! Prepare a test environment for [openQA](https://open.qa). | ||
//! | ||
//! This crate is responsible for preparing an `openQA` worker machine or VM for executing the test suite. | ||
//! | ||
//! ## Optional Features | ||
//! | ||
//! * `default-logging` - Provides you with a sensible logger configuration using the `env_logger` crate. | ||
// Organize library structure | ||
pub mod logging; | ||
pub mod errors; | ||
|
||
// Provide code on the root level of the library | ||
#[cfg(feature = "default-logging")] | ||
use crate::logging::init_default_logging; | ||
#[cfg(feature = "default-logging")] | ||
use crate::errors::util_errors::LoggingError; | ||
|
||
#[cfg(feature = "default-logging")] | ||
pub fn init_logging(level: Option<&str>) -> Result<(), LoggingError> { | ||
init_default_logging(level)?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
//! This module provides a sensible default configuration of a logging system. | ||
#[cfg(feature = "default-logging")] | ||
use env_logger::Builder; | ||
#[cfg(feature = "default-logging")] | ||
use std::io::Write; | ||
#[cfg(feature = "default-logging")] | ||
use crate::errors::util_errors::LoggingError; | ||
|
||
pub const LOG_TARGET: &str = "[isototest]"; | ||
|
||
#[cfg(feature = "default-logging")] | ||
/// Initialize default logging configuration with given log level. | ||
/// | ||
/// Log Level can be: | ||
/// * "info" - Default log level also adapted if level is `none`. Logs events relevant for general usage. | ||
/// * "debug" - Debug level for extended logging. Should only be used for development purposes. | ||
/// * "trace" - Extensive log evel logging every event. Should only be used for development purposes. | ||
/// | ||
pub(crate) fn init_default_logging(level: Option<&str>) -> Result<(), LoggingError> { | ||
match level { | ||
Some("info") | None => { | ||
log_builder(log::LevelFilter::Info); | ||
Ok(()) | ||
}, | ||
Some("debug") => { | ||
log_builder(log::LevelFilter::Debug); | ||
Ok(()) | ||
}, | ||
Some("trace") => { | ||
log_builder(log::LevelFilter::Trace); | ||
Ok(()) | ||
}, | ||
Some(invalid) => { | ||
Err(LoggingError::InvalidLogLevelError(format!("Invalid log level '{}'!", invalid))) | ||
} | ||
} | ||
} | ||
|
||
#[cfg(feature = "default-logging")] | ||
fn log_builder(level: log::LevelFilter) { | ||
Builder::new() | ||
.filter_level(level) | ||
.format(|buf, record| { | ||
writeln!( | ||
buf, | ||
"{} [{}] {}: {}", | ||
buf.timestamp(), | ||
record.level(), | ||
record.target(), | ||
record.args() | ||
) | ||
}) | ||
.init(); | ||
} | ||
|