update tests

pull/5/head
Mingwei Samuel 2019-10-30 22:52:00 -07:00
parent 9db4c1a4a5
commit 2bd0e2ac4c
10 changed files with 55 additions and 174 deletions

View File

@ -195,7 +195,7 @@ impl<'a> LeagueExpV4<'a> {
let mut query_params = Serializer::new(String::new()); let mut query_params = Serializer::new(String::new());
if let Some(page) = page { query_params.append_pair("page", &*page.to_string()); }; if let Some(page) = page { query_params.append_pair("page", &*page.to_string()); };
let query_string = query_params.finish(); let query_string = query_params.finish();
let path_string = format!("/lol/league-exp/v4/entries/{}/{}/{}", division, tier, queue); let path_string = format!("/lol/league-exp/v4/entries/{}/{}/{}", queue, tier, division);
self.base.get::<Vec<league_exp_v4::LeagueEntry>>("league-exp-v4.getLeagueEntries", region, path_string, Some(query_string)) self.base.get::<Vec<league_exp_v4::LeagueEntry>>("league-exp-v4.getLeagueEntries", region, path_string, Some(query_string))
} }

View File

@ -1,4 +1,5 @@
//! Module docs TODO. //! Module docs TODO.
#![feature(non_exhaustive)]
mod riot_api_error; mod riot_api_error;
pub use riot_api_error::*; pub use riot_api_error::*;
@ -15,41 +16,3 @@ pub use riot_api::*;
mod req; mod req;
mod util; mod util;
#[cfg(test)]
mod tests {
use tokio::runtime::Runtime;
use super::*;
use url::form_urlencoded::Serializer;
#[test]
fn checkme() {
let mut query = Serializer::new(String::new());
query.append_pair("hello", "false");
query.append_pair("hello", "world");
let result = query.finish();
println!("{}", result);
}
#[test]
#[ignore]
fn it_works() {
env_logger::init();
let champ = crate::consts::Champion::Riven;
println!("{}", champ);
let api_key = std::fs::read_to_string("apikey.txt").unwrap(); // TODO don't use unwrap.
let rt = Runtime::new().unwrap();
let riot_api = RiotApi::with_key(api_key.trim());
for i in 0..2 {
let my_future = riot_api.champion_mastery_v4().get_all_champion_masteries(
consts::Region::NA, "SBM8Ubipo4ge2yj7bhEzL7yvV0C9Oc1XA2l6v5okGMA_nCw");
let val = rt.block_on(my_future).unwrap();
//println!("VAL {}: {:#?}", i, val.unwrap());
}
}
}

View File

@ -8,7 +8,8 @@ macro_rules! async_tests {
const TUPLE_ERR: (u32, u32) = (0, 1); const TUPLE_ERR: (u32, u32) = (0, 1);
std::process::exit({ std::process::exit({
let mut rt = Runtime::new().expect("Failed to create runtime."); let mut rt = tokio::runtime::current_thread::Runtime::new()
.expect("Failed to create runtime.");
let (_, errs) = rt.block_on(async { let (_, errs) = rt.block_on(async {
println!(); println!();
@ -70,6 +71,14 @@ macro_rules! rassert {
macro_rules! rassert_eq { macro_rules! rassert_eq {
( $a:expr, $b:expr ) => { rassert!($a == $b) }; ( $a:expr, $b:expr ) => { rassert!($a == $b) };
( $a:expr, $b:expr, $format:expr $(, $arg:expr)* ) => { ( $a:expr, $b:expr, $format:expr $(, $arg:expr)* ) => {
rassert!($a == $b, $format, $( $arg )* ) rassert!($a == $b, $format $(, $arg )* )
};
}
#[macro_export]
macro_rules! rassert_ne {
( $a:expr, $b:expr ) => { rassert!($a != $b) };
( $a:expr, $b:expr, $format:expr $(, $arg:expr)* ) => {
rassert!($a != $b, $format $(, $arg )* )
}; };
} }

View File

@ -1,5 +0,0 @@
pub const SUMMONER_ID_LUGNUTSK: &'static str = "SBM8Ubipo4ge2yj7bhEzL7yvV0C9Oc1XA2l6v5okGMA_nCw";
pub const SUMMONER_ID_MA5TERY: &'static str = "IbC4uyFEEW3ZkZw6FZF4bViw3P1EynclAcI6-p-vCpI99Ec";
pub const SUMMONER_ID_C9SNEAKY: &'static str = "ghHSdADqgxKwcRl_vWndx6wKiyZx0xKQv-LOhOcU5LU";
pub const ACCOUNT_ID_C9SNEAKY: &'static str = "ML_CcLT94UUHp1iDvXOXCidfmzzPrk_Jbub1f_INhw";
pub const ACCOUNT_ID_LUGNUTSK: &'static str = "iheZF2uJ50S84Hfq6Ob8GNlJAUmBmac-EsEEWBJjD01q1jQ";

View File

@ -1,75 +0,0 @@
#![feature(custom_test_frameworks)]
#![test_runner(my_runner)]
// use std::future::Future;
use colored::*;
use lazy_static::lazy_static;
use riven::RiotApi;
use tokio::runtime::current_thread::Runtime;
lazy_static! {
static ref API_KEY: String = {
let api_key = std::fs::read_to_string("apikey.txt").unwrap(); // TODO don't use unwrap.
api_key.trim().to_owned()
};
static ref RIOT_API: RiotApi<'static> = {
RiotApi::with_key(&API_KEY)
};
}
fn my_runner(tests: &[()]) {
std::process::exit({
let mut rt = Runtime::new().expect("Failed to create runtime.");
let result = rt.block_on(async {
let a = async {
let result = plus_one(&RIOT_API).await;
print!("plus_one ... ");
match &result {
Ok(_) => println!("{}", "ok".green()),
Err(msg) => println!("{}: {}", "error".red(), msg),
};
result
};
let b = async {
let result = plus_two(&RIOT_API).await;
print!("plus_two ... ");
match &result {
Ok(_) => println!("{}", "ok".green()),
Err(msg) => println!("{}: {}", "error".bright_red(), msg),
};
result
};
let err = None;
let err = err.or(a.await.err());
let err = err.or(b.await.err());
err.map_or(Ok(()), |e| Err(e))
});
match &result {
Ok(_) => 0,
Err(_) => 2,
}
});
}
macro_rules! rassert {
( $x:expr ) => {
{
if $x { Ok(()) } else { Err(stringify!($x)) }?
}
};
}
macro_rules! rassert_eq {
( $a:expr, $b:expr ) => { rassert!($a == $b) };
}
async fn plus_one(riot_api: &'static RiotApi<'static>) -> Result<(), String> {
rassert_eq!("world", "world");
Ok(())
}
async fn plus_two(riot_api: &'static RiotApi<'static>) -> Result<(), String> {
rassert_eq!("hello", "world");
Ok(())
}

View File

@ -2,23 +2,15 @@
#![test_runner(my_runner)] #![test_runner(my_runner)]
mod async_tests; mod async_tests;
mod ids; mod testutils;
use testutils::*;
use colored::*; use colored::*;
use lazy_static::lazy_static;
use tokio::runtime::current_thread::Runtime;
use riven::RiotApi; use riven::RiotApi;
use riven::consts::*; use riven::consts::*;
lazy_static! {
static ref RIOT_API: RiotApi = {
let api_key = std::fs::read_to_string("apikey.txt").unwrap();
RiotApi::with_key(api_key.trim())
};
}
async_tests!{ async_tests!{
my_runner { my_runner {
// Champion Mastery tests. // Champion Mastery tests.

View File

@ -2,23 +2,13 @@
#![test_runner(my_runner)] #![test_runner(my_runner)]
mod async_tests; mod async_tests;
mod ids; mod testutils;
use testutils::*;
use colored::*; use colored::*;
use lazy_static::lazy_static;
use tokio::runtime::current_thread::Runtime;
use riven::RiotApi;
use riven::consts::*; use riven::consts::*;
lazy_static! {
static ref RIOT_API: RiotApi = {
let api_key = std::fs::read_to_string("apikey.txt").unwrap();
RiotApi::with_key(api_key.trim())
};
}
async_tests!{ async_tests!{
my_runner { my_runner {
// Summoner tests. // Summoner tests.

View File

@ -2,24 +2,15 @@
#![test_runner(my_runner)] #![test_runner(my_runner)]
mod async_tests; mod async_tests;
mod ids; mod testutils;
use testutils::*;
use colored::*; use colored::*;
use lazy_static::lazy_static;
use tokio::runtime::current_thread::Runtime;
use riven::RiotApi;
use riven::consts::*; use riven::consts::*;
use riven::endpoints::summoner_v4::*; use riven::endpoints::summoner_v4::*;
lazy_static! {
static ref RIOT_API: RiotApi = {
let api_key = std::fs::read_to_string("apikey.txt").unwrap();
RiotApi::with_key(api_key.trim())
};
}
fn validate_lugnutsk(s: Summoner, tag: &str) -> Result<(), String> { fn validate_lugnutsk(s: Summoner, tag: &str) -> Result<(), String> {
rassert_eq!("LugnutsK", s.name, rassert_eq!("LugnutsK", s.name,
"LugnutsK name didn't match {}.", tag); "LugnutsK name didn't match {}.", tag);
@ -53,10 +44,16 @@ async_tests!{
rassert_eq!(10, level, "New player level: {}", level); rassert_eq!(10, level, "New player level: {}", level);
Ok(()) Ok(())
}, },
leagueexp_get: async {
let p = RIOT_API.league_exp_v4().get_league_entries(Region::NA, Division::I, Tier::CHALLENGER, QueueType::RANKED_SOLO_5x5, None);
let d = p.await.map_err(|e| e.to_string())?.ok_or("Failed to get challenger exp league entries.".to_owned())?;
rassert!(!d.is_empty(), "Challenger shouldn't be empty.");
Ok(())
},
match_get: async { match_get: async {
let p = RIOT_API.match_v4().get_match(Region::NA, 3190191338); let p = RIOT_API.match_v4().get_match(Region::NA, 3190191338);
let m = p.await.map_err(|e| e.to_string())?.ok_or("Failed to get match.".to_owned())?; let m = p.await.map_err(|e| e.to_string())?.ok_or("Failed to get match.".to_owned())?;
// TODO. rassert!(!m.participants.is_empty(), "Match should have participants.");
Ok(()) Ok(())
}, },
// match_get_old: async { // match_get_old: async {
@ -68,13 +65,13 @@ async_tests!{
match_get_aram: async { match_get_aram: async {
let p = RIOT_API.match_v4().get_match(Region::NA, 2961635718); let p = RIOT_API.match_v4().get_match(Region::NA, 2961635718);
let m = p.await.map_err(|e| e.to_string())?.ok_or("Failed to get match.".to_owned())?; let m = p.await.map_err(|e| e.to_string())?.ok_or("Failed to get match.".to_owned())?;
// TODO. rassert!(!m.participants.is_empty(), "Match should have participants.");
Ok(()) Ok(())
}, },
match_get_urf900: async { match_get_urf900: async {
let p = RIOT_API.match_v4().get_match(Region::NA, 2963663381); let p = RIOT_API.match_v4().get_match(Region::NA, 2963663381);
let m = p.await.map_err(|e| e.to_string())?.ok_or("Failed to get match.".to_owned())?; let m = p.await.map_err(|e| e.to_string())?.ok_or("Failed to get match.".to_owned())?;
// TODO. rassert!(!m.participants.is_empty(), "Match should have participants.");
Ok(()) Ok(())
}, },
} }

View File

@ -2,23 +2,14 @@
#![test_runner(my_runner)] #![test_runner(my_runner)]
mod async_tests; mod async_tests;
mod ids; mod testutils;
use testutils::*;
use colored::*; use colored::*;
use lazy_static::lazy_static;
use tokio::runtime::current_thread::Runtime;
use riven::RiotApi;
use riven::consts::*; use riven::consts::*;
lazy_static! {
static ref RIOT_API: RiotApi = {
let api_key = std::fs::read_to_string("apikey.txt").unwrap();
RiotApi::with_key(api_key.trim())
};
}
async_tests!{ async_tests!{
my_runner { my_runner {
league_summoner_bulk_test: async { league_summoner_bulk_test: async {

19
tests/testutils.rs Normal file
View File

@ -0,0 +1,19 @@
use riven::RiotApi;
use lazy_static::lazy_static;
lazy_static! {
pub static ref RIOT_API: RiotApi = {
let api_key = std::env::var("RGAPI_KEY").ok()
.or_else(|| std::fs::read_to_string("apikey.txt").ok())
.expect("Failed to find RGAPI_KEY env var or apikey.txt.");
RiotApi::with_key(api_key.trim())
};
}
pub mod ids {
pub const SUMMONER_ID_LUGNUTSK: &'static str = "SBM8Ubipo4ge2yj7bhEzL7yvV0C9Oc1XA2l6v5okGMA_nCw";
pub const SUMMONER_ID_MA5TERY: &'static str = "IbC4uyFEEW3ZkZw6FZF4bViw3P1EynclAcI6-p-vCpI99Ec";
pub const SUMMONER_ID_C9SNEAKY: &'static str = "ghHSdADqgxKwcRl_vWndx6wKiyZx0xKQv-LOhOcU5LU";
pub const ACCOUNT_ID_C9SNEAKY: &'static str = "ML_CcLT94UUHp1iDvXOXCidfmzzPrk_Jbub1f_INhw";
pub const ACCOUNT_ID_LUGNUTSK: &'static str = "iheZF2uJ50S84Hfq6Ob8GNlJAUmBmac-EsEEWBJjD01q1jQ";
}