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:
parent
3690e4cfb9
commit
b28411da99
32
.travis.yml
32
.travis.yml
@ -7,6 +7,7 @@ cache:
|
|||||||
- kcov-master
|
- kcov-master
|
||||||
sudo: true
|
sudo: true
|
||||||
dist: trusty
|
dist: trusty
|
||||||
|
services: postgres
|
||||||
|
|
||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
@ -21,7 +22,7 @@ addons:
|
|||||||
- libiberty-dev
|
- libiberty-dev
|
||||||
stages:
|
stages:
|
||||||
- build
|
- build
|
||||||
- code coverage
|
- test and coverage
|
||||||
jobs:
|
jobs:
|
||||||
include:
|
include:
|
||||||
- stage: build
|
- stage: build
|
||||||
@ -34,21 +35,22 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
- MIGRATION_DIR=migrations/sqlite FEATURES=sqlite DATABASE_URL=plume.sqlite3
|
- MIGRATION_DIR=migrations/sqlite FEATURES=sqlite DATABASE_URL=plume.sqlite3
|
||||||
script: cargo build --no-default-features --features="${FEATURES}"
|
script: cargo build --no-default-features --features="${FEATURES}"
|
||||||
- stage: code coverage
|
- stage: test and coverage
|
||||||
name: "Calculate code coverage"
|
name: "Test with potgresql backend"
|
||||||
env:
|
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'
|
- RUSTFLAGS='-C link-dead-code'
|
||||||
script:
|
script:
|
||||||
- |
|
- |
|
||||||
cargo test --features sqlite --no-default-features --all && (
|
cargo test --features "${FEATURES}" --no-default-features --all &&
|
||||||
wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz &&
|
./script/compute_coverage.sh
|
||||||
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 )
|
|
||||||
|
@ -5,15 +5,20 @@ extern crate plume_models;
|
|||||||
|
|
||||||
use diesel::Connection;
|
use diesel::Connection;
|
||||||
use plume_models::{
|
use plume_models::{
|
||||||
|
DATABASE_URL,
|
||||||
Connection as Conn,
|
Connection as Conn,
|
||||||
instance::*,
|
instance::*,
|
||||||
safe_string::SafeString,
|
safe_string::SafeString,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[cfg(feature = "sqlite")]
|
||||||
embed_migrations!("../migrations/sqlite");
|
embed_migrations!("../migrations/sqlite");
|
||||||
|
|
||||||
|
#[cfg(feature = "postgres")]
|
||||||
|
embed_migrations!("../migrations/postgres");
|
||||||
|
|
||||||
fn db() -> Conn {
|
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");
|
embedded_migrations::run(&conn).expect("Couldn't run migrations");
|
||||||
conn
|
conn
|
||||||
}
|
}
|
||||||
@ -21,6 +26,7 @@ fn db() -> Conn {
|
|||||||
#[test]
|
#[test]
|
||||||
fn instance_insert() {
|
fn instance_insert() {
|
||||||
let conn = &db();
|
let conn = &db();
|
||||||
|
conn.test_transaction::<_, (), _>(|| {
|
||||||
Instance::insert(conn, NewInstance {
|
Instance::insert(conn, NewInstance {
|
||||||
default_license: "WTFPL".to_string(),
|
default_license: "WTFPL".to_string(),
|
||||||
local: true,
|
local: true,
|
||||||
@ -36,4 +42,6 @@ fn instance_insert() {
|
|||||||
assert!(inst.is_some());
|
assert!(inst.is_some());
|
||||||
let inst = inst.unwrap();
|
let inst = inst.unwrap();
|
||||||
assert_eq!(inst.name, "My instance".to_string());
|
assert_eq!(inst.name, "My instance".to_string());
|
||||||
|
Ok(())
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
19
script/compute_coverage.sh
Executable file
19
script/compute_coverage.sh
Executable 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"
|
Loading…
Reference in New Issue
Block a user