Added a truncate_db helper function.
This commit is contained in:
parent
7498a37f68
commit
f0a0fdfa83
@ -14,8 +14,9 @@ before_script:
|
|||||||
# kcov
|
# kcov
|
||||||
# - apt-get install -y libcurl4-openssl-dev libelf-dev libdw-dev cmake gcc binutils-dev libiberty-dev
|
# - apt-get install -y libcurl4-openssl-dev libelf-dev libdw-dev cmake gcc binutils-dev libiberty-dev
|
||||||
|
|
||||||
# variables:
|
variables:
|
||||||
# RUSTFLAGS: "-C link-dead-code"
|
# RUSTFLAGS: "-C link-dead-code"
|
||||||
|
RUST_BACKTRACE: "FULL"
|
||||||
|
|
||||||
# Currently doesnt work.
|
# Currently doesnt work.
|
||||||
# # Build with meson
|
# # Build with meson
|
||||||
|
|||||||
@ -65,3 +65,14 @@ pub fn run_migration_on(connection: &SqliteConnection) -> Result<()> {
|
|||||||
embedded_migrations::run_with_output(connection, &mut io::stdout())?;
|
embedded_migrations::run_with_output(connection, &mut io::stdout())?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reset the database into a clean state.
|
||||||
|
// Test share a Temp file db.
|
||||||
|
pub fn truncate_db() -> Result<()> {
|
||||||
|
let db = connection();
|
||||||
|
let con = db.get()?;
|
||||||
|
con.execute("DELETE FROM episode")?;
|
||||||
|
con.execute("DELETE FROM podcast")?;
|
||||||
|
con.execute("DELETE FROM source")?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|||||||
@ -2,11 +2,13 @@ use diesel::result;
|
|||||||
use diesel::migrations::RunMigrationsError;
|
use diesel::migrations::RunMigrationsError;
|
||||||
use rss;
|
use rss;
|
||||||
use reqwest;
|
use reqwest;
|
||||||
|
use r2d2;
|
||||||
|
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
error_chain! {
|
error_chain! {
|
||||||
foreign_links {
|
foreign_links {
|
||||||
|
R2D2TimeoutError(r2d2::GetTimeout);
|
||||||
DieselResultError(result::Error);
|
DieselResultError(result::Error);
|
||||||
DieselMigrationError(RunMigrationsError);
|
DieselMigrationError(RunMigrationsError);
|
||||||
RSSError(rss::Error);
|
RSSError(rss::Error);
|
||||||
|
|||||||
@ -142,7 +142,7 @@ mod tests {
|
|||||||
|
|
||||||
use rss;
|
use rss;
|
||||||
use models::Source;
|
use models::Source;
|
||||||
use database::connection;
|
use database::{connection, truncate_db};
|
||||||
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::BufReader;
|
use std::io::BufReader;
|
||||||
@ -152,6 +152,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
/// Insert feeds and update/index them.
|
/// Insert feeds and update/index them.
|
||||||
fn test_index_loop() {
|
fn test_index_loop() {
|
||||||
|
truncate_db().unwrap();
|
||||||
let inpt = vec![
|
let inpt = vec![
|
||||||
"https://request-for-explanation.github.io/podcast/rss.xml",
|
"https://request-for-explanation.github.io/podcast/rss.xml",
|
||||||
"https://feeds.feedburner.com/InterceptedWithJeremyScahill",
|
"https://feeds.feedburner.com/InterceptedWithJeremyScahill",
|
||||||
@ -192,15 +193,7 @@ mod tests {
|
|||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
{
|
truncate_db().unwrap();
|
||||||
// Reset the database into a clean state.
|
|
||||||
// Test share a Temp file db I think.
|
|
||||||
let db = connection();
|
|
||||||
let con = db.get().unwrap();
|
|
||||||
con.execute("DELETE FROM episode").unwrap();
|
|
||||||
con.execute("DELETE FROM podcast").unwrap();
|
|
||||||
con.execute("DELETE FROM source").unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut feeds: Vec<_> = urls.iter()
|
let mut feeds: Vec<_> = urls.iter()
|
||||||
.map(|&(path, url)| {
|
.map(|&(path, url)| {
|
||||||
@ -224,8 +217,41 @@ mod tests {
|
|||||||
assert_eq!(dbqueries::get_episodes().unwrap().len(), 274);
|
assert_eq!(dbqueries::get_episodes().unwrap().len(), 274);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
// Ingore this. Trying to replicate a bug
|
||||||
|
// Sometimes I get the following:
|
||||||
|
// ```
|
||||||
|
// failures:
|
||||||
|
// ---- feed::tests::test_partial_index_podcast stdout ----
|
||||||
|
// thread 'feed::tests::test_partial_index_podcast' panicked at 'assertion failed:
|
||||||
|
// `(left == right)` left: `Source { id: 1, uri: "https://feeds.feedburner.com/InterceptedWithJeremyScahill", last_modified: None, http_etag: None }`,
|
||||||
|
// right: `Source { id: 3, uri: "https://feeds.feedburner.com/InterceptedWithJeremyScahill", last_modified: None, http_etag: None }`', hammond-data/src/feed.rs:233:8
|
||||||
|
// note: Run with `RUST_BACKTRACE=1` for a backtrace.
|
||||||
|
// ```
|
||||||
|
fn foo() {
|
||||||
|
truncate_db().unwrap();
|
||||||
|
use models::NewSource;
|
||||||
|
|
||||||
|
let url = "https://feeds.feedburner.com/InterceptedWithJeremyScahill";
|
||||||
|
let sources = dbqueries::get_sources().unwrap();
|
||||||
|
println!("{:?}", sources);
|
||||||
|
|
||||||
|
let s1 = NewSource::new_with_uri(url).into_source().unwrap();
|
||||||
|
let sources = dbqueries::get_sources().unwrap();
|
||||||
|
println!("{:?}", sources);
|
||||||
|
|
||||||
|
let s2 = NewSource::new_with_uri(url).into_source().unwrap();
|
||||||
|
|
||||||
|
let sources = dbqueries::get_sources().unwrap();
|
||||||
|
println!("{:?}", sources);
|
||||||
|
|
||||||
|
assert_eq!(s1, s2);
|
||||||
|
assert_eq!(s1.id(), s2.id());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_partial_index_podcast() {
|
fn test_partial_index_podcast() {
|
||||||
|
truncate_db().unwrap();
|
||||||
let url = "https://feeds.feedburner.com/InterceptedWithJeremyScahill";
|
let url = "https://feeds.feedburner.com/InterceptedWithJeremyScahill";
|
||||||
|
|
||||||
let s1 = Source::from_url(url).unwrap();
|
let s1 = Source::from_url(url).unwrap();
|
||||||
|
|||||||
@ -5,7 +5,7 @@ max_width = 100
|
|||||||
comment_width = 100
|
comment_width = 100
|
||||||
wrap_comments = true
|
wrap_comments = true
|
||||||
error_on_line_overflow = true
|
error_on_line_overflow = true
|
||||||
error_on_line_overflow_comments = true
|
error_on_line_overflow_comments = false
|
||||||
tab_spaces = 4
|
tab_spaces = 4
|
||||||
newline_style = "Unix"
|
newline_style = "Unix"
|
||||||
fn_call_style = "Block"
|
fn_call_style = "Block"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user