add: log test helper
This commit is contained in:
parent
342ac49bea
commit
64fa76d39b
@ -6,13 +6,17 @@ edition = "2021"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "dummy"
|
name = "wmtest-helper-dummy"
|
||||||
path = "src/bin/test-helper/dummy.rs"
|
path = "src/bin/test-helper/dummy.rs"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "spawner"
|
name = "wmtest-helper-spawner"
|
||||||
path = "src/bin/test-helper/spawner.rs"
|
path = "src/bin/test-helper/spawner.rs"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "wmtest-helper-log"
|
||||||
|
path = "src/bin/test-helper/log.rs"
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.75"
|
anyhow = "1.0.75"
|
||||||
|
|||||||
2
coba.txt
Normal file
2
coba.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
2023-12-02 2:24:47.539978006 +00:00:00 hello world
|
||||||
|
2023-12-02 2:25:04.397220985 +00:00:00 hello world
|
||||||
@ -1,11 +1,15 @@
|
|||||||
use std::{env, thread, time};
|
use std::{env, thread, time};
|
||||||
|
|
||||||
|
|
||||||
fn main() {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let myi: u64;
|
let myi: u64;
|
||||||
let args: Vec<String> = env::args().collect();
|
let args: Vec<String> = env::args().collect();
|
||||||
if args.len() > 1 {
|
if args.len() > 1 {
|
||||||
myi = args[1].parse().unwrap();
|
myi = args[1].parse().unwrap();
|
||||||
thread::sleep(time::Duration::from_secs(myi));
|
thread::sleep(time::Duration::from_secs(myi));
|
||||||
|
} else {
|
||||||
|
return Err(anyhow::anyhow!("invalid arguments").into());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
19
src/bin/test-helper/log.rs
Normal file
19
src/bin/test-helper/log.rs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
use std::env;
|
||||||
|
use std::fs;
|
||||||
|
use std::io;
|
||||||
|
use std::io::Write;
|
||||||
|
use time::OffsetDateTime;
|
||||||
|
|
||||||
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let args: Vec<String> = env::args().collect();
|
||||||
|
|
||||||
|
if args.len() == 3 {
|
||||||
|
let file = fs::OpenOptions::new().create(true).append(true).open(&args[1])?;
|
||||||
|
let mut buf = io::BufWriter::new(file);
|
||||||
|
let local_time = OffsetDateTime::now_local()?;
|
||||||
|
buf.write_all(format!("{} {}\n", local_time, &args[2]).as_bytes())?;
|
||||||
|
} else {
|
||||||
|
return Err(anyhow::anyhow!("invalid argument").into());
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@ -10,6 +10,8 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
// println!("spawning {}", _i);
|
// println!("spawning {}", _i);
|
||||||
Command::new("/usr/local/bin/dummy").arg("10").spawn()?;
|
Command::new("/usr/local/bin/dummy").arg("10").spawn()?;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return Err(anyhow::anyhow!("invalid arguments").into());
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@ -75,14 +75,11 @@ pub enum CronConfigError {
|
|||||||
#[error("setting day of week and day of month at the same time will lead to unexpected behavior")]
|
#[error("setting day of week and day of month at the same time will lead to unexpected behavior")]
|
||||||
ClashingConfig,
|
ClashingConfig,
|
||||||
|
|
||||||
#[error("when setting time for higher order, the smallest (minute) muste be set")]
|
// #[error("something went wrong")]
|
||||||
MissingMinute,
|
// Other {
|
||||||
|
// #[source]
|
||||||
#[error("something went wrong")]
|
// source: anyhow::Error,
|
||||||
Other {
|
// }
|
||||||
#[source]
|
|
||||||
source: anyhow::Error,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Error,Debug)]
|
#[derive(Error,Debug)]
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
|
mod init;
|
||||||
|
|
||||||
use std::error;
|
use std::error;
|
||||||
use wingmate_rs::init;
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn error::Error>> {
|
async fn main() -> Result<(), Box<dyn error::Error>> {
|
||||||
Loading…
x
Reference in New Issue
Block a user