Skip to content

Commit

Permalink
Make it a bit simpler to test against an Aura instance (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
knutwalker authored Aug 14, 2024
1 parent 4c042cc commit b081f63
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 11 deletions.
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,28 @@ You can use the `NEO4J_VERSION_TAG` environment variable to set the version of t
It is recommended to only run a single integration test and manually clean up the database after the test.

```sh
env NEO4J_TEST_URI=neo4j+s://42421337thisisnotarealinstance.databases.neo4j.io NEO4J_TEST_USER=neo4j NEO4J_TEST_PASS=supersecret NEO4J_VERSION_TAG=5.8 cargo test --test <name of the integration test, see the file names in lib/tests/>
env NEO4J_TEST_URI=bolt://localhost:7687 NEO4J_TEST_USER=neo4j NEO4J_TEST_PASS=supersecret NEO4J_VERSION_TAG=5.8 cargo test --test <name of the integration test, see the file names in lib/tests/>
```

##### Using an Aura instance

> ![WARNING]
> Running the tests will create new data and might change and delete existing data or entire databases.
> Do not use a production instance.
Running a test against an Aura instance can be done by setting the values as outlined above.
However, the environment variables used do not match the names that are given in the connection file when an Aura instance is created.

By setting the environment variable `NEO4RS_TEST_ON_AURA` to `1`, the tests will look for the environment variables as they are used in the connection file.
The tests can then also be run by using a `dotenv` like tool, e.g.

```sh
dotenvx run -f .auraenv -e NEO4RS_TEST_ON_AURA=1 -- cargo test
```

> ![NOTE]
> Some tests might also use features not available on Aura and will fail.
### Updating `Cargo.lock` files for CI

We have CI tests that verify the MSRV as well as the minimal version of the dependencies.
Expand Down
30 changes: 20 additions & 10 deletions lib/tests/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ impl Neo4jContainer {
) -> Result<Self, Box<dyn Error + Send + Sync + 'static>> {
let _ = pretty_env_logger::try_init();

let connection = Self::create_test_endpoint();
let server = Self::server_from_env();
let connection = Self::create_test_endpoint(matches!(server, TestServer::Aura(_)));

let (uri, _container) = match server {
TestServer::TestContainer => {
let (uri, container) = Self::create_testcontainer(&connection, enterprise_edition)?;
(uri, Some(container))
}
TestServer::External(uri) => (uri, None),
TestServer::External(uri) | TestServer::Aura(uri) => (uri, None),
};

let version = connection.version;
Expand All @@ -94,12 +94,17 @@ impl Neo4jContainer {

fn server_from_env() -> TestServer {
const TEST_URI_VAR: &str = "NEO4J_TEST_URI";
const CHECK_AURA_VAR: &str = "NEO4RS_TEST_ON_AURA";
const AURA_URI_VAR: &str = "NEO4J_URI";

if let Ok(uri) = std::env::var(TEST_URI_VAR) {
TestServer::External(uri)
} else {
TestServer::TestContainer
}
use std::env::var;

var(CHECK_AURA_VAR)
.ok()
.filter(|use_aura| use_aura == "1")
.and_then(|_| var(AURA_URI_VAR).ok().map(TestServer::Aura))
.or_else(|| var(TEST_URI_VAR).ok().map(TestServer::External))
.unwrap_or(TestServer::TestContainer)
}

fn create_testcontainer(
Expand Down Expand Up @@ -155,9 +160,11 @@ impl Neo4jContainer {
Ok((uri, container))
}

fn create_test_endpoint() -> TestConnection {
fn create_test_endpoint(use_aura: bool) -> TestConnection {
const USER_VAR: &str = "NEO4J_TEST_USER";
const AURA_USER_VAR: &str = "NEO4J_USERNAME";
const PASS_VAR: &str = "NEO4J_TEST_PASS";
const AURA_PASS_VAR: &str = "NEO4J_PASSWORD";
const VERSION_VAR: &str = "NEO4J_VERSION_TAG";

const DEFAULT_USER: &str = "neo4j";
Expand All @@ -166,8 +173,10 @@ impl Neo4jContainer {

use std::env::var;

let user = var(USER_VAR).unwrap_or_else(|_| DEFAULT_USER.to_owned());
let pass = var(PASS_VAR).unwrap_or_else(|_| DEFAULT_PASS.to_owned());
let user = var(if use_aura { AURA_USER_VAR } else { USER_VAR })
.unwrap_or_else(|_| DEFAULT_USER.to_owned());
let pass = var(if use_aura { AURA_PASS_VAR } else { PASS_VAR })
.unwrap_or_else(|_| DEFAULT_PASS.to_owned());
let auth = TestAuth { user, pass };
let version = var(VERSION_VAR).unwrap_or_else(|_| DEFAULT_VERSION_TAG.to_owned());

Expand Down Expand Up @@ -198,5 +207,6 @@ struct TestConnection {

enum TestServer {
TestContainer,
Aura(String),
External(String),
}

0 comments on commit b081f63

Please sign in to comment.