-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
template_tests: add test example in plugin template
closes #8
- Loading branch information
Showing
3 changed files
with
80 additions
and
1 deletion.
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
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,63 @@ | ||
use log::info; | ||
use std::{ | ||
fs::{self}, | ||
io::ErrorKind, | ||
path::{Path, PathBuf}, | ||
}; | ||
|
||
// TODO: check in workspaces | ||
pub const TMP_DIR: &str = "tmp/"; | ||
pub const TOPOLOGY_PATH: &str = "topology.toml"; | ||
pub const TARGET_DIR: &str = "target"; | ||
|
||
pub struct Cluster {} | ||
|
||
impl Drop for Cluster { | ||
fn drop(&mut self) { | ||
let data_dir = PathBuf::from(TMP_DIR.to_owned()); | ||
pike::cluster::stop(&data_dir).unwrap(); | ||
} | ||
} | ||
|
||
impl Cluster { | ||
pub fn new() -> Cluster { | ||
info!("cleaning artefacts from previous run"); | ||
|
||
match fs::remove_file(Path::new(TMP_DIR).join("instance.log")) { | ||
Ok(()) => info!("Clearing logs."), | ||
Err(e) if e.kind() == ErrorKind::NotFound => { | ||
info!("instance.log not found, skipping cleanup"); | ||
}, | ||
Err(e) => panic!("failed to delete instance.log: {e}"), | ||
} | ||
|
||
match fs::remove_dir_all(TMP_DIR) { | ||
Ok(()) => info!("clearing test plugin dir."), | ||
Err(e) if e.kind() == ErrorKind::NotFound => { | ||
info!("plugin dir not found, skipping cleanup"); | ||
}, | ||
Err(e) => panic!("failed to delete plugin_dir: {e}"), | ||
} | ||
|
||
Cluster {} | ||
} | ||
} | ||
|
||
pub fn run_cluster() -> Cluster { | ||
let cluster_handle = Cluster::new(); | ||
let data_dir = PathBuf::from(TMP_DIR.to_owned()); | ||
let topology_path = PathBuf::from(TOPOLOGY_PATH.to_owned()); | ||
let target_dir = PathBuf::from(TARGET_DIR.to_owned()); | ||
pike::cluster::run( | ||
&topology_path, | ||
&data_dir, | ||
false, | ||
8000, | ||
&PathBuf::from("picodata".to_owned()), | ||
5432, | ||
false, | ||
&target_dir, | ||
) | ||
.unwrap(); | ||
cluster_handle | ||
} |
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,11 @@ | ||
mod helpers; | ||
|
||
use helpers::run_cluster; | ||
use reqwest::blocking as req; | ||
|
||
#[test] | ||
fn test_metrics() { | ||
let _cluster_handle = run_cluster(); | ||
let resp = req::get("http://localhost:8001/metrics").unwrap(); | ||
assert!(resp.status().is_success()); | ||
} |