Added a truncate_db helper function.
This commit is contained in:
parent
7498a37f68
commit
f0a0fdfa83
@ -14,8 +14,9 @@ before_script:
|
||||
# kcov
|
||||
# - apt-get install -y libcurl4-openssl-dev libelf-dev libdw-dev cmake gcc binutils-dev libiberty-dev
|
||||
|
||||
# variables:
|
||||
variables:
|
||||
# RUSTFLAGS: "-C link-dead-code"
|
||||
RUST_BACKTRACE: "FULL"
|
||||
|
||||
# Currently doesnt work.
|
||||
# # Build with meson
|
||||
|
||||
@ -65,3 +65,14 @@ pub fn run_migration_on(connection: &SqliteConnection) -> Result<()> {
|
||||
embedded_migrations::run_with_output(connection, &mut io::stdout())?;
|
||||
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 rss;
|
||||
use reqwest;
|
||||
use r2d2;
|
||||
|
||||
use std::io;
|
||||
|
||||
error_chain! {
|
||||
foreign_links {
|
||||
R2D2TimeoutError(r2d2::GetTimeout);
|
||||
DieselResultError(result::Error);
|
||||
DieselMigrationError(RunMigrationsError);
|
||||
RSSError(rss::Error);
|
||||
|
||||
@ -142,7 +142,7 @@ mod tests {
|
||||
|
||||
use rss;
|
||||
use models::Source;
|
||||
use database::connection;
|
||||
use database::{connection, truncate_db};
|
||||
|
||||
use std::fs;
|
||||
use std::io::BufReader;
|
||||
@ -152,6 +152,7 @@ mod tests {
|
||||
#[test]
|
||||
/// Insert feeds and update/index them.
|
||||
fn test_index_loop() {
|
||||
truncate_db().unwrap();
|
||||
let inpt = vec![
|
||||
"https://request-for-explanation.github.io/podcast/rss.xml",
|
||||
"https://feeds.feedburner.com/InterceptedWithJeremyScahill",
|
||||
@ -192,15 +193,7 @@ mod tests {
|
||||
),
|
||||
];
|
||||
|
||||
{
|
||||
// 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();
|
||||
}
|
||||
truncate_db().unwrap();
|
||||
|
||||
let mut feeds: Vec<_> = urls.iter()
|
||||
.map(|&(path, url)| {
|
||||
@ -224,8 +217,41 @@ mod tests {
|
||||
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]
|
||||
fn test_partial_index_podcast() {
|
||||
truncate_db().unwrap();
|
||||
let url = "https://feeds.feedburner.com/InterceptedWithJeremyScahill";
|
||||
|
||||
let s1 = Source::from_url(url).unwrap();
|
||||
|
||||
@ -5,7 +5,7 @@ max_width = 100
|
||||
comment_width = 100
|
||||
wrap_comments = true
|
||||
error_on_line_overflow = true
|
||||
error_on_line_overflow_comments = true
|
||||
error_on_line_overflow_comments = false
|
||||
tab_spaces = 4
|
||||
newline_style = "Unix"
|
||||
fn_call_style = "Block"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user