Skip to content

Commit

Permalink
Add e2e test in hurl
Browse files Browse the repository at this point in the history
  • Loading branch information
allevo committed Oct 31, 2024
1 parent 6cd7aac commit 053d875
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ jobs:
cargo check --target x86_64-unknown-linux-gnu
cargo fmt -- --check
cargo clippy --target x86_64-unknown-linux-gnu -- -D warnings
cargo test --target x86_64-unknown-linux-gnu
cargo build --target x86_64-unknown-linux-gnu
6 changes: 6 additions & 0 deletions rustorama/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ config = { version = "0.14.0", features = ["json5"] }
anyhow = "1.0.91"
serde = { version = "1.0.214", features = ["derive"] }
tokio = { version = "1", features = ["full"] }

[dev-dependencies]
futures = "0.3.31"
hurl = "5.0.1"
hurl_core = "5.0.1"
tempdir = "0.3.7"
78 changes: 77 additions & 1 deletion rustorama/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::sync::Arc;

use anyhow::Context;
use anyhow::{Context, Result};
use collection_manager::{CollectionManager, CollectionsConfiguration};
use config::Config;
use rocksdb::OptimisticTransactionDB;
Expand Down Expand Up @@ -28,6 +28,12 @@ async fn main() -> anyhow::Result<()> {
.try_deserialize::<RustoramaConfig>()
.context("Failed to deserialize configuration")?;

start(config).await?;

Ok(())
}

async fn start(config: RustoramaConfig) -> Result<()> {
let manager = create_manager(config.clone());
let manager = Arc::new(manager);
let web_server = WebServer::new(manager);
Expand All @@ -43,3 +49,73 @@ fn create_manager(config: RustoramaConfig) -> CollectionManager {

CollectionManager::new(CollectionsConfiguration { storage })
}

#[cfg(test)]
mod tests {
use super::*;

use std::collections::HashMap;
use std::time::Duration;
use futures::future::Either;
use hurl::runner;
use hurl::runner::{Value, RunnerOptionsBuilder};
use hurl::util::logger::{LoggerOptionsBuilder, Verbosity};
use futures::{future, pin_mut};
use tempdir::TempDir;
use tokio::time::sleep;

#[tokio::test]
async fn test_hurl() {
const HOST: &str = "127.0.0.1";
const PORT: u16 = 8080;

async fn run() {
let data_dir = TempDir::new("string_index_test").unwrap();
let data_dir: String = data_dir.into_path().to_str().unwrap().to_string();
let config = RustoramaConfig {
data_dir,
http: HttpConfig {
host: HOST.parse().unwrap(),
port: PORT,
},
};
start(config).await.unwrap();
}
async fn run_test() {
sleep(Duration::from_secs(5)).await;

let content = include_str!("../../api-test.hurl");

let runner_opts = RunnerOptionsBuilder::new()
.follow_location(true)
.build();
let logger_opts = LoggerOptionsBuilder::new()
.verbosity(Some(Verbosity::Verbose))
.build();

let variables: HashMap<_, _> = vec![
("base_url".to_string(), Value::String(format!("http://{}:{}", HOST, PORT))),
].into_iter().collect();

let result = runner::run(
content,
None,
&runner_opts,
&variables,
&logger_opts
);
assert!(result.unwrap().success);
}

let future1 = run();
let future2 = run_test();

pin_mut!(future1);
pin_mut!(future2);

match future::select(future1, future2).await {
Either::Left((value1, _)) => value1,
Either::Right((value2, _)) => value2,
};
}
}

0 comments on commit 053d875

Please sign in to comment.