Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Extract a net module and rename the test database to ente_test

Manav Rathia83295e7e1b8
diff --git a/rust/crates/test-support/README.md b/rust/crates/test-support/README.md
index 1ce33c3ad1..88c1b83983 100644
--- a/rust/crates/test-support/README.md
+++ b/rust/crates/test-support/README.md
@@ -1,19 +1,15 @@
# ente-test-support
-Runs a local Museum backed by a temporary Postgres
-([postgresql_embedded](https://crates.io/crates/postgresql_embedded)) for the
-`ente-rs` and `ente-e2e` integration tests.
+Runs a local Museum backed by a temporary Postgres for use by various Rust integration tests.
## Setup
-Requires `go` on PATH (to build and run Museum). The Postgres binary is
-downloaded and cached automatically on first use.
+Requires `go` on PATH to build and run Museum. The Postgres binary ([postgresql_embedded](https://crates.io/crates/postgresql_embedded)) is downloaded and cached on first use.
## Usage
-Tests that use it are gated behind the `museum` Cargo feature, so a plain
-`cargo test` skips them:
+Tests that use it are gated behind a Cargo feature so that a plain `cargo test` skips them. They can be run by enabling the `museum` feature, e.g.:
```sh
-cargo test -p ente-e2e --features museum
+cargo test -p ente-rs --features museum
```
diff --git a/rust/crates/test-support/src/lib.rs b/rust/crates/test-support/src/lib.rs
index bf156631c1..55f9adb3a2 100644
--- a/rust/crates/test-support/src/lib.rs
+++ b/rust/crates/test-support/src/lib.rs
@@ -6,6 +6,7 @@
//! [postgresql_embedded]: https://crates.io/crates/postgresql_embedded
mod museum;
+mod net;
mod postgres;
mod process;
mod server;
@@ -14,8 +15,6 @@ pub use museum::Museum;
pub type TestResult<T = ()> = Result<T, Box<dyn std::error::Error>>;
-const LOCAL_HOST: &str = "127.0.0.1";
-
/// Museum accepts [`HARDCODED_OTT`] as the email verification code for any
/// address ending in [`HARDCODED_OTT_EMAIL_SUFFIX`], so tests can sign up and
/// log in without an email inbox.
@@ -23,9 +22,3 @@ pub const HARDCODED_OTT: &str = "123456";
/// See [`HARDCODED_OTT`].
pub const HARDCODED_OTT_EMAIL_SUFFIX: &str = "@example.org";
-
-fn free_port() -> TestResult<u16> {
- Ok(std::net::TcpListener::bind((LOCAL_HOST, 0))?
- .local_addr()?
- .port())
-}
diff --git a/rust/crates/test-support/src/museum.rs b/rust/crates/test-support/src/museum.rs
index 5f57b1897f..ea759708b7 100644
--- a/rust/crates/test-support/src/museum.rs
+++ b/rust/crates/test-support/src/museum.rs
@@ -5,7 +5,13 @@ use std::{
use uuid::Uuid;
-use crate::{LOCAL_HOST, TestResult, free_port, postgres, process::ChildProcess, server};
+use crate::{
+ TestResult,
+ net::{LOCAL_HOST, free_port},
+ postgres,
+ process::ChildProcess,
+ server,
+};
/// A running Museum for integration tests, backed by a temporary Postgres.
///
diff --git a/rust/crates/test-support/src/net.rs b/rust/crates/test-support/src/net.rs
new file mode 100644
index 0000000000..20cd8e7d3a
--- /dev/null
+++ b/rust/crates/test-support/src/net.rs
@@ -0,0 +1,13 @@
+use crate::TestResult;
+
+pub const LOCAL_HOST: &str = "127.0.0.1";
+
+/// An unused local TCP port.
+///
+/// Racy: the port is free when returned, not reserved, so the caller should
+/// bind it promptly.
+pub fn free_port() -> TestResult<u16> {
+ Ok(std::net::TcpListener::bind((LOCAL_HOST, 0))?
+ .local_addr()?
+ .port())
+}
diff --git a/rust/crates/test-support/src/postgres.rs b/rust/crates/test-support/src/postgres.rs
index 644701f8cd..917194f31c 100644
--- a/rust/crates/test-support/src/postgres.rs
+++ b/rust/crates/test-support/src/postgres.rs
@@ -1,9 +1,12 @@
use postgresql_embedded::Settings;
use postgresql_embedded::blocking::PostgreSQL;
-use crate::{LOCAL_HOST, TestResult, free_port};
+use crate::{
+ TestResult,
+ net::{LOCAL_HOST, free_port},
+};
-const DATABASE: &str = "ente";
+const DATABASE: &str = "ente_test";
/// A temporary local Postgres, torn down on drop.
pub struct Postgres {
diff --git a/rust/crates/test-support/src/server.rs b/rust/crates/test-support/src/server.rs
index 23c08b57a4..5a0005d571 100644
--- a/rust/crates/test-support/src/server.rs
+++ b/rust/crates/test-support/src/server.rs
@@ -8,7 +8,7 @@ use std::{
};
use crate::{
- HARDCODED_OTT, HARDCODED_OTT_EMAIL_SUFFIX, LOCAL_HOST, TestResult, postgres::Postgres,
+ HARDCODED_OTT, HARDCODED_OTT_EMAIL_SUFFIX, TestResult, net::LOCAL_HOST, postgres::Postgres,
process::ChildProcess,
};