Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ jobs:
components: clippy
override: true
- name: Lint default
run: cargo clippy --features pg-type-postgis -- -D warnings
run: cargo clippy --all-targets --features pg-type-postgis -- -D warnings
- name: Lint minimal
run: cargo clippy --no-default-features -- -D warnings
run: cargo clippy --all-targets --no-default-features -- -D warnings
- name: Lint server-api without tls
run: cargo clippy --no-default-features --features server-api -- -D warnings
run: cargo clippy --all-targets --no-default-features --features server-api -- -D warnings
- name: Lint ring
run: cargo clippy --no-default-features --features server-api-ring -- -D warnings
run: cargo clippy --all-targets --no-default-features --features server-api-ring -- -D warnings
- name: Lint client api
run: cargo clippy --features client-api-aws-lc-rs -- -D warnings
run: cargo clippy --all-targets --features client-api-aws-lc-rs -- -D warnings

test:
name: Test
Expand Down
2 changes: 1 addition & 1 deletion examples/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub async fn main() {

let server_addr = std::env::var("PGWIRE_BENCH_ADDR").unwrap_or(String::from("127.0.0.1:5433"));
let listener = TcpListener::bind(&server_addr).await.unwrap();
println!("Listening to {}", &server_addr);
println!("Listening to {}", server_addr);
loop {
let incoming_socket = listener.accept().await.unwrap();
let factory_ref = factory.clone();
Expand Down
42 changes: 28 additions & 14 deletions src/types/format/date_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,10 @@ mod tests {
let datetime: DateTime<Utc> = Utc.from_utc_datetime(&dt);

let mut out = BytesMut::new();
let mut format_option = FormatOptions::default();
format_option.date_style = "ISO".to_string();
let format_option = FormatOptions {
date_style: "ISO".to_string(),
..Default::default()
};

datetime
.to_sql_text(&Type::TIMESTAMP, &mut out, &format_option)
Expand Down Expand Up @@ -347,8 +349,10 @@ mod tests {
.unwrap();

let mut out = BytesMut::new();
let mut format_options = FormatOptions::default();
format_options.date_style = "SQL, DMY".to_string();
let format_options = FormatOptions {
date_style: "SQL, DMY".to_string(),
..Default::default()
};

dt.to_sql_text(&Type::TIMESTAMP, &mut out, &format_options)
.unwrap();
Expand Down Expand Up @@ -387,8 +391,10 @@ mod tests {

let system_time = UNIX_EPOCH + Duration::from_secs(1703514645); // 2023-12-25 14:30:45 UTC
let mut out = BytesMut::new();
let mut format_options = FormatOptions::default();
format_options.date_style = "german".to_string();
let format_options = FormatOptions {
date_style: "german".to_string(),
..Default::default()
};

system_time
.to_sql_text(&Type::TIMESTAMP, &mut out, &format_options)
Expand All @@ -406,8 +412,10 @@ mod tests {

let date = NaiveDate::from_ymd_opt(2023, 12, 25).unwrap();
let mut out = BytesMut::new();
let mut format_options = FormatOptions::default();
format_options.date_style = "postgres, DMY".to_string();
let format_options = FormatOptions {
date_style: "postgres, DMY".to_string(),
..Default::default()
};

date.to_sql_text(&Type::DATE, &mut out, &format_options)
.unwrap();
Expand All @@ -424,8 +432,10 @@ mod tests {
.and_hms_opt(14, 30, 45)
.unwrap();
let mut out = BytesMut::new();
let mut format_options = FormatOptions::default();
format_options.date_style = "ISO".to_string();
let format_options = FormatOptions {
date_style: "ISO".to_string(),
..Default::default()
};

let result = dt.to_sql_text(&Type::BOOL, &mut out, &format_options);
assert!(result.is_err());
Expand All @@ -441,8 +451,10 @@ mod tests {
.and_hms_micro_opt(14, 30, 45, 123456)
.unwrap();
let mut out = BytesMut::new();
let mut format_options = FormatOptions::default();
format_options.date_style = "postgres".to_string();
let format_options = FormatOptions {
date_style: "postgres".to_string(),
..Default::default()
};

dt.to_sql_text(&Type::TIMESTAMP, &mut out, &format_options)
.unwrap();
Expand All @@ -460,8 +472,10 @@ mod tests {
.and_hms_micro_opt(7, 37, 16, 123000)
.unwrap();
let mut out = BytesMut::new();
let mut format_options = FormatOptions::default();
format_options.date_style = "postgres, DMY".to_string();
let format_options = FormatOptions {
date_style: "postgres, DMY".to_string(),
..Default::default()
};

dt.to_sql_text(&Type::TIMESTAMP, &mut out, &format_options)
.unwrap();
Expand Down
6 changes: 4 additions & 2 deletions src/types/format/interval_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,10 @@ mod tests {

let duration = Duration::seconds(86400 + 7200 + 120 + 2); // 1 day, 2 hours, 2 minutes, 2 seconds
let mut out = BytesMut::new();
let mut format_options = FormatOptions::default();
format_options.interval_style = "postgres_verbose".to_string();
let format_options = FormatOptions {
interval_style: "postgres_verbose".to_string(),
..Default::default()
};

duration
.to_sql_text(&Type::INTERVAL, &mut out, &format_options)
Expand Down
3 changes: 3 additions & 0 deletions src/types/from_sql_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ mod tests {
#[cfg(feature = "pg-type-chrono")]
use chrono::TimeZone;

#[cfg(feature = "pg-type-chrono")]
macro_rules! test_parse_naive_date {
($sql_text:expr, $expected:expr) => {
let result =
Expand All @@ -595,6 +596,7 @@ mod tests {
};
}

#[cfg(feature = "pg-type-chrono")]
macro_rules! test_parse_naive_datetime {
($sql_text:expr, $expected:expr) => {
let result = NaiveDateTime::from_sql_text(
Expand All @@ -607,6 +609,7 @@ mod tests {
};
}

#[cfg(feature = "pg-type-chrono")]
macro_rules! test_parse_datetime_fixed_offset {
($sql_text:expr, $expected:expr) => {
let result = DateTime::<FixedOffset>::from_sql_text(
Expand Down
34 changes: 22 additions & 12 deletions src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ mod roundtrip_tests {
fn test_roundtrip_floats() {
test_roundtrip_float!(f32, 0.0, &Type::FLOAT4);
test_roundtrip_float!(f32, 1.5, &Type::FLOAT4);
test_roundtrip_float!(f32, -3.14, &Type::FLOAT4);
test_roundtrip_float!(f32, -3.15, &Type::FLOAT4);

test_roundtrip_float!(f64, 0.0, &Type::FLOAT8);
test_roundtrip_float!(f64, 1.5, &Type::FLOAT8);
test_roundtrip_float!(f64, -3.14159265359, &Type::FLOAT8);
test_roundtrip_float!(f64, -3.15159265359, &Type::FLOAT8);
}

#[test]
Expand Down Expand Up @@ -526,8 +526,10 @@ mod roundtrip_tests {
fn test_roundtrip_interval_iso8601_style() {
use pg_interval::Interval;

let mut format_options = FormatOptions::default();
format_options.interval_style = "iso_8601".to_string();
let format_options = FormatOptions {
interval_style: "iso_8601".to_string(),
..Default::default()
};

// Test simple time interval
let interval1 = Interval::new(0, 0, 3661000000i64);
Expand Down Expand Up @@ -589,8 +591,10 @@ mod roundtrip_tests {
fn test_roundtrip_interval_postgres_verbose_style() {
use pg_interval::Interval;

let mut format_options = FormatOptions::default();
format_options.interval_style = "postgres_verbose".to_string();
let format_options = FormatOptions {
interval_style: "postgres_verbose".to_string(),
..Default::default()
};

// Test interval with months
let interval1 = Interval::new(6, 0, 0);
Expand Down Expand Up @@ -710,8 +714,10 @@ mod roundtrip_tests {
fn test_roundtrip_interval_negative_values_iso8601() {
use pg_interval::Interval;

let mut format_options = FormatOptions::default();
format_options.interval_style = "iso_8601".to_string();
let format_options = FormatOptions {
interval_style: "iso_8601".to_string(),
..Default::default()
};

let interval1 = Interval::new(-6, 0, 0);
let mut buf = BytesMut::new();
Expand All @@ -738,8 +744,10 @@ mod roundtrip_tests {
fn test_roundtrip_interval_negative_values_postgres_verbose() {
use pg_interval::Interval;

let mut format_options = FormatOptions::default();
format_options.interval_style = "postgres_verbose".to_string();
let format_options = FormatOptions {
interval_style: "postgres_verbose".to_string(),
..Default::default()
};

let interval1 = Interval::new(-6, 0, 0);
let mut buf = BytesMut::new();
Expand Down Expand Up @@ -768,10 +776,12 @@ mod roundtrip_tests {

let interval = Interval::new(12, 15, 1296060000000i64);

let mut format_options = FormatOptions::default();
let mut format_options = FormatOptions {
interval_style: "postgres".to_string(),
..Default::default()
};

// Test postgres encoding
format_options.interval_style = "postgres".to_string();
let mut buf = BytesMut::new();
interval
.to_sql_text(&Type::INTERVAL, &mut buf, &format_options)
Expand Down
2 changes: 1 addition & 1 deletion tests-integration/client-api/tests/cancel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ async fn cancel_request_message_cancels_from_another_connection() {
send_cancel_request(pid, secret_key).await;

let result = query.await.expect("query task panicked");
match result.err().expect("query should have been cancelled") {
match result.expect_err("query should have been cancelled") {
pgwire::error::PgWireClientError::RemoteError(info) => {
assert_eq!(info.code, QUERY_CANCELED);
}
Expand Down
4 changes: 1 addition & 3 deletions tests-integration/client-api/tests/extended_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,7 @@ async fn server_error_is_reported_and_connection_recovers() {
let error = eqc
.prepare(Some("st_broken"), "SELEC 1", &[])
.await
.err()
.expect("preparing a syntax error must fail");
.expect_err("preparing a syntax error must fail");

match error {
PgWireClientError::RemoteError(info) => {
Expand Down Expand Up @@ -358,7 +357,6 @@ async fn parameter_status_during_extended_query_updates_cache() {
.await
.expect("SET via extended query failed");

drop(eqc);
assert_eq!(
client.server_parameters().get("application_name"),
Some(&"eq-renamed".to_owned())
Expand Down
3 changes: 1 addition & 2 deletions tests-integration/client-api/tests/simple_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ async fn server_error_is_reported_and_connection_recovers() {
"SELECT * FROM pgwire_itest_no_such_table",
)
.await
.err()
.expect("querying a missing table must fail");
.expect_err("querying a missing table must fail");

match error {
PgWireClientError::RemoteError(info) => {
Expand Down
5 changes: 4 additions & 1 deletion tests-integration/test-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,10 @@ impl ExtendedQueryHandler for DummyDatabase {
// JDBC doesn't provide type information for some cases,
// we try to parse them as TIMESTAMP or DATE accordingly

if let Err(_) = portal.parameter::<NaiveDateTime>(idx, &Type::TIMESTAMP) {
if portal
.parameter::<NaiveDateTime>(idx, &Type::TIMESTAMP)
.is_err()
{
let _ = portal.parameter::<NaiveDate>(idx, &Type::DATE);
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/short_message_length_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn other_frontend_and_backend_messages_reject_short_lengths() {
ctx.awaiting_frontend_startup = false;

for length in [0, 1, 2, 3] {
for message_type in [b'B', b'P', b'Q', b'd'] {
for &message_type in b"BPQd" {
let mut packet = BytesMut::new();
packet.put_u8(message_type);
packet.put_i32(length);
Expand All @@ -51,7 +51,7 @@ fn other_frontend_and_backend_messages_reject_short_lengths() {
Err(PgWireError::InvalidMessageLength(actual)) if actual == length as usize
));
}
for message_type in [b'D', b'G', b'R'] {
for &message_type in b"DGR" {
let mut packet = BytesMut::new();
packet.put_u8(message_type);
packet.put_i32(length);
Expand Down
Loading