chore: clippy lints
This commit is contained in:
parent
9a3425eabe
commit
31fd0f0c51
13 changed files with 60 additions and 102 deletions
|
@ -102,8 +102,9 @@ pub async fn adding_forge_works<'a, T: SCDatabase>(
|
|||
|
||||
/// test if all forge type implementations are loaded into DB
|
||||
pub async fn forge_type_exists_helper<T: SCDatabase>(db: &T) {
|
||||
for f in [ForgeImplementation::Gitea].iter() {
|
||||
println!("Testing forge implementation exists for: {}", f.to_str());
|
||||
assert!(db.forge_type_exists(f).await.unwrap());
|
||||
}
|
||||
//for f in [ForgeImplementation::Gitea].iter() {
|
||||
//let f = For
|
||||
let f = ForgeImplementation::Gitea;
|
||||
println!("Testing forge implementation exists for: {}", f.to_str());
|
||||
assert!(db.forge_type_exists(&f).await.unwrap());
|
||||
}
|
||||
|
|
|
@ -274,7 +274,7 @@ impl SCDatabase for Database {
|
|||
.map_err(|e| DBError::DBError(Box::new(e)))?;
|
||||
Ok(User {
|
||||
username: username.into(),
|
||||
url: url.into(),
|
||||
url,
|
||||
profile_photo: res.profile_photo_html_url,
|
||||
html_link: res.html_url,
|
||||
})
|
||||
|
@ -496,6 +496,7 @@ impl SCDatabase for Database {
|
|||
|
||||
/// Get all repositories
|
||||
async fn get_all_repositories(&self, offset: u32, limit: u32) -> DBResult<Vec<Repository>> {
|
||||
#[allow(non_snake_case)]
|
||||
struct InnerRepository {
|
||||
/// html link to the repository
|
||||
pub html_url: String,
|
||||
|
|
|
@ -32,12 +32,12 @@ pub async fn adding_forge_works<'a, T: Federate>(
|
|||
|
||||
// add user
|
||||
assert!(!ff
|
||||
.user_exists(&create_user_msg.username, &create_user_msg.url)
|
||||
.user_exists(create_user_msg.username, &create_user_msg.url)
|
||||
.await
|
||||
.unwrap());
|
||||
ff.create_user(&create_user_msg).await.unwrap();
|
||||
assert!(ff
|
||||
.user_exists(&create_user_msg.username, &create_user_msg.url)
|
||||
.user_exists(create_user_msg.username, &create_user_msg.url)
|
||||
.await
|
||||
.unwrap());
|
||||
|
||||
|
|
|
@ -136,7 +136,7 @@ impl Federate for PccFederate {
|
|||
|
||||
/// delete forge instance
|
||||
async fn delete_forge_instance(&self, url: &Url) -> FResult<()> {
|
||||
let path = self.get_instance_path(&url, false).await?;
|
||||
let path = self.get_instance_path(url, false).await?;
|
||||
self.rm_util(&path).await
|
||||
}
|
||||
|
||||
|
|
|
@ -131,10 +131,11 @@ impl From<DBError> for ServiceError {
|
|||
#[cfg(not(tarpaulin_include))]
|
||||
fn from(e: DBError) -> ServiceError {
|
||||
println!("from conversin: {}", e);
|
||||
match e {
|
||||
// TODO: resolve all errors to ServiceError::*
|
||||
_ => ServiceError::DBError(DBErrorWrapper(e)),
|
||||
}
|
||||
ServiceError::DBError(DBErrorWrapper(e))
|
||||
// match e {
|
||||
// // TODO: resolve all errors to ServiceError::*
|
||||
// _ => ServiceError::DBError(DBErrorWrapper(e)),
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
use actix_web::http::{self, header::ContentType};
|
||||
use actix_web::{HttpResponse, Responder};
|
||||
use actix_web_codegen_const_routes::{get, post};
|
||||
use log::info;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::cell::RefCell;
|
||||
use tera::Context;
|
||||
|
@ -97,7 +96,7 @@ pub async fn add_submit(
|
|||
db: &BoxDB,
|
||||
) -> ServiceResult<TXTChallenge> {
|
||||
let url_hostname = Url::parse(&payload.hostname).unwrap();
|
||||
let key = TXTChallenge::get_challenge_txt_key(&ctx, &url_hostname);
|
||||
let key = TXTChallenge::get_challenge_txt_key(ctx, &url_hostname);
|
||||
if db.dns_challenge_exists(&key).await? {
|
||||
let value = db.get_dns_challenge(&key).await?.value;
|
||||
Ok(TXTChallenge { key, value })
|
||||
|
@ -136,14 +135,9 @@ mod tests {
|
|||
use actix_web::test;
|
||||
use url::Url;
|
||||
|
||||
use super::AddChallenge;
|
||||
use super::AddChallengePayload;
|
||||
use super::TXTChallenge;
|
||||
use crate::errors::*;
|
||||
use crate::pages::errors::*;
|
||||
use crate::settings::Settings;
|
||||
|
||||
use db_core::prelude::*;
|
||||
|
||||
#[cfg(test)]
|
||||
mod isolated {
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
use actix_web::http::{self, header::ContentType};
|
||||
use actix_web::{HttpResponse, Responder};
|
||||
use actix_web_codegen_const_routes::{get, post};
|
||||
use log::info;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::cell::RefCell;
|
||||
use tera::Context;
|
||||
|
@ -83,7 +82,7 @@ pub async fn get_verify(
|
|||
query: web::Query<VerifyChallengePayload>,
|
||||
) -> PageResult<impl Responder, VerifyChallenge> {
|
||||
let payload = query.into_inner();
|
||||
let value = _get_challenge(&payload, &ctx, &db).await.map_err(|e| {
|
||||
let value = _get_challenge(&payload, &db).await.map_err(|e| {
|
||||
let challenge = Challenge {
|
||||
key: payload.hostname,
|
||||
value: "".into(),
|
||||
|
@ -103,11 +102,7 @@ pub fn services(cfg: &mut web::ServiceConfig) {
|
|||
cfg.service(submit_verify);
|
||||
}
|
||||
|
||||
async fn _get_challenge(
|
||||
payload: &VerifyChallengePayload,
|
||||
ctx: &ArcCtx,
|
||||
db: &BoxDB,
|
||||
) -> ServiceResult<Challenge> {
|
||||
async fn _get_challenge(payload: &VerifyChallengePayload, db: &BoxDB) -> ServiceResult<Challenge> {
|
||||
let value = db.get_dns_challenge(&payload.hostname).await?;
|
||||
Ok(value)
|
||||
}
|
||||
|
@ -120,7 +115,7 @@ pub async fn submit_verify(
|
|||
federate: WebFederate,
|
||||
) -> PageResult<impl Responder, VerifyChallenge> {
|
||||
let payload = payload.into_inner();
|
||||
let value = _get_challenge(&payload, &ctx, &db).await.map_err(|e| {
|
||||
let value = _get_challenge(&payload, &db).await.map_err(|e| {
|
||||
let challenge = Challenge {
|
||||
key: payload.hostname.clone(),
|
||||
value: "".into(),
|
||||
|
|
|
@ -90,13 +90,11 @@ impl Repository {
|
|||
if license_path.exists() {
|
||||
if license_path.is_dir() {
|
||||
panic!("Can't create license file at {:?}", license_path);
|
||||
} else {
|
||||
if !fs::read_to_string(&license_path)
|
||||
.unwrap()
|
||||
.contains(CC0_LICENSE_TXT)
|
||||
{
|
||||
panic!("Can't create license file at {:?}", &license_path);
|
||||
}
|
||||
} else if !fs::read_to_string(&license_path)
|
||||
.unwrap()
|
||||
.contains(CC0_LICENSE_TXT)
|
||||
{
|
||||
panic!("Can't create license file at {:?}", &license_path);
|
||||
}
|
||||
} else {
|
||||
fs::write(license_path, CC0_LICENSE_TXT).unwrap();
|
||||
|
@ -113,16 +111,6 @@ pub enum DBType {
|
|||
Sqlite,
|
||||
}
|
||||
|
||||
impl DBType {
|
||||
fn from_url(url: &Url) -> Result<Self, ConfigError> {
|
||||
match url.scheme() {
|
||||
"sqlite" => Ok(Self::Sqlite),
|
||||
"postgres" => Ok(Self::Postgres),
|
||||
_ => Err(ConfigError::Message("Unknown database type".into())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Database {
|
||||
pub url: String,
|
||||
|
@ -237,20 +225,6 @@ mod tests {
|
|||
use super::*;
|
||||
use crate::utils::get_random;
|
||||
|
||||
#[test]
|
||||
fn database_type_test() {
|
||||
for i in ["sqlite://foo", "postgres://bar", "unknown://"].iter() {
|
||||
let url = Url::parse(i).unwrap();
|
||||
if i.contains("sqlite") {
|
||||
assert_eq!(DBType::from_url(&url).unwrap(), DBType::Sqlite);
|
||||
} else if i.contains("unknown") {
|
||||
assert!(DBType::from_url(&url).is_err());
|
||||
} else {
|
||||
assert_eq!(DBType::from_url(&url).unwrap(), DBType::Postgres);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn root_dir_is_created_test() {
|
||||
let dir;
|
||||
|
|
|
@ -43,21 +43,19 @@ impl Ctx {
|
|||
let url = forge.get_url();
|
||||
if !db.forge_exists(url).await.unwrap() {
|
||||
info!("[crawl][{url}] Creating forge");
|
||||
let mut msg = CreateForge {
|
||||
let msg = CreateForge {
|
||||
url: url.clone(),
|
||||
forge_type: forge.forge_type(),
|
||||
};
|
||||
|
||||
db.create_forge_instance(&msg).await.unwrap();
|
||||
} else {
|
||||
if !federate.forge_exists(&url).await.unwrap() {
|
||||
let forge = db.get_forge(&url).await.unwrap();
|
||||
let msg = CreateForge {
|
||||
url: url.clone(),
|
||||
forge_type: forge.forge_type,
|
||||
};
|
||||
federate.create_forge_instance(&msg).await.unwrap();
|
||||
}
|
||||
} else if !federate.forge_exists(url).await.unwrap() {
|
||||
let forge = db.get_forge(url).await.unwrap();
|
||||
let msg = CreateForge {
|
||||
url: url.clone(),
|
||||
forge_type: forge.forge_type,
|
||||
};
|
||||
federate.create_forge_instance(&msg).await.unwrap();
|
||||
}
|
||||
|
||||
loop {
|
||||
|
@ -84,15 +82,14 @@ impl Ctx {
|
|||
let msg = u.as_ref().into();
|
||||
db.add_user(&msg).await.unwrap();
|
||||
federate.create_user(&msg).await.unwrap();
|
||||
} else {
|
||||
if !federate
|
||||
.user_exists(username, forge.get_url())
|
||||
.await
|
||||
.unwrap()
|
||||
{
|
||||
let msg = u.as_ref().into();
|
||||
federate.create_user(&msg).await.unwrap();
|
||||
}
|
||||
}
|
||||
if !federate
|
||||
.user_exists(username, forge.get_url())
|
||||
.await
|
||||
.unwrap()
|
||||
{
|
||||
let msg = u.as_ref().into();
|
||||
federate.create_user(&msg).await.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,15 +103,14 @@ impl Ctx {
|
|||
let msg = r.into();
|
||||
db.create_repository(&msg).await.unwrap();
|
||||
federate.create_repository(&msg).await.unwrap();
|
||||
} else {
|
||||
if !federate
|
||||
.repository_exists(&r.name, &r.owner.username, &r.url)
|
||||
.await
|
||||
.unwrap()
|
||||
{
|
||||
let msg = r.into();
|
||||
federate.create_repository(&msg).await.unwrap();
|
||||
}
|
||||
}
|
||||
if !federate
|
||||
.repository_exists(&r.name, &r.owner.username, &r.url)
|
||||
.await
|
||||
.unwrap()
|
||||
{
|
||||
let msg = r.into();
|
||||
federate.create_repository(&msg).await.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -126,7 +122,6 @@ impl Ctx {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::tests::sqlx_sqlite;
|
||||
use db_core::prelude::*;
|
||||
|
||||
use url::Url;
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ pub mod routes {
|
|||
use super::*;
|
||||
|
||||
lazy_static! {
|
||||
pub static ref ASSETS: Assets = Assets::new();
|
||||
pub static ref ASSETS: Assets = Assets::default();
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
|
@ -43,9 +43,9 @@ pub mod routes {
|
|||
pub css: &'static str,
|
||||
}
|
||||
|
||||
impl Assets {
|
||||
impl Default for Assets {
|
||||
/// create new instance of Routes
|
||||
pub fn new() -> Assets {
|
||||
fn default() -> Assets {
|
||||
Assets {
|
||||
css: &static_files::assets::CSS,
|
||||
}
|
||||
|
|
|
@ -67,9 +67,7 @@ mod tests {
|
|||
use actix_web::http::StatusCode;
|
||||
use actix_web::test;
|
||||
|
||||
use crate::db::BoxDB;
|
||||
use crate::tests::*;
|
||||
use crate::ArcCtx;
|
||||
use crate::*;
|
||||
|
||||
use super::assets::CSS;
|
||||
|
|
18
src/tests.rs
18
src/tests.rs
|
@ -25,16 +25,16 @@ pub use crate::federate::{get_federate, ArcFederate};
|
|||
use crate::settings::{DBType, Settings};
|
||||
|
||||
//use actix_web::cookie::Cookie;
|
||||
use crate::errors::*;
|
||||
//use crate::errors::*;
|
||||
use crate::*;
|
||||
use actix_web::test;
|
||||
use actix_web::{
|
||||
body::{BoxBody, EitherBody},
|
||||
dev::ServiceResponse,
|
||||
error::ResponseError,
|
||||
http::StatusCode,
|
||||
};
|
||||
use serde::Serialize;
|
||||
//use actix_web::test;
|
||||
//use actix_web::{
|
||||
// body::{BoxBody, EitherBody},
|
||||
// dev::ServiceResponse,
|
||||
// error::ResponseError,
|
||||
// http::StatusCode,
|
||||
//};
|
||||
//use serde::Serialize;
|
||||
|
||||
//pub mod sqlx_postgres {
|
||||
// use super::*;
|
||||
|
|
|
@ -31,7 +31,6 @@ pub struct TXTChallenge {
|
|||
pub value: String,
|
||||
}
|
||||
|
||||
const KEY_LEN: usize = 30;
|
||||
const VALUES_LEN: usize = 30;
|
||||
|
||||
impl TXTChallenge {
|
||||
|
|
Loading…
Reference in a new issue