Skip to content

Commit 039d02e

Browse files
committed
Fix tests on Travis
1 parent db2d81d commit 039d02e

5 files changed

Lines changed: 40 additions & 6 deletions

File tree

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ before_install:
33
- sudo apt-get update
44
install:
55
- sudo apt-get install rust-nightly
6+
before_script:
7+
- ./travis/setup.sh
68
script:
79
- rustc --lib --out-dir . src/postgres/lib.rs
8-
- rustc --test --out-dir . -L. src/postgres/test.rs
10+
- rustc --test --out-dir . -L. --cfg travis src/postgres/test.rs
911
- ./test
1012
# - rustpkg test postgres

src/postgres/test.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ fn test_bytea_params() {
283283
}
284284
285285
#[test]
286+
#[cfg(not(travis))] // Travis runs Postgres 9.1
286287
fn test_json_params() {
287288
test_type("JSON", [(Some(json::from_str("[10, 11, 12]").unwrap()),
288289
"'[10, 11, 12]'"),
@@ -418,7 +419,8 @@ fn test_plaintext_pass_no_pass() {
418419
let ret = PostgresConnection::try_connect("postgres://pass_user@localhost");
419420
match ret {
420421
Err(MissingPassword) => (),
421-
ret => fail!("Unexpected result %?", ret)
422+
Err(err) => fail2!("Unexpected error {}", err.to_str()),
423+
_ => fail2!("Expected error")
422424
}
423425
}
424426

@@ -427,7 +429,8 @@ fn test_plaintext_pass_wrong_pass() {
427429
let ret = PostgresConnection::try_connect("postgres://pass_user:asdf@localhost");
428430
match ret {
429431
Err(DbError(PostgresDbError { code: InvalidPassword, _ })) => (),
430-
ret => fail!("Unexpected result %?", ret)
432+
Err(err) => fail2!("Unexpected error {}", err.to_str()),
433+
_ => fail2!("Expected error")
431434
}
432435
}
433436

@@ -441,7 +444,8 @@ fn test_md5_pass_no_pass() {
441444
let ret = PostgresConnection::try_connect("postgres://md5_user@localhost");
442445
match ret {
443446
Err(MissingPassword) => (),
444-
ret => fail!("Unexpected result %?", ret)
447+
Err(err) => fail2!("Unexpected error {}", err.to_str()),
448+
_ => fail2!("Expected error")
445449
}
446450
}
447451

@@ -450,7 +454,8 @@ fn test_md5_pass_wrong_pass() {
450454
let ret = PostgresConnection::try_connect("postgres://md5_user:asdf@localhost");
451455
match ret {
452456
Err(DbError(PostgresDbError { code: InvalidPassword, _ })) => (),
453-
ret => fail!("Unexpected result %?", ret)
457+
Err(err) => fail2!("Unexpected error {}", err.to_str()),
458+
_ => fail2!("Expected error")
454459
}
455460
}
456461

@@ -459,6 +464,7 @@ fn test_dns_failure() {
459464
let ret = PostgresConnection::try_connect("postgres://postgres@asdfasdfasdf");
460465
match ret {
461466
Err(DnsError) => (),
462-
ret => fail!("Unexpected result %?", ret)
467+
Err(err) => fail2!("Unexpected error {}", err.to_str()),
468+
_ => fail2!("Expected error")
463469
}
464470
}

travis/pg_hba.conf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# TYPE DATABASE USER ADDRESS METHOD
2+
host all pass_user 127.0.0.1/32 password
3+
host all md5_user 127.0.0.1/32 md5
4+
host all pass_user ::1/128 password
5+
host all md5_user ::1/128 md5
6+
7+
# IPv4 local connections:
8+
host all postgres 127.0.0.1/32 trust
9+
# IPv6 local connections:
10+
host all postgres ::1/128 trust

travis/setup.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
set -ev
3+
4+
cd "$(dirname "$0")"
5+
6+
psql -U postgres < setup.sql
7+
8+
sudo cp pg_hba.conf $(psql -U postgres -c "SHOW hba_file" -At)
9+
10+
DATA_DIR=$(psql -U postgres -c "SHOW data_directory" -At)
11+
PG_PID=$(sudo head -n1 $DATA_DIR/postmaster.pid)
12+
sudo kill -SIGHUP $PG_PID

travis/setup.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CREATE ROLE pass_user PASSWORD 'password' LOGIN;
2+
CREATE ROLE md5_user PASSWORD 'password' LOGIN;
3+
CREATE DATABASE pass_user OWNER pass_user;
4+
CREATE DATABASE md5_user OWNER md5_user;

0 commit comments

Comments
 (0)