excluding main and from impls from code coverage

This commit is contained in:
realaravinth 2021-03-10 21:37:20 +05:30
parent 5c4435430f
commit 7f289cce03
No known key found for this signature in database
GPG Key ID: AD9F0F08E855ED88
5 changed files with 16 additions and 0 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@
tarpaulin-report.html tarpaulin-report.html
.env .env
.env .env
tarpaulin-report.html

View File

@ -75,7 +75,9 @@ pub struct ErrorToResponse {
pub error: String, pub error: String,
} }
#[cfg(not(tarpaulin_include))]
impl ResponseError for ServiceError { impl ResponseError for ServiceError {
#[cfg(not(tarpaulin_include))]
fn error_response(&self) -> HttpResponse { fn error_response(&self) -> HttpResponse {
HttpResponseBuilder::new(self.status_code()) HttpResponseBuilder::new(self.status_code())
.set_header(header::CONTENT_TYPE, "application/json; charset=UTF-8") .set_header(header::CONTENT_TYPE, "application/json; charset=UTF-8")
@ -84,6 +86,7 @@ impl ResponseError for ServiceError {
}) })
} }
#[cfg(not(tarpaulin_include))]
fn status_code(&self) -> StatusCode { fn status_code(&self) -> StatusCode {
match *self { match *self {
ServiceError::InternalServerError => StatusCode::INTERNAL_SERVER_ERROR, ServiceError::InternalServerError => StatusCode::INTERNAL_SERVER_ERROR,
@ -102,6 +105,7 @@ impl ResponseError for ServiceError {
} }
impl From<CredsError> for ServiceError { impl From<CredsError> for ServiceError {
#[cfg(not(tarpaulin_include))]
fn from(e: CredsError) -> ServiceError { fn from(e: CredsError) -> ServiceError {
debug!("{:?}", &e); debug!("{:?}", &e);
match e { match e {
@ -122,7 +126,10 @@ impl From<CredsError> for ServiceError {
// } // }
// } // }
// //
#[cfg(not(tarpaulin_include))]
impl From<sqlx::Error> for ServiceError { impl From<sqlx::Error> for ServiceError {
#[cfg(not(tarpaulin_include))]
fn from(e: sqlx::Error) -> Self { fn from(e: sqlx::Error) -> Self {
use sqlx::error::Error; use sqlx::error::Error;
use std::borrow::Cow; use std::borrow::Cow;
@ -137,4 +144,5 @@ impl From<sqlx::Error> for ServiceError {
} }
} }
#[cfg(not(tarpaulin_include))]
pub type ServiceResult<V> = std::result::Result<V, ServiceError>; pub type ServiceResult<V> = std::result::Result<V, ServiceError>;

View File

@ -34,6 +34,7 @@ lazy_static! {
pub static ref SETTINGS: Settings = Settings::new().unwrap(); pub static ref SETTINGS: Settings = Settings::new().unwrap();
} }
#[cfg(not(tarpaulin_include))]
#[actix_web::main] #[actix_web::main]
async fn main() -> std::io::Result<()> { async fn main() -> std::io::Result<()> {
use api::v1::services as v1_services; use api::v1::services as v1_services;

View File

@ -37,6 +37,7 @@ pub struct Captcha {
} }
impl Server { impl Server {
#[cfg(not(tarpaulin_include))]
pub fn get_ip(&self) -> String { pub fn get_ip(&self) -> String {
format!("{}:{}", self.ip, self.port) format!("{}:{}", self.ip, self.port)
} }
@ -53,6 +54,7 @@ struct DatabaseBuilder {
} }
impl DatabaseBuilder { impl DatabaseBuilder {
#[cfg(not(tarpaulin_include))]
fn extract_database_url(url: &Url) -> Self { fn extract_database_url(url: &Url) -> Self {
// if url.scheme() != "postgres" || url.scheme() != "postgresql" { // if url.scheme() != "postgres" || url.scheme() != "postgresql" {
// panic!("URL must be postgres://url, url found: {}", url.scheme()); // panic!("URL must be postgres://url, url found: {}", url.scheme());
@ -125,6 +127,7 @@ impl Settings {
} }
} }
#[cfg(not(tarpaulin_include))]
fn set_from_database_url(s: &mut Config, database_conf: &DatabaseBuilder) { fn set_from_database_url(s: &mut Config, database_conf: &DatabaseBuilder) {
s.set("database.username", database_conf.username.clone()) s.set("database.username", database_conf.username.clone())
.expect("Couldn't set database username"); .expect("Couldn't set database username");
@ -138,6 +141,7 @@ fn set_from_database_url(s: &mut Config, database_conf: &DatabaseBuilder) {
.expect("Couldn't access database name"); .expect("Couldn't access database name");
} }
#[cfg(not(tarpaulin_include))]
fn set_database_url(s: &mut Config) { fn set_database_url(s: &mut Config) {
s.set( s.set(
"database.url", "database.url",

View File

@ -24,9 +24,11 @@ pub use data::Data;
pub use settings::Settings; pub use settings::Settings;
lazy_static! { lazy_static! {
#[cfg(not(tarpaulin_include))]
pub static ref SETTINGS: Settings = Settings::new().unwrap(); pub static ref SETTINGS: Settings = Settings::new().unwrap();
} }
#[cfg(not(tarpaulin_include))]
#[actix_web::main] #[actix_web::main]
async fn main() { async fn main() {
let data = Data::new().await; let data = Data::new().await;