diff --git a/README.md b/README.md index 6d4a9d1e..4c889363 100644 --- a/README.md +++ b/README.md @@ -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 +env NEO4J_TEST_URI=bolt://localhost:7687 NEO4J_TEST_USER=neo4j NEO4J_TEST_PASS=supersecret NEO4J_VERSION_TAG=5.8 cargo test --test ``` +##### 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. diff --git a/lib/tests/container.rs b/lib/tests/container.rs index fc25e47e..1f420306 100644 --- a/lib/tests/container.rs +++ b/lib/tests/container.rs @@ -60,15 +60,15 @@ impl Neo4jContainer { ) -> Result> { 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; @@ -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( @@ -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"; @@ -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()); @@ -198,5 +207,6 @@ struct TestConnection { enum TestServer { TestContainer, + Aura(String), External(String), }