Test with PostgreSQL too (#309)

* Test with PostgreSQL too

* Add 'test' to Travis build stages

* Add test coverage for postgresql
This commit is contained in:
Baptiste Gelez 2018-11-07 15:50:24 +01:00 committed by GitHub
parent 3690e4cfb9
commit b28411da99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 59 additions and 30 deletions

View File

@ -7,6 +7,7 @@ cache:
- kcov-master
sudo: true
dist: trusty
services: postgres
addons:
apt:
@ -21,7 +22,7 @@ addons:
- libiberty-dev
stages:
- build
- code coverage
- test and coverage
jobs:
include:
- stage: build
@ -34,21 +35,22 @@ jobs:
env:
- MIGRATION_DIR=migrations/sqlite FEATURES=sqlite DATABASE_URL=plume.sqlite3
script: cargo build --no-default-features --features="${FEATURES}"
- stage: code coverage
name: "Calculate code coverage"
- stage: test and coverage
name: "Test with potgresql backend"
env:
- MIGRATION_DIR=migrations/postgres FEATURES=postgres DATABASE_URL=postgres://postgres@localhost/plume_tests
- RUSTFLAGS='-C link-dead-code'
before_script: psql -c 'create database plume_tests;' -U postgres
script:
- |
cargo test --features "${FEATURES}" --no-default-features --all &&
./script/compute_coverage.sh
- stage: test and coverage
name: "Test with Sqlite backend"
env:
- MIGRATION_DIR=migrations/sqlite FEATURES=sqlite DATABASE_URL=plume.sqlite3
- RUSTFLAGS='-C link-dead-code'
script:
- |
cargo test --features sqlite --no-default-features --all && (
wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz &&
tar xzf master.tar.gz &&
mkdir -p kcov-master/build &&
cd kcov-master/build &&
cmake .. &&
make &&
sudo make install &&
cd ../.. &&
for crate in plume plume_common plume_models plume_api plm lib; do for file in target/debug/$crate-*[^\.d]; do mkdir -p "target/cov/$(basename $file)"; kcov --exclude-pattern=/.cargo,/usr/lib --verify "target/cov/$(basename $file)" "$file"; done; done &&
bash <(curl -s https://codecov.io/bash) &&
echo "Uploaded code coverage" || true )
cargo test --features "${FEATURES}" --no-default-features --all &&
./script/compute_coverage.sh

View File

@ -5,15 +5,20 @@ extern crate plume_models;
use diesel::Connection;
use plume_models::{
DATABASE_URL,
Connection as Conn,
instance::*,
safe_string::SafeString,
};
#[cfg(feature = "sqlite")]
embed_migrations!("../migrations/sqlite");
#[cfg(feature = "postgres")]
embed_migrations!("../migrations/postgres");
fn db() -> Conn {
let conn = Conn::establish(":memory:").expect("Couldn't connect to the database");
let conn = Conn::establish(&*DATABASE_URL.as_str()).expect("Couldn't connect to the database");
embedded_migrations::run(&conn).expect("Couldn't run migrations");
conn
}
@ -21,6 +26,7 @@ fn db() -> Conn {
#[test]
fn instance_insert() {
let conn = &db();
conn.test_transaction::<_, (), _>(|| {
Instance::insert(conn, NewInstance {
default_license: "WTFPL".to_string(),
local: true,
@ -36,4 +42,6 @@ fn instance_insert() {
assert!(inst.is_some());
let inst = inst.unwrap();
assert_eq!(inst.name, "My instance".to_string());
Ok(())
});
}

19
script/compute_coverage.sh Executable file
View File

@ -0,0 +1,19 @@
#!/bin/bash
wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz &&
tar xzf master.tar.gz &&
mkdir -p kcov-master/build &&
cd kcov-master/build &&
cmake .. &&
make &&
sudo make install &&
cd ../.. &&
for file in target/debug/*-*[^\.d]; do
if [[ -x "$file" ]]
then
filename=$(basename $file)
mkdir -p "target/cov/$filename"
kcov --exclude-pattern=/.cargo,/usr/lib --verify "target/cov/$filename" "$file"
fi
done &&
bash <(curl -s https://codecov.io/bash) &&
echo "Uploaded code coverage"