rust-postgres/src/postgres/test.rs

29 lines
732 B
Rust
Raw Normal View History

2013-07-25 07:10:18 +00:00
extern mod postgres;
2013-08-04 02:17:32 +00:00
use postgres::{PostgresConnection, PostgresRow};
macro_rules! chk(
($e:expr) => (
match $e {
Ok(ok) => ok,
Err(err) => fail!(err)
}
)
)
2013-07-25 07:10:18 +00:00
#[test]
fn test_conn() {
2013-08-04 02:17:32 +00:00
let conn = chk!(PostgresConnection::new("postgres://postgres@localhost"));
chk!(conn.update("DROP TABLE IF EXISTS foo"));
chk!(conn.update("CREATE TABLE foo (foo INT PRIMARY KEY)"));
chk!(conn.update("INSERT INTO foo (foo) VALUES (101)"));
let res = chk!(conn.query("SELECT foo from foo"));
assert_eq!(1, res.len());
let rows: ~[PostgresRow] = res.iter().collect();
assert_eq!(1, rows.len());
assert_eq!(1, rows[0].len());
assert_eq!(Some(101), rows[0][0]);
2013-07-25 07:10:18 +00:00
}