Skip to content

Commit 15b8452

Browse files
committed
Separate unit and e2e tests
1 parent 3be98b7 commit 15b8452

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

.github/workflows/pr.yaml

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ jobs:
2424
- name: Build
2525
run: cargo build --verbose
2626

27-
- name: Test
27+
- name: Unit test
2828
run: cargo test --verbose
2929

30+
- name: E2E test
31+
run: cargo test --features e2e-test --no-default-features
32+
3033
- name: Check formatting
3134
run: cargo fmt -- --check
3235

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
*.iml
33
.idea/
44
Cargo.lock
5+
.env

Cargo.toml

+7
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,10 @@ reqwest = { version = "0.11.3", default-features = false, features = ["blocking"
1414
serde = { version = "1.0.125", features = ["derive"] }
1515
chrono = {version = "0.4.19", features = ["serde"] }
1616
serde_json = "1.0.64"
17+
18+
[dev-dependencies]
19+
dotenv = "0.15.0"
20+
ctor = "0.1.26"
21+
22+
[features]
23+
e2e-test = []

src/lib.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,29 @@ impl Event {
143143
}
144144
}
145145

146+
#[cfg(test)]
147+
mod test_setup {
148+
use ctor::ctor;
149+
use dotenv::dotenv;
150+
151+
#[ctor]
152+
fn load_dotenv() {
153+
dotenv().ok(); // Load the .env file
154+
println!("Loaded .env for tests");
155+
}
156+
}
157+
146158
#[cfg(test)]
147159
pub mod tests {
148160
use super::*;
149-
use chrono::Utc;
150161

162+
#[cfg(feature = "e2e-test")]
151163
#[test]
152164
fn get_client() {
153-
let client = crate::client(env!("POSTHOG_API_KEY"));
165+
use std::collections::HashMap;
166+
167+
let api_key = std::env::var("POSTHOG_RS_E2E_TEST_API_KEY").unwrap();
168+
let client = crate::client(api_key.as_str());
154169

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

0 commit comments

Comments
 (0)