weld icon indicating copy to clipboard operation
weld copied to clipboard

tests...

Open serayuzgur opened this issue 8 years ago • 3 comments

Since the dependencies are fixed and basic skeleton created it is the sweet spot for writing tests.

serayuzgur avatar Apr 17 '17 13:04 serayuzgur

I found a sollution for integration tests. You can check this link for integration test. integration_tests

I will complete integrations tests and push issue asap.

kbukum avatar May 02 '17 21:05 kbukum

@serayuzgur

I am thinking to change code like below.

// main.rs
#![warn(missing_docs)]
extern crate weld;
use weld::start_application;

fn main() {
   start_application();
}

moved all main code in lib.rs.

// lib.rs
#![warn(missing_docs)]
//! # Weld
//! Weld is a fake API generator for easily mocking back-end services.
//! It is heavily inspired from [JSON Server](https://github.com/typicode/json-server).
//! Weld also claims that you can create APIs with **zero coding** in less than **30 seconds**.
//! Providing a `db.json` file will generate crud operations, cascading manipulation and query parametric filter support.

extern crate hyper;
extern crate rand;
extern crate futures;
extern crate futures_cpupool;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
#[macro_use]
extern crate slog;
extern crate slog_term;
extern crate slog_async;
#[macro_use]
extern crate lazy_static;
extern crate time;

pub mod service;
pub mod server;
pub mod configuration;
pub mod database;
pub mod weld;

use server::Server;
use std::env::args;

pub fn start_application() {
    info!(weld::ROOT_LOGGER, "Application started";"started_at" => format!("{}", time::now().rfc3339()), "version" => env!("CARGO_PKG_VERSION"));

    load_config();

    load_db();

    start_server();
}

/// Loads configuration.
fn load_config() {
    let mut configuration = weld::CONFIGURATION.lock()
        .expect("Configuration is not accesible. Terminating...");

    //No arg ? so use default.
    if let Some(path) = args().nth(1) {
        configuration.load(path.as_str())
    } else {
        info!(weld::ROOT_LOGGER, "Program arguments not found.");
        configuration.load("weld.json");
    }
}

/// Loads database.
fn load_db() {
    let mut db = weld::DATABASE.lock().expect("Database is not accesible. Terminating...");
    db.load(&weld::CONFIGURATION.lock().unwrap().database);
}

/// Starts server.
fn start_server() {
    let config = weld::CONFIGURATION.lock().unwrap().server.clone();
    Server::new(&config).start();
}

what do you think about that ?

kbukum avatar May 02 '17 22:05 kbukum

Seems ok

serayuzgur avatar May 03 '17 05:05 serayuzgur