|
@@ -3,7 +3,12 @@ use backend::{
|
|
config::{get_configuration, DatabaseSettings},
|
|
config::{get_configuration, DatabaseSettings},
|
|
context::AppContext,
|
|
context::AppContext,
|
|
};
|
|
};
|
|
-use backend_service::{errors::ServerError, user_request::*, workspace_request::*};
|
|
|
|
|
|
+use backend_service::{
|
|
|
|
+ configuration::{get_client_server_configuration, ClientServerConfiguration},
|
|
|
|
+ errors::ServerError,
|
|
|
|
+ user_request::*,
|
|
|
|
+ workspace_request::*,
|
|
|
|
+};
|
|
use flowy_document::services::server::read_doc_request;
|
|
use flowy_document::services::server::read_doc_request;
|
|
use flowy_document_infra::entities::doc::{Doc, DocIdentifier};
|
|
use flowy_document_infra::entities::doc::{Doc, DocIdentifier};
|
|
use flowy_user_infra::entities::*;
|
|
use flowy_user_infra::entities::*;
|
|
@@ -12,11 +17,10 @@ use sqlx::{Connection, Executor, PgConnection, PgPool};
|
|
use uuid::Uuid;
|
|
use uuid::Uuid;
|
|
|
|
|
|
pub struct TestUserServer {
|
|
pub struct TestUserServer {
|
|
- pub host: String,
|
|
|
|
- pub port: u16,
|
|
|
|
pub pg_pool: PgPool,
|
|
pub pg_pool: PgPool,
|
|
pub user_token: Option<String>,
|
|
pub user_token: Option<String>,
|
|
pub user_id: Option<String>,
|
|
pub user_id: Option<String>,
|
|
|
|
+ pub client_server_config: ClientServerConfiguration,
|
|
}
|
|
}
|
|
|
|
|
|
impl TestUserServer {
|
|
impl TestUserServer {
|
|
@@ -167,19 +171,24 @@ impl TestUserServer {
|
|
response
|
|
response
|
|
}
|
|
}
|
|
|
|
|
|
- pub fn http_addr(&self) -> String { format!("http://{}", self.host) }
|
|
|
|
|
|
+ pub fn http_addr(&self) -> String { self.client_server_config.base_url() }
|
|
|
|
|
|
- pub fn ws_addr(&self) -> String { format!("ws://{}/ws/{}", self.host, self.user_token.as_ref().unwrap()) }
|
|
|
|
|
|
+ pub fn ws_addr(&self) -> String {
|
|
|
|
+ format!(
|
|
|
|
+ "{}/{}",
|
|
|
|
+ self.client_server_config.ws_addr(),
|
|
|
|
+ self.user_token.as_ref().unwrap()
|
|
|
|
+ )
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
impl std::convert::From<TestServer> for TestUserServer {
|
|
impl std::convert::From<TestServer> for TestUserServer {
|
|
fn from(server: TestServer) -> Self {
|
|
fn from(server: TestServer) -> Self {
|
|
TestUserServer {
|
|
TestUserServer {
|
|
- host: server.host,
|
|
|
|
- port: server.port,
|
|
|
|
pg_pool: server.pg_pool,
|
|
pg_pool: server.pg_pool,
|
|
user_token: None,
|
|
user_token: None,
|
|
user_id: None,
|
|
user_id: None,
|
|
|
|
+ client_server_config: server.client_server_config.clone(),
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -190,10 +199,9 @@ pub async fn spawn_user_server() -> TestUserServer {
|
|
}
|
|
}
|
|
|
|
|
|
pub struct TestServer {
|
|
pub struct TestServer {
|
|
- pub host: String,
|
|
|
|
- pub port: u16,
|
|
|
|
pub pg_pool: PgPool,
|
|
pub pg_pool: PgPool,
|
|
pub app_ctx: AppContext,
|
|
pub app_ctx: AppContext,
|
|
|
|
+ pub client_server_config: ClientServerConfiguration,
|
|
}
|
|
}
|
|
|
|
|
|
pub async fn spawn_server() -> TestServer {
|
|
pub async fn spawn_server() -> TestServer {
|
|
@@ -218,13 +226,15 @@ pub async fn spawn_server() -> TestServer {
|
|
// drop_test_database(database_name).await;
|
|
// drop_test_database(database_name).await;
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+ let mut client_server_config = get_client_server_configuration().expect("Failed to read configuration.");
|
|
|
|
+ client_server_config.reset_host_with_port("localhost", application_port);
|
|
|
|
+
|
|
TestServer {
|
|
TestServer {
|
|
- host: format!("localhost:{}", application_port),
|
|
|
|
- port: application_port,
|
|
|
|
pg_pool: get_connection_pool(&configuration.database)
|
|
pg_pool: get_connection_pool(&configuration.database)
|
|
.await
|
|
.await
|
|
.expect("Failed to connect to the database"),
|
|
.expect("Failed to connect to the database"),
|
|
app_ctx,
|
|
app_ctx,
|
|
|
|
+ client_server_config,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|