rename test modules
This commit is contained in:
parent
6bbfe1a6b4
commit
6698c00f78
8 changed files with 77 additions and 71 deletions
|
@ -17,12 +17,12 @@ pub fn get_database() -> Result<&'static DatabaseConnection, Error> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod unit_test {
|
||||||
use super::get_database;
|
use super::get_database;
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn unit_lib_error_uninitialized() {
|
fn error_uninitialized() {
|
||||||
assert_eq!(get_database().unwrap_err(), Error::Uninitialized);
|
assert_eq!(get_database().unwrap_err(), Error::Uninitialized);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ pub static VALIDATOR: Lazy<JSONSchema> = Lazy::new(|| Antenna::validator());
|
||||||
// ----
|
// ----
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod unit_test {
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
use crate::{entity::sea_orm_active_enums::AntennaSrcEnum, schema::antenna::AntennaSrc};
|
use crate::{entity::sea_orm_active_enums::AntennaSrcEnum, schema::antenna::AntennaSrc};
|
||||||
|
@ -68,13 +68,13 @@ mod tests {
|
||||||
use super::VALIDATOR;
|
use super::VALIDATOR;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn unit_schema_src_from_active_enum() {
|
fn src_from_active_enum() {
|
||||||
let src = AntennaSrc::try_from(AntennaSrcEnum::All).unwrap();
|
let src = AntennaSrc::try_from(AntennaSrcEnum::All).unwrap();
|
||||||
assert_eq!(src, AntennaSrc::All);
|
assert_eq!(src, AntennaSrc::All);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn unit_schema_antenna_valid() {
|
fn antenna_valid() {
|
||||||
let instance = json!({
|
let instance = json!({
|
||||||
"id": "9f4x0bkx1u",
|
"id": "9f4x0bkx1u",
|
||||||
"createdAt": "2023-05-24T06:56:14.323Z",
|
"createdAt": "2023-05-24T06:56:14.323Z",
|
||||||
|
@ -98,7 +98,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn unit_schema_antenna_invalid() {
|
fn antenna_invalid() {
|
||||||
let instance = json!({
|
let instance = json!({
|
||||||
// "id" is required
|
// "id" is required
|
||||||
"id": null,
|
"id": null,
|
||||||
|
|
|
@ -94,14 +94,14 @@ impl Schema<Self> for App {}
|
||||||
pub static VALIDATOR: Lazy<JSONSchema> = Lazy::new(|| App::validator());
|
pub static VALIDATOR: Lazy<JSONSchema> = Lazy::new(|| App::validator());
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod unit_test {
|
||||||
#[test]
|
#[test]
|
||||||
fn unit_schema_app_valid() {
|
fn valid() {
|
||||||
todo!();
|
todo!();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn unit_shcmea_app_invalid() {
|
fn invalid() {
|
||||||
todo!();
|
todo!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,8 +81,12 @@ async fn setup_model(db: &DatabaseConnection) {
|
||||||
.expect("Unable to setup predefined models");
|
.expect("Unable to setup predefined models");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
mod it_test {
|
||||||
async fn inte_common_prepare_and_cleanup() {
|
use super::{cleanup, prepare};
|
||||||
prepare().await;
|
|
||||||
cleanup().await;
|
#[tokio::test]
|
||||||
|
async fn can_prepare_and_cleanup() {
|
||||||
|
prepare().await;
|
||||||
|
cleanup().await;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,60 +1,62 @@
|
||||||
use model::{
|
mod it_test {
|
||||||
entity::{antenna, user},
|
use model::{
|
||||||
repository::Repository,
|
entity::{antenna, user},
|
||||||
schema,
|
repository::Repository,
|
||||||
};
|
schema,
|
||||||
use sea_orm::{ColumnTrait, EntityTrait, QueryFilter};
|
};
|
||||||
|
use sea_orm::{ColumnTrait, EntityTrait, QueryFilter};
|
||||||
|
|
||||||
use crate::{cleanup, prepare};
|
use crate::{cleanup, prepare};
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn inte_repository_antenna_can_pack() {
|
async fn can_pack() {
|
||||||
prepare().await;
|
prepare().await;
|
||||||
|
|
||||||
let db = database::get_database().unwrap();
|
let db = database::get_database().unwrap();
|
||||||
|
|
||||||
let alice_antenna = user::Entity::find()
|
let alice_antenna = user::Entity::find()
|
||||||
.filter(user::Column::Username.eq("alice"))
|
.filter(user::Column::Username.eq("alice"))
|
||||||
.find_also_related(antenna::Entity)
|
.find_also_related(antenna::Entity)
|
||||||
.one(db)
|
.one(db)
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.expect("alice not found")
|
.expect("alice not found")
|
||||||
.1
|
.1
|
||||||
.expect("alice's antenna not found");
|
.expect("alice's antenna not found");
|
||||||
|
|
||||||
let packed = alice_antenna
|
let packed = alice_antenna
|
||||||
.to_owned()
|
.to_owned()
|
||||||
.pack()
|
.pack()
|
||||||
.await
|
.await
|
||||||
.expect("Unable to pack");
|
.expect("Unable to pack");
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
packed,
|
packed,
|
||||||
schema::antenna::Antenna {
|
schema::antenna::Antenna {
|
||||||
id: alice_antenna.id,
|
id: alice_antenna.id,
|
||||||
created_at: alice_antenna.created_at.into(),
|
created_at: alice_antenna.created_at.into(),
|
||||||
name: "Test Antenna".to_string(),
|
name: "Test Antenna".to_string(),
|
||||||
keywords: vec![
|
keywords: vec![
|
||||||
vec!["foo".to_string(), "bar".to_string()],
|
vec!["foo".to_string(), "bar".to_string()],
|
||||||
vec!["foobar".to_string()]
|
vec!["foobar".to_string()]
|
||||||
],
|
],
|
||||||
exclude_keywords: vec![
|
exclude_keywords: vec![
|
||||||
vec!["abc".to_string()],
|
vec!["abc".to_string()],
|
||||||
vec!["def".to_string(), "ghi".to_string()]
|
vec!["def".to_string(), "ghi".to_string()]
|
||||||
],
|
],
|
||||||
src: schema::antenna::AntennaSrc::All,
|
src: schema::antenna::AntennaSrc::All,
|
||||||
user_list_id: None,
|
user_list_id: None,
|
||||||
user_group_id: None,
|
user_group_id: None,
|
||||||
users: vec![],
|
users: vec![],
|
||||||
instances: vec![],
|
instances: vec![],
|
||||||
case_sensitive: true,
|
case_sensitive: true,
|
||||||
notify: true,
|
notify: true,
|
||||||
with_replies: false,
|
with_replies: false,
|
||||||
with_file: false,
|
with_file: false,
|
||||||
has_unread_note: false,
|
has_unread_note: false,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
cleanup().await;
|
cleanup().await;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,13 +21,13 @@ pub fn create_id() -> Result<String, ErrorUninitialized> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod unit_test {
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
|
||||||
use crate::id;
|
use crate::id;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn unit_id_can_generate() {
|
fn can_generate_unique_ids() {
|
||||||
assert_eq!(id::create_id(), Err(id::ErrorUninitialized));
|
assert_eq!(id::create_id(), Err(id::ErrorUninitialized));
|
||||||
id::init_id(12);
|
id::init_id(12);
|
||||||
assert_eq!(id::create_id().unwrap().len(), 12);
|
assert_eq!(id::create_id().unwrap().len(), 12);
|
||||||
|
|
|
@ -9,13 +9,13 @@ pub fn gen_string(length: u16) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod unit_test {
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
|
||||||
use super::gen_string;
|
use super::gen_string;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn unit_random_can_generate_string() {
|
fn can_generate_unique_strings() {
|
||||||
assert_eq!(gen_string(16).len(), 16);
|
assert_eq!(gen_string(16).len(), 16);
|
||||||
assert_ne!(gen_string(16), gen_string(16));
|
assert_ne!(gen_string(16), gen_string(16));
|
||||||
let s1 = thread::spawn(|| gen_string(16));
|
let s1 = thread::spawn(|| gen_string(16));
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
"test": "ava",
|
"test": "ava",
|
||||||
"universal": "napi universal",
|
"universal": "napi universal",
|
||||||
"version": "napi version",
|
"version": "napi version",
|
||||||
"cargo:unit": "cargo test --workspace unit",
|
"cargo:unit": "cargo test --workspace unit_test",
|
||||||
"cargo:integration": "cargo test --workspace inte -- --test-threads=1"
|
"cargo:integration": "cargo test --workspace it_test -- --test-threads=1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue