Skip to content

Commit

Permalink
Cargo update & adapt tests to diesel's mut connection requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
Ten0 committed Jul 8, 2021
1 parent 499f5d4 commit f321179
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 80 deletions.
66 changes: 34 additions & 32 deletions tests/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions tests/src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub struct Simple {
pub fn get_connection() -> PgConnection {
let database_url =
::std::env::var("PG_TEST_DATABASE_URL").expect("Env var PG_TEST_DATABASE_URL not set");
let conn = PgConnection::establish(&database_url)
let mut conn = PgConnection::establish(&database_url)
.expect(&format!("Failed to connect to {}", database_url));
conn.execute("SET search_path TO pg_temp;").unwrap();
conn
Expand Down Expand Up @@ -91,7 +91,7 @@ pub fn sample_data() -> Vec<Simple> {
}

#[cfg(feature = "postgres")]
pub fn create_table(conn: &PgConnection) {
pub fn create_table(conn: &mut PgConnection) {
use diesel::connection::SimpleConnection;
conn.batch_execute(
r#"
Expand All @@ -106,7 +106,7 @@ pub fn create_table(conn: &PgConnection) {
}

#[cfg(feature = "mysql")]
pub fn create_table(conn: &MysqlConnection) {
pub fn create_table(conn: &mut MysqlConnection) {
use diesel::connection::SimpleConnection;
conn.batch_execute(
r#"
Expand All @@ -120,7 +120,7 @@ pub fn create_table(conn: &MysqlConnection) {
}

#[cfg(feature = "sqlite")]
pub fn create_table(conn: &SqliteConnection) {
pub fn create_table(conn: &mut SqliteConnection) {
conn.execute(
r#"
CREATE TABLE test_simple (
Expand Down
12 changes: 6 additions & 6 deletions tests/src/complex_join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct Server {
}

#[cfg(feature = "postgres")]
pub fn create_table(conn: &PgConnection) {
pub fn create_table(conn: &mut PgConnection) {
use diesel::connection::SimpleConnection;
conn.batch_execute(
r#"
Expand All @@ -80,8 +80,8 @@ pub fn create_table(conn: &PgConnection) {
#[test]
#[cfg(feature = "postgres")]
fn test_complex_join() {
let conn = get_connection();
create_table(&conn);
let conn = &mut get_connection();
create_table(conn);
let some_users = vec![User { id: 1 }, User { id: 2 }];
let some_servers = vec![
Server {
Expand All @@ -102,11 +102,11 @@ fn test_complex_join() {
];
diesel::insert_into(users::table)
.values(&some_users)
.execute(&conn)
.execute(conn)
.unwrap();
diesel::insert_into(servers::table)
.values(&some_servers)
.execute(&conn)
.execute(conn)
.unwrap();
let (user, server) = users::table
.find(1)
Expand All @@ -115,7 +115,7 @@ fn test_complex_join() {
.eq(users::dsl::id)
.and(servers::dsl::status.eq(ServerStatus::Started))),
)
.first::<(User, Option<Server>)>(&conn)
.first::<(User, Option<Server>)>(conn)
.unwrap();
assert_eq!(user, User { id: 1 });
assert_eq!(
Expand Down
20 changes: 10 additions & 10 deletions tests/src/nullable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct MaybeNullable {
}

#[cfg(feature = "postgres")]
pub fn create_null_table(conn: &PgConnection) {
pub fn create_null_table(conn: &mut PgConnection) {
use diesel::connection::SimpleConnection;
conn.batch_execute(
r#"
Expand All @@ -53,7 +53,7 @@ pub fn create_null_table(conn: &PgConnection) {
}

#[cfg(feature = "mysql")]
pub fn create_null_table(conn: &MysqlConnection) {
pub fn create_null_table(conn: &mut MysqlConnection) {
use diesel::connection::SimpleConnection;
conn.batch_execute(
r#"
Expand All @@ -67,7 +67,7 @@ pub fn create_null_table(conn: &MysqlConnection) {
}

#[cfg(feature = "sqlite")]
pub fn create_null_table(conn: &SqliteConnection) {
pub fn create_null_table(conn: &mut SqliteConnection) {
conn.execute(
r#"
CREATE TABLE test_nullable (
Expand All @@ -81,8 +81,8 @@ pub fn create_null_table(conn: &SqliteConnection) {

#[test]
fn nullable_enum_round_trip() {
let connection = get_connection();
create_null_table(&connection);
let connection = &mut get_connection();
create_null_table(connection);
let data = vec![
Nullable {
id: 1,
Expand All @@ -94,16 +94,16 @@ fn nullable_enum_round_trip() {
},
];
let sql = insert_into(test_nullable::table).values(&data);
let ct = sql.execute(&connection).unwrap();
let ct = sql.execute(connection).unwrap();
assert_eq!(data.len(), ct);
let items = test_nullable::table.load::<Nullable>(&connection).unwrap();
let items = test_nullable::table.load::<Nullable>(connection).unwrap();
assert_eq!(data, items);
}

#[test]
fn not_nullable_enum_round_trip() {
let connection = get_connection();
create_null_table(&connection);
let connection = &mut get_connection();
create_null_table(connection);
let data = vec![
MaybeNullable {
id: 1,
Expand All @@ -116,7 +116,7 @@ fn not_nullable_enum_round_trip() {
];
let ct = insert_into(test_nullable::table)
.values(&data)
.execute(&connection)
.execute(connection)
.unwrap();
assert_eq!(data.len(), ct);
}
10 changes: 5 additions & 5 deletions tests/src/pg_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use diesel::prelude::*;

use crate::common::*;

pub fn create_table(conn: &PgConnection) {
pub fn create_table(conn: &mut PgConnection) {
use diesel::connection::SimpleConnection;
conn.batch_execute(
r#"
Expand All @@ -19,21 +19,21 @@ pub fn create_table(conn: &PgConnection) {

#[test]
fn enum_query() {
let connection = get_connection();
create_table(&connection);
let connection = &mut get_connection();
create_table(connection);
let data_item = TestArray {
id: 1,
my_enum_arr: vec![MyEnum::Foo],
};
let data = vec![data_item];
let ct = insert_into(test_array::table)
.values(&data)
.execute(&connection)
.execute(connection)
.unwrap();
assert_eq!(data.len(), ct);
let item = test_array::table
.find(1)
.get_results::<TestArray>(&connection)
.get_results::<TestArray>(connection)
.unwrap();
assert_eq!(data, item);
}
Expand Down
Loading

0 comments on commit f321179

Please sign in to comment.