From 342ac49beadcf36f467e574282424318609d068c Mon Sep 17 00:00:00 2001 From: Suyono Date: Fri, 1 Dec 2023 22:33:52 +0000 Subject: [PATCH 1/3] add: test helper binaries --- Cargo.toml | 9 +++++++++ src/bin/test-helper/dummy.rs | 11 +++++++++++ src/bin/test-helper/spawner.rs | 15 +++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 src/bin/test-helper/dummy.rs create mode 100644 src/bin/test-helper/spawner.rs diff --git a/Cargo.toml b/Cargo.toml index 2762a51..e1c3065 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,15 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[[bin]] +name = "dummy" +path = "src/bin/test-helper/dummy.rs" + +[[bin]] +name = "spawner" +path = "src/bin/test-helper/spawner.rs" + + [dependencies] anyhow = "1.0.75" lazy_static = "1.4.0" diff --git a/src/bin/test-helper/dummy.rs b/src/bin/test-helper/dummy.rs new file mode 100644 index 0000000..14b3c15 --- /dev/null +++ b/src/bin/test-helper/dummy.rs @@ -0,0 +1,11 @@ +use std::{env, thread, time}; + + +fn main() { + let myi: u64; + let args: Vec = env::args().collect(); + if args.len() > 1 { + myi = args[1].parse().unwrap(); + thread::sleep(time::Duration::from_secs(myi)); + } +} diff --git a/src/bin/test-helper/spawner.rs b/src/bin/test-helper/spawner.rs new file mode 100644 index 0000000..6ac0c46 --- /dev/null +++ b/src/bin/test-helper/spawner.rs @@ -0,0 +1,15 @@ +use std::error::Error; +use std::process::Command; +use std::env; + +fn main() -> Result<(), Box> { + let args: Vec = env::args().collect(); + if args.len() > 1 { + let x: u64 = args[1].parse()?; + for _i in 0..x { + // println!("spawning {}", _i); + Command::new("/usr/local/bin/dummy").arg("10").spawn()?; + } + } + Ok(()) +} From 64fa76d39be38768d2003588ad63464cc80a1778 Mon Sep 17 00:00:00 2001 From: Suyono Date: Sat, 2 Dec 2023 14:04:58 +1100 Subject: [PATCH 2/3] add: log test helper --- Cargo.toml | 8 ++++++-- coba.txt | 2 ++ src/bin/test-helper/dummy.rs | 6 +++++- src/bin/test-helper/log.rs | 19 +++++++++++++++++++ src/bin/test-helper/spawner.rs | 2 ++ src/init/error.rs | 13 +++++-------- src/{bin/init.rs => main.rs} | 2 +- 7 files changed, 40 insertions(+), 12 deletions(-) create mode 100644 coba.txt create mode 100644 src/bin/test-helper/log.rs rename src/{bin/init.rs => main.rs} (89%) diff --git a/Cargo.toml b/Cargo.toml index e1c3065..0d95386 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,13 +6,17 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [[bin]] -name = "dummy" +name = "wmtest-helper-dummy" path = "src/bin/test-helper/dummy.rs" [[bin]] -name = "spawner" +name = "wmtest-helper-spawner" path = "src/bin/test-helper/spawner.rs" +[[bin]] +name = "wmtest-helper-log" +path = "src/bin/test-helper/log.rs" + [dependencies] anyhow = "1.0.75" diff --git a/coba.txt b/coba.txt new file mode 100644 index 0000000..570405e --- /dev/null +++ b/coba.txt @@ -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 diff --git a/src/bin/test-helper/dummy.rs b/src/bin/test-helper/dummy.rs index 14b3c15..e070065 100644 --- a/src/bin/test-helper/dummy.rs +++ b/src/bin/test-helper/dummy.rs @@ -1,11 +1,15 @@ use std::{env, thread, time}; -fn main() { +fn main() -> Result<(), Box> { let myi: u64; let args: Vec = env::args().collect(); if args.len() > 1 { myi = args[1].parse().unwrap(); thread::sleep(time::Duration::from_secs(myi)); + } else { + return Err(anyhow::anyhow!("invalid arguments").into()); } + + Ok(()) } diff --git a/src/bin/test-helper/log.rs b/src/bin/test-helper/log.rs new file mode 100644 index 0000000..d11ea80 --- /dev/null +++ b/src/bin/test-helper/log.rs @@ -0,0 +1,19 @@ +use std::env; +use std::fs; +use std::io; +use std::io::Write; +use time::OffsetDateTime; + +fn main() -> Result<(), Box> { + let args: Vec = 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(()) +} \ No newline at end of file diff --git a/src/bin/test-helper/spawner.rs b/src/bin/test-helper/spawner.rs index 6ac0c46..c641793 100644 --- a/src/bin/test-helper/spawner.rs +++ b/src/bin/test-helper/spawner.rs @@ -10,6 +10,8 @@ fn main() -> Result<(), Box> { // println!("spawning {}", _i); Command::new("/usr/local/bin/dummy").arg("10").spawn()?; } + } else { + return Err(anyhow::anyhow!("invalid arguments").into()); } Ok(()) } diff --git a/src/init/error.rs b/src/init/error.rs index 2634896..67b5de7 100644 --- a/src/init/error.rs +++ b/src/init/error.rs @@ -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")] ClashingConfig, - #[error("when setting time for higher order, the smallest (minute) muste be set")] - MissingMinute, - - #[error("something went wrong")] - Other { - #[source] - source: anyhow::Error, - } + // #[error("something went wrong")] + // Other { + // #[source] + // source: anyhow::Error, + // } } #[derive(Error,Debug)] diff --git a/src/bin/init.rs b/src/main.rs similarity index 89% rename from src/bin/init.rs rename to src/main.rs index e6a44b9..7fc0b50 100644 --- a/src/bin/init.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ +mod init; use std::error; -use wingmate_rs::init; #[tokio::main] async fn main() -> Result<(), Box> { From b4f81ccf30f88f84c49fd4507afd26d895181087 Mon Sep 17 00:00:00 2001 From: Suyono Date: Sat, 2 Dec 2023 14:45:01 +1100 Subject: [PATCH 3/3] chore: remove tmp file from git index --- .gitignore | 1 + coba.txt | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) delete mode 100644 coba.txt diff --git a/.gitignore b/.gitignore index ea8c4bf..218f39f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +/coba.txt \ No newline at end of file diff --git a/coba.txt b/coba.txt deleted file mode 100644 index 570405e..0000000 --- a/coba.txt +++ /dev/null @@ -1,2 +0,0 @@ -2023-12-02 2:24:47.539978006 +00:00:00 hello world -2023-12-02 2:25:04.397220985 +00:00:00 hello world