Skip to content

Commit

Permalink
Separate unit and e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
robbie-c committed Jan 6, 2025
1 parent 3be98b7 commit 15b8452
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ jobs:
- name: Build
run: cargo build --verbose

- name: Test
- name: Unit test
run: cargo test --verbose

- name: E2E test
run: cargo test --features e2e-test --no-default-features

- name: Check formatting
run: cargo fmt -- --check

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
*.iml
.idea/
Cargo.lock
.env
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,10 @@ reqwest = { version = "0.11.3", default-features = false, features = ["blocking"
serde = { version = "1.0.125", features = ["derive"] }
chrono = {version = "0.4.19", features = ["serde"] }
serde_json = "1.0.64"

[dev-dependencies]
dotenv = "0.15.0"
ctor = "0.1.26"

[features]
e2e-test = []
19 changes: 17 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,29 @@ impl Event {
}
}

#[cfg(test)]
mod test_setup {
use ctor::ctor;
use dotenv::dotenv;

#[ctor]
fn load_dotenv() {
dotenv().ok(); // Load the .env file
println!("Loaded .env for tests");
}
}

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

#[cfg(feature = "e2e-test")]
#[test]
fn get_client() {
let client = crate::client(env!("POSTHOG_API_KEY"));
use std::collections::HashMap;

let api_key = std::env::var("POSTHOG_RS_E2E_TEST_API_KEY").unwrap();
let client = crate::client(api_key.as_str());

let mut child_map = HashMap::new();
child_map.insert("child_key1", "child_value1");
Expand Down

0 comments on commit 15b8452

Please sign in to comment.