Skip to content

Commit 724365c

Browse files
committed
Move integration tests into their own crate
1 parent a1f119c commit 724365c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+421
-397
lines changed

.github/workflows/checks.yml

Lines changed: 19 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -27,40 +27,13 @@ env:
2727
HACK: hack --package neo4rs --each-feature --exclude-features unstable-serde-packstream-format,unstable-bolt-protocol-impl-v2,unstable-result-summary
2828

2929
jobs:
30-
check:
31-
name: Compile on MSRV
32-
runs-on: ubuntu-latest
33-
steps:
34-
35-
- name: Checkout code
36-
uses: actions/checkout@v4
37-
with:
38-
fetch-depth: 2
39-
40-
- name: Set up Rust
41-
uses: dtolnay/rust-toolchain@master
42-
with:
43-
toolchain: ${{ env.MSRV }}
44-
45-
- name: Set up Rust cache
46-
uses: Swatinem/rust-cache@v2
47-
48-
- name: Install cargo-hack
49-
uses: taiki-e/install-action@cargo-hack
50-
51-
- name: Prepare MSRV lockfile
52-
run: cp ci/Cargo.lock.msrv Cargo.lock
53-
54-
- name: Run cargo check
55-
run: cargo +$MSRV --locked ${{ env.HACK }} check
56-
5730
fmt:
5831
name: Check formatting
5932
runs-on: ubuntu-latest
6033
steps:
6134

6235
- name: Checkout code
63-
uses: actions/checkout@v4
36+
uses: actions/checkout@v5
6437
with:
6538
fetch-depth: 2
6639

@@ -82,7 +55,7 @@ jobs:
8255
steps:
8356

8457
- name: Checkout code
85-
uses: actions/checkout@v4
58+
uses: actions/checkout@v5
8659
with:
8760
fetch-depth: 2
8861

@@ -114,14 +87,14 @@ jobs:
11487
steps:
11588

11689
- name: Checkout code
117-
uses: actions/checkout@v4
90+
uses: actions/checkout@v5
11891
with:
11992
fetch-depth: 2
12093

12194
- name: Set up Rust
12295
uses: dtolnay/rust-toolchain@master
12396
with:
124-
toolchain: stable
97+
toolchain: ${{ env.MSRV }}
12598

12699
- name: Set up Rust cache
127100
uses: Swatinem/rust-cache@v2
@@ -132,8 +105,11 @@ jobs:
132105
- name: Install cargo-nextest
133106
uses: taiki-e/install-action@nextest
134107

108+
- name: Prepare MSRV lockfile
109+
run: cp ci/Cargo.lock.msrv Cargo.lock
110+
135111
- name: Run unit tests
136-
run: cargo ${{ env.HACK }} nextest run --lib
112+
run: cargo +$MSRV --locked ${{ env.HACK }} nextest run --lib
137113

138114
integration-tests:
139115
name: Run integration tests
@@ -158,14 +134,14 @@ jobs:
158134
steps:
159135

160136
- name: Checkout code
161-
uses: actions/checkout@v4
137+
uses: actions/checkout@v5
162138
with:
163139
fetch-depth: 2
164140

165141
- name: Set up Rust
166142
uses: dtolnay/rust-toolchain@master
167143
with:
168-
toolchain: ${{ env.MSRV }}
144+
toolchain: stable
169145

170146
- name: Set up Rust cache
171147
uses: Swatinem/rust-cache@v2
@@ -176,22 +152,11 @@ jobs:
176152
- name: Install cargo-nextest
177153
uses: taiki-e/install-action@nextest
178154

179-
- name: Prepare MSRV lockfile
180-
run: cp ci/Cargo.lock.msrv Cargo.lock
181-
182155
- name: Run integration tests
183-
run: cargo +$MSRV --locked ${{ env.HACK }} nextest run -E 'kind(test)'
156+
run: cargo {{ env.HACK }} nextest run -E 'kind(test)'
184157

185-
msrv:
186-
name: Validate MSRV and minimal dependency versions
187-
strategy:
188-
fail-fast: false
189-
matrix:
190-
include:
191-
- file: Cargo.lock.msrv
192-
name: MSRV
193-
- file: Cargo.lock.min
194-
name: minimal dependency versions
158+
min_dep:
159+
name: Validate minimal dependency versions
195160
runs-on: ubuntu-latest
196161
steps:
197162

@@ -203,21 +168,21 @@ jobs:
203168
with:
204169
toolchain: ${{ env.MSRV }}
205170

206-
- name: Prepare ${{ matrix.name }} lockfile
207-
run: cp ci/${{ matrix.file }} Cargo.lock
208-
209171
- name: Set up Rust cache
210172
uses: Swatinem/rust-cache@v2
211173

212174
- name: Install cargo-nextest
213175
uses: taiki-e/install-action@nextest
214176

215-
- name: Run ${{ matrix.name }} unit tests
216-
run: cargo +$MSRV nextest run --lib --all-features --locked
177+
- name: Prepare minimal dependency versions lockfile
178+
run: cp ci/Cargo.lock.min Cargo.lock
179+
180+
- name: Run minimal dependency versions unit tests
181+
run: cargo +$MSRV nextest --package neo4rs run --lib --all-features --locked
217182

218183
release:
219184
name: Release
220-
needs: [ check, fmt, clippy, unit-tests, integration-tests, msrv ]
185+
needs: [ fmt, clippy, unit-tests, integration-tests, min_dep ]
221186
if: startsWith(github.ref, 'refs/tags/')
222187
runs-on: ubuntu-latest
223188
steps:

.github/workflows/create-release-pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
steps:
3333

3434
- name: Checkout code
35-
uses: actions/checkout@v4
35+
uses: actions/checkout@v5
3636
with:
3737
fetch-depth: 2
3838

include_snippet/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[package]
2-
name = "include_snippet"
3-
version = "0.0.0"
2+
name = "neo4rs_include_snippet"
3+
version = "0.9.0-rc.8"
44
edition = "2021"
55
description = "Internal proc macro for the include_snippet! macro"
6-
publish = false
6+
publish = true
77

88
[lib]
99
proc-macro = true

integrationtests/Cargo.toml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
[package]
2+
name = "neo4rs_tests"
3+
version = "0.0.0"
4+
edition = "2024"
5+
description = "Rust driver for Neo4j"
6+
license = "MIT"
7+
repository = "https://github.com/neo4j-labs/neo4rs"
8+
documentation = "https://docs.rs/neo4rs"
9+
readme = "../README.md"
10+
publish = false
11+
12+
[features]
13+
json = ["neo4rs/json"]
14+
uuid = ["neo4rs/uuid"]
15+
unstable-v1 = ["neo4rs/unstable-v1"]
16+
unstable-serde-packstream-format = ["neo4rs/unstable-serde-packstream-format"]
17+
unstable-result-summary = ["neo4rs/unstable-result-summary"]
18+
unstable-bolt-protocol-impl-v2 = ["neo4rs/unstable-bolt-protocol-impl-v2"]
19+
20+
[dependencies]
21+
neo4rs = { version = "0.9.0-rc.8", path = "../lib" }
22+
23+
[dev-dependencies]
24+
futures = { version = "0.3.0" }
25+
pretty_env_logger = "0.5.0"
26+
serde = { version = "1.0.185" }
27+
uuid = { version = "1.0.0", features = ["v4"] }
28+
29+
[dev-dependencies.chrono]
30+
version = "0.4.35"
31+
default-features = false
32+
features = ["std", "serde"]
33+
34+
[dev-dependencies.lenient_semver]
35+
version = "0.4.2"
36+
default-features = false
37+
features = ["version_lite"]
38+
39+
[dev-dependencies.testcontainers]
40+
version = "0.25.2"
41+
features = ["blocking"]
42+
43+
[dev-dependencies.testcontainers-modules]
44+
version = "0.13.0"
45+
features = ["neo4j"]
46+
47+
[dependencies.tokio]
48+
version = "1.5.0"
49+
features = ["full"]
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#![cfg(feature = "unstable-bolt-protocol-impl-v2")]
2+
use neo4rs::*;
3+
4+
mod container;
5+
6+
#[tokio::test]
7+
async fn transactions() {
8+
let neo4j = container::Neo4jContainer::new().await;
9+
let graph = neo4j.graph();
10+
11+
// snippet-start
12+
let mut txn = graph
13+
.start_txn()
14+
.await
15+
.expect("Failed to start a new transaction");
16+
let id = uuid::Uuid::new_v4().to_string();
17+
txn.run(query("CREATE (p:Person {id: $id})").param("id", id.clone()))
18+
.await
19+
.unwrap();
20+
txn.run(query("CREATE (p:Person {id: $id})").param("id", id.clone()))
21+
.await
22+
.unwrap();
23+
// graph.execute(..) will not see the changes done above as the txn is not committed yet
24+
let mut result = graph
25+
.execute(query("MATCH (p:Person) WHERE p.id = $id RETURN p.id").param("id", id.clone()))
26+
.await
27+
.unwrap();
28+
assert!(result.next().await.unwrap().is_none());
29+
let bookmark = txn.commit().await.unwrap();
30+
assert!(bookmark.is_some());
31+
if let Some(ref b) = bookmark {
32+
println!("Got a bookmark after commit: {:?}", b);
33+
}
34+
35+
//changes are now seen as the transaction is committed.
36+
let mut txn = graph
37+
.start_txn_as(Operation::Read, bookmark.map(|b| vec![b]))
38+
.await
39+
.expect("Failed to start a new transaction");
40+
let mut stream = txn
41+
.execute(query("MATCH (p:Person) WHERE p.id = $id RETURN p.id").param("id", id.clone()))
42+
.await
43+
.unwrap();
44+
loop {
45+
let next = stream.next(txn.handle());
46+
if let Ok(Some(record)) = next.await {
47+
println!("Record: {:?}", record);
48+
} else {
49+
break;
50+
}
51+
}
52+
// snippet-end
53+
}

lib/tests/configurations.rs renamed to integrationtests/tests/configurations.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,11 @@ async fn configurations() {
1111
let neo4j = container::Neo4jContainer::from_config(config).await;
1212
let graph = neo4j.graph();
1313

14-
include!("../include/configurations.rs");
14+
// snippet-start
15+
let mut result = graph.execute(query("RETURN 1")).await.unwrap();
16+
let row = result.next().await.unwrap().unwrap();
17+
let value: i64 = row.get("1").unwrap();
18+
assert_eq!(1, value);
19+
assert!(result.next().await.unwrap().is_none());
20+
// snippet-end
1521
}
File renamed without changes.

lib/include/dates.rs renamed to integrationtests/tests/dates.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
{
1+
use neo4rs::*;
2+
3+
mod container;
4+
5+
#[tokio::test]
6+
async fn dates() {
7+
let neo4j = container::Neo4jContainer::new().await;
8+
let graph = neo4j.graph();
9+
10+
// snippet-start
211
let date = chrono::NaiveDate::from_ymd_opt(1985, 2, 5).unwrap();
312
let mut result = graph
413
.execute(query("RETURN $d as output").param("d", date))
@@ -8,4 +17,5 @@
817
let d: chrono::NaiveDate = row.get("output").unwrap();
918
assert_eq!(d.to_string(), "1985-02-05");
1019
assert!(result.next().await.unwrap().is_none());
20+
// snippet-end
1121
}

lib/include/datetime_as_param.rs renamed to integrationtests/tests/datetime_as_param.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
{
1+
use neo4rs::*;
2+
3+
mod container;
4+
5+
#[tokio::test]
6+
async fn datetime_as_param() {
7+
let neo4j = container::Neo4jContainer::new().await;
8+
let graph = neo4j.graph();
9+
10+
// snippet-start
211
//send datetime as parameter in the query
312
let datetime = chrono::DateTime::parse_from_rfc2822("Tue, 01 Jul 2003 10:52:37 +0200").unwrap();
413

@@ -13,8 +22,8 @@
1322

1423
//send NaiveDateTime as parameter in the query
1524
let localdatetime =
16-
chrono::NaiveDateTime::parse_from_str("2015-07-01 08:55:59.123", "%Y-%m-%d %H:%M:%S%.f")
17-
.unwrap();
25+
chrono::NaiveDateTime::parse_from_str("2015-07-01 08:55:59.123", "%Y-%m-%d %H:%M:%S%.f")
26+
.unwrap();
1827

1928
let mut result = graph
2029
.execute(query("RETURN $d as output").param("d", localdatetime))
@@ -27,8 +36,8 @@
2736

2837
//send NaiveDateTime with timezone id as parameter in the query
2938
let datetime =
30-
chrono::NaiveDateTime::parse_from_str("2015-07-03 08:55:59.555", "%Y-%m-%d %H:%M:%S%.f")
31-
.unwrap();
39+
chrono::NaiveDateTime::parse_from_str("2015-07-03 08:55:59.555", "%Y-%m-%d %H:%M:%S%.f")
40+
.unwrap();
3241
let timezone = "Europe/Paris";
3342

3443
let mut result = graph
@@ -40,4 +49,5 @@
4049
assert_eq!(time.to_string(), "2015-07-03 08:55:59.555");
4150
assert_eq!(zone, "Europe/Paris");
4251
assert!(result.next().await.unwrap().is_none());
52+
// snippet-end
4353
}

0 commit comments

Comments
 (0)