1mod action;
2mod client;
3mod page;
4mod types;
5
6pub use action::action;
7pub(crate) use client::{client, handle, url};
8pub use page::page;
9pub use types::{Error, Result};
10
11pub fn is_test() -> bool {
12 std::env::args().any(|e| e == "--test")
13}
14
15pub fn mock<T1, T2>(tid: Option<String>, input: T1) -> T2
16where
17 T1: serde::Serialize,
18 T2: serde::de::DeserializeOwned,
19{
20 let tid = match tid {
21 Some(v) => v,
22 None => panic!("tid is none in test mode"),
23 };
24
25 std::fs::create_dir_all("out").unwrap();
28 let out = format!("out/{}.out.json", tid.as_str());
29 std::fs::write(
30 out.as_str(),
31 sorted_json::to_json(&serde_json::to_value(input).unwrap()),
32 )
33 .unwrap_or_else(|e| panic!("failed to write to: {}, err={:?}", out, e));
34
35 let input = format!("{}.in.json", tid.as_str());
36
37 serde_json::from_str(
38 std::fs::read_to_string(input.as_str())
39 .unwrap_or_else(|e| panic!("failed to read from: {}, err={:?}", input, e))
40 .as_str(),
41 )
42 .expect("failed to parse json")
43}