add basic test running
continuous-integration/drone/push Build is failing Details

does not add actual test
This commit is contained in:
ayham 2021-08-21 08:50:18 +03:00
parent ca6f0677ed
commit edf212de7e
Signed by: ayham
GPG Key ID: EAB7F5A9DF503678
14 changed files with 59 additions and 23 deletions

View File

@ -27,6 +27,13 @@ steps:
- sleep 75
- ./scripts/deploy_sandbox_client.sh server:4000
- name: test_server
image: rust
commands:
- sleep 75
- ./scripts/deploy_sandbox_client.sh server:4000
- cargo test --no-default_features --features "client,tls_no_verify"
services:
- name: database
image: postgres

View File

@ -18,7 +18,7 @@ test = false
bench = false
[features]
default = ["server", "client"]
default = ["server"]
server = []
client = []
tls_no_verify = ["tokio-rustls/dangerous_configuration"]

0
scripts/test_client.sh Normal file
View File

18
scripts/test_server.sh Executable file
View File

@ -0,0 +1,18 @@
#!/bin/sh
. ./scripts/env.sh && cargo run --no-default-features --features "server" -- ${1:-0.0.0.0:4000} &
PID_server=$!
echo $PID_server
while kill -0 $PID_server > /dev/null 2>&1
do
[[ -f "/tmp/paper/running" ]] && break
done
if [[ -f "/tmp/paper/running" ]]; then
cargo test --no-default-features --features "client,tls_no_verify"
rm /tmp/paper/running
kill $PID_server
pkill sandbox
fi

View File

@ -1,9 +1,9 @@
extern crate log;
#[cfg(feature = "client")]
use libtrader::client::initializer::libtrader_init_client;
#[cfg(feature = "server")]
use libtrader::server::initializer::{libtrader_init_server, IP};
use libtrader::server;
#[cfg(feature = "client")]
use libtrader::client;
fn main() {
#[cfg(feature = "server")]
@ -18,9 +18,9 @@ fn main() {
// Spawn server
rt.block_on(async move {
IP.scope("0.0.0.0:0000".parse().unwrap(), async move {
server::IP.scope("0.0.0.0:0000".parse().unwrap(), async move {
// for main task logging
libtrader_init_server()
server::initialize()
.await
.expect("failed running server");
})
@ -31,5 +31,5 @@ fn main() {
/* this is a sandbox, we should try to atleast
* implement a testing method */
#[cfg(feature = "client")]
libtrader_init_client().expect("failed running client");
client::initialize().expect("failed running client");
}

View File

@ -2,6 +2,6 @@ pub mod authorization;
pub mod creation;
pub mod hash;
pub use crate::client::account::creation::create;
pub use crate::client::account::authorization::authorize;
pub use crate::client::account::creation::create;
pub use crate::client::account::hash::hash;

View File

@ -37,7 +37,7 @@ struct Options {
/// libtrader_init_client().expect("failed running client");
/// ```
///
fn libtrader_init_log() -> io::Result<()> {
fn initialize_log() -> io::Result<()> {
use fern::colors::{Color, ColoredLevelConfig};
let mut dispatch = fern::Dispatch::new().format(|out, message, record| {
@ -99,12 +99,12 @@ fn libtrader_init_log() -> io::Result<()> {
///
/// Example:
/// ```rust
/// libtrader_init_client()?;
/// initialize()?;
/// ```
#[tokio::main]
pub async fn libtrader_init_client() -> std::io::Result<()> {
pub async fn initialize() -> std::io::Result<()> {
// Initialize log.
libtrader_init_log()?;
initialize_log()?;
// Initialize arguments
let options: Options = argh::from_env();

View File

@ -2,3 +2,5 @@ pub mod account;
pub mod ds;
pub mod initializer;
pub mod network;
pub use crate::client::initializer::initialize;

View File

@ -1,3 +1,3 @@
pub mod cmd;
pub mod tls;
pub mod handle_data;
pub mod tls;

View File

@ -7,10 +7,10 @@ use tokio::io::AsyncReadExt;
use tokio::io::AsyncWriteExt;
use tokio::net::TcpStream;
#[cfg(all(feature = "client", not(feature = "server")))]
use tokio_rustls::client::TlsStream;
#[cfg(all(feature = "server", not(feature = "client")))]
use tokio_rustls::server::TlsStream;
#[cfg(all(feature = "client", not(feature = "server")))]
use tokio_rustls::client::TlsStream;
#[derive(Serialize, Deserialize, PartialEq, Debug, Default)]
pub struct Message {

View File

@ -42,7 +42,7 @@ tokio::task_local! {
/// libtrader_init_log()?;
/// ```
///
fn libtrader_init_log() -> std::io::Result<()> {
fn initialize_log() -> std::io::Result<()> {
use fern::colors::{Color, ColoredLevelConfig};
let mut dispatch = fern::Dispatch::new().format(|out, message, record| {
@ -124,9 +124,9 @@ fn libtrader_init_log() -> std::io::Result<()> {
/// .await;
/// });
/// ```
pub async fn libtrader_init_server() -> std::io::Result<()> {
pub async fn initialize() -> std::io::Result<()> {
// Initialize log.
libtrader_init_log()?;
initialize_log()?;
// Initialize SQL connection
let sql_shared_conn = Arc::new(
@ -160,6 +160,12 @@ pub async fn libtrader_init_server() -> std::io::Result<()> {
let listener = TcpListener::bind(&addr).await?;
// create temporary file to mark server is running
let marker_path = std::path::Path::new("/tmp/paper/running");
let marker_prefix = marker_path.parent().unwrap();
std::fs::create_dir_all(marker_prefix).unwrap();
std::fs::write(marker_path, "").unwrap();
loop {
let (socket, peer_addr) = listener.accept().await?; // socket, peer_addr
let acceptor = acceptor.clone();

View File

@ -3,3 +3,6 @@ pub mod db;
pub mod ds;
pub mod initializer;
pub mod network;
pub use crate::server::initializer::initialize;
pub use crate::server::initializer::IP;

View File

@ -1,3 +1,3 @@
pub mod tls;
pub mod handle_data;
pub mod jwt;
pub mod tls;

View File

@ -1,9 +1,5 @@
## To do
- add testing suite
* [ ] configure ci to run those tests
* [ ] add tests for all server functions
* [ ] add tests for all client functions
- create correct modules
* [ ] fix weird file naming
* [ ] fix namespace naming
@ -19,6 +15,10 @@
## In progress
- add testing suite
* [ ] configure ci to run those tests
* [ ] add tests for all server functions
* [ ] add tests for all client functions
## Done