improve tests and docs
This commit is contained in:
parent
85a876b221
commit
007a26974f
3 changed files with 49 additions and 16 deletions
8
Cargo.lock
generated
8
Cargo.lock
generated
|
@ -520,9 +520,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.165"
|
version = "0.2.166"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fcb4d3d38eab6c5239a362fa8bae48c03baf980a6e7079f063942d563ef3533e"
|
checksum = "c2ccc108bbc0b1331bd061864e7cd823c0cab660bbe6970e66e2c0614decde36"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "linux-raw-sys"
|
name = "linux-raw-sys"
|
||||||
|
@ -1301,9 +1301,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tracing-attributes"
|
name = "tracing-attributes"
|
||||||
version = "0.1.27"
|
version = "0.1.28"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
|
checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
|
32
src/data.rs
32
src/data.rs
|
@ -9,9 +9,13 @@ pub(crate) type SearchFunc = fn(String, Vec<String>) -> Result<String, String>;
|
||||||
/// These fields are just those listed in the example on [torznab.github.io](https://torznab.github.io), there's no actual specification for thse fields.
|
/// These fields are just those listed in the example on [torznab.github.io](https://torznab.github.io), there's no actual specification for thse fields.
|
||||||
/// TODO: Update this to have customizable fields instead
|
/// TODO: Update this to have customizable fields instead
|
||||||
pub struct ServerInfo {
|
pub struct ServerInfo {
|
||||||
|
/// The title of the server
|
||||||
pub title: Option<String>,
|
pub title: Option<String>,
|
||||||
|
/// The email for the server info
|
||||||
pub email: Option<String>,
|
pub email: Option<String>,
|
||||||
|
/// The URL to the server's image (e.g. logo)
|
||||||
pub image: Option<String>,
|
pub image: Option<String>,
|
||||||
|
/// What version the server is - unrelated to torznab-toolkit's version, but may be used by the program
|
||||||
pub version: Option<String>,
|
pub version: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,49 +29,67 @@ pub struct Limits {
|
||||||
In fact, I *really* hope you aren't - if you are, you're doing something extremely wrong
|
In fact, I *really* hope you aren't - if you are, you're doing something extremely wrong
|
||||||
But hey, it's an option
|
But hey, it's an option
|
||||||
*/
|
*/
|
||||||
|
/// The maximum number of entries that can be listed in a search query
|
||||||
pub max: u64,
|
pub max: u64,
|
||||||
|
/// The default number of entries to be listed in a search query
|
||||||
pub default: u64,
|
pub default: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
/// A struct holding the info for a type of search
|
/// A struct holding the info for a type of search
|
||||||
/// - `search_type` must be `search`, `tv-search`, `movie-search`, `audio-search`, or `book-search`
|
|
||||||
/// - `available`
|
|
||||||
pub struct SearchInfo {
|
pub struct SearchInfo {
|
||||||
|
/// What type of search this is - must be `search`, `tv-search`, `movie-search`, `audio-search`, or `book-search`
|
||||||
pub search_type: String,
|
pub search_type: String,
|
||||||
|
/// Whether this search type is available
|
||||||
pub available: bool,
|
pub available: bool,
|
||||||
|
/// The supported parameters for this search type
|
||||||
pub supported_params: Vec<String>,
|
pub supported_params: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
/// Contains subcategories, for use in `Category`
|
/// Contains subcategories, for use in `Category`
|
||||||
pub struct Subcategory {
|
pub struct Subcategory {
|
||||||
|
/// The numeric ID of a subcategory
|
||||||
|
///
|
||||||
|
/// The (de facto?) standard is `xxyy`, xx being the first two digits of the category, and the last two digits specifying the subcategory; see also: Category
|
||||||
pub id: String,
|
pub id: String,
|
||||||
|
/// The name of the subcategory, e.g. "Anime" under the "TV" cateogyr
|
||||||
pub name: String,
|
pub name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
/// Contains a category, for use in `Caps` and searches as a query parameter
|
/// Contains a category, for use in `Caps` and searches as a query parameter
|
||||||
pub struct Category {
|
pub struct Category {
|
||||||
|
/// The numeric ID of a category
|
||||||
|
///
|
||||||
|
/// The (de facto?) standard is `xxyy`, xx being the first two digits of the category, and the last two digits specifying the subcategory; see also: Subcategory
|
||||||
pub id: String,
|
pub id: String,
|
||||||
|
/// The name of the category, e.g. "Movies"
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
/// A vector of all the subcategory in this category
|
||||||
pub subcategories: Vec<Subcategory>,
|
pub subcategories: Vec<Subcategory>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
/// Contains a genre, for use in `Caps` and searches as a query parameter
|
/// Contains a genre, for use in `Caps` and searches as a query parameter
|
||||||
pub struct Genre {
|
pub struct Genre {
|
||||||
|
/// The numeric ID of a genre
|
||||||
|
///
|
||||||
|
/// I'm not aware of any sure standard for this; the specification for Torznab shows an example with an ID of 1.
|
||||||
pub id: String,
|
pub id: String,
|
||||||
|
/// The numeric ID of the category this genre is for.
|
||||||
pub category_id: String,
|
pub category_id: String,
|
||||||
|
/// The name of the genre
|
||||||
pub name: String,
|
pub name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
/// Contains a tag, for use in `Caps` and searches as a query parameter
|
/// Contains a tag, for use in `Caps` and searches as a query parameter
|
||||||
pub struct Tag {
|
pub struct Tag {
|
||||||
pub id: String,
|
/// The name of a tag for a torrent
|
||||||
pub category_id: String,
|
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
/// The description of the tag
|
||||||
|
pub description: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
@ -108,7 +130,7 @@ pub struct Caps {
|
||||||
/// A search function (/api?t=search) and capabilities (/api?t=caps - struct Caps) required
|
/// A search function (/api?t=search) and capabilities (/api?t=caps - struct Caps) required
|
||||||
/// Everything else is optional
|
/// Everything else is optional
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub search: SearchFunc, // NOTE: This is NOT optional,
|
pub search: SearchFunc,
|
||||||
pub auth: Option<AuthFunc>,
|
pub auth: Option<AuthFunc>,
|
||||||
pub caps: Caps,
|
pub caps: Caps,
|
||||||
pub tvsearch: Option<SearchFunc>,
|
pub tvsearch: Option<SearchFunc>,
|
||||||
|
|
25
src/dummy.rs
25
src/dummy.rs
|
@ -1,11 +1,11 @@
|
||||||
//! Some dummy stuff for testing the API
|
//! Some dummy stuff for testing the API
|
||||||
use crate::data::*;
|
use crate::data::*;
|
||||||
|
|
||||||
fn dummy_search_func(a: String, b: Vec<String>) -> Result<String, String> {
|
fn dummy_search_func(_a: String, _b: Vec<String>) -> Result<String, String> {
|
||||||
return Ok("hi".to_string());
|
return Ok("hi".to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dummy_auth_func(a: String) -> Result<bool, String> {
|
fn dummy_auth_func(_a: String) -> Result<bool, String> {
|
||||||
return Ok(true);
|
return Ok(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,9 +40,8 @@ pub fn create_empty_config() -> Config {
|
||||||
|
|
||||||
let mut tags = Vec::new();
|
let mut tags = Vec::new();
|
||||||
tags.push(Tag {
|
tags.push(Tag {
|
||||||
id: "a".to_string(),
|
name: "a".to_string(),
|
||||||
category_id: "b".to_string(),
|
description: "b".to_string(),
|
||||||
name: "c".to_string(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return Config {
|
return Config {
|
||||||
|
@ -73,7 +72,7 @@ pub fn create_empty_config() -> Config {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::{dummy::create_empty_config, run};
|
use crate::{api, dummy::create_empty_config, run};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn caps_test_with_empty_config() {
|
fn caps_test_with_empty_config() {
|
||||||
|
@ -93,7 +92,19 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn api_with_empty() {
|
async fn api_with_empty_config() {
|
||||||
run(create_empty_config()).await.unwrap();
|
run(create_empty_config()).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn api_with_no_config() {
|
||||||
|
// copied from lib.rs
|
||||||
|
// in this case, CONFIG is still None
|
||||||
|
// can't just use run() because that expects a Config, not an Option<Config>
|
||||||
|
rocket::build()
|
||||||
|
.mount("/", rocket::routes![api::caps])
|
||||||
|
.launch()
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue