Fix tests
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use bytes::BytesMut;
|
||||
use fallible_iterator::FallibleIterator;
|
||||
use std::collections::HashMap;
|
||||
|
||||
@@ -6,32 +7,32 @@ use crate::IsNull;
|
||||
|
||||
#[test]
|
||||
fn bool() {
|
||||
let mut buf = vec![];
|
||||
let mut buf = BytesMut::new();
|
||||
bool_to_sql(true, &mut buf);
|
||||
assert_eq!(bool_from_sql(&buf).unwrap(), true);
|
||||
|
||||
let mut buf = vec![];
|
||||
let mut buf = BytesMut::new();
|
||||
bool_to_sql(false, &mut buf);
|
||||
assert_eq!(bool_from_sql(&buf).unwrap(), false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn int2() {
|
||||
let mut buf = vec![];
|
||||
let mut buf = BytesMut::new();
|
||||
int2_to_sql(0x0102, &mut buf);
|
||||
assert_eq!(int2_from_sql(&buf).unwrap(), 0x0102);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn int4() {
|
||||
let mut buf = vec![];
|
||||
let mut buf = BytesMut::new();
|
||||
int4_to_sql(0x0102_0304, &mut buf);
|
||||
assert_eq!(int4_from_sql(&buf).unwrap(), 0x0102_0304);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn int8() {
|
||||
let mut buf = vec![];
|
||||
let mut buf = BytesMut::new();
|
||||
int8_to_sql(0x0102_0304_0506_0708, &mut buf);
|
||||
assert_eq!(int8_from_sql(&buf).unwrap(), 0x0102_0304_0506_0708);
|
||||
}
|
||||
@@ -39,7 +40,7 @@ fn int8() {
|
||||
#[test]
|
||||
#[allow(clippy::float_cmp)]
|
||||
fn float4() {
|
||||
let mut buf = vec![];
|
||||
let mut buf = BytesMut::new();
|
||||
float4_to_sql(10343.95, &mut buf);
|
||||
assert_eq!(float4_from_sql(&buf).unwrap(), 10343.95);
|
||||
}
|
||||
@@ -47,7 +48,7 @@ fn float4() {
|
||||
#[test]
|
||||
#[allow(clippy::float_cmp)]
|
||||
fn float8() {
|
||||
let mut buf = vec![];
|
||||
let mut buf = BytesMut::new();
|
||||
float8_to_sql(10343.95, &mut buf);
|
||||
assert_eq!(float8_from_sql(&buf).unwrap(), 10343.95);
|
||||
}
|
||||
@@ -58,7 +59,7 @@ fn hstore() {
|
||||
map.insert("hello", Some("world"));
|
||||
map.insert("hola", None);
|
||||
|
||||
let mut buf = vec![];
|
||||
let mut buf = BytesMut::new();
|
||||
hstore_to_sql(map.iter().map(|(&k, &v)| (k, v)), &mut buf).unwrap();
|
||||
assert_eq!(
|
||||
hstore_from_sql(&buf)
|
||||
@@ -74,7 +75,7 @@ fn varbit() {
|
||||
let len = 12;
|
||||
let bits = [0b0010_1011, 0b0000_1111];
|
||||
|
||||
let mut buf = vec![];
|
||||
let mut buf = BytesMut::new();
|
||||
varbit_to_sql(len, bits.iter().cloned(), &mut buf).unwrap();
|
||||
let out = varbit_from_sql(&buf).unwrap();
|
||||
assert_eq!(out.len(), len);
|
||||
@@ -95,7 +96,7 @@ fn array() {
|
||||
];
|
||||
let values = [None, Some(&b"hello"[..])];
|
||||
|
||||
let mut buf = vec![];
|
||||
let mut buf = BytesMut::new();
|
||||
array_to_sql(
|
||||
dimensions.iter().cloned(),
|
||||
10,
|
||||
@@ -132,7 +133,7 @@ fn non_null_array() {
|
||||
];
|
||||
let values = [Some(&b"hola"[..]), Some(&b"hello"[..])];
|
||||
|
||||
let mut buf = vec![];
|
||||
let mut buf = BytesMut::new();
|
||||
array_to_sql(
|
||||
dimensions.iter().cloned(),
|
||||
10,
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use crate::config::SslMode;
|
||||
use crate::tls::TlsConnect;
|
||||
use crate::{connect_tls, Error};
|
||||
use bytes::BytesMut;
|
||||
use postgres_protocol::message::frontend;
|
||||
use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt};
|
||||
use bytes::BytesMut;
|
||||
|
||||
pub async fn cancel_query_raw<S, T>(
|
||||
stream: S,
|
||||
|
||||
@@ -18,7 +18,7 @@ use crate::{cancel_query_raw, copy_in, copy_out, query, Transaction};
|
||||
use crate::{prepare, SimpleQueryMessage};
|
||||
use crate::{simple_query, Row};
|
||||
use crate::{Error, Statement};
|
||||
use bytes::{IntoBuf, BytesMut};
|
||||
use bytes::{BytesMut, IntoBuf};
|
||||
use fallible_iterator::FallibleIterator;
|
||||
use futures::channel::mpsc;
|
||||
use futures::{future, TryStream, TryStreamExt};
|
||||
@@ -118,7 +118,10 @@ impl InnerClient {
|
||||
self.state.lock().types.insert(oid, type_.clone());
|
||||
}
|
||||
|
||||
pub fn with_buf<F, R>(&self, f: F) -> R where F: FnOnce(&mut BytesMut) -> R {
|
||||
pub fn with_buf<F, R>(&self, f: F) -> R
|
||||
where
|
||||
F: FnOnce(&mut BytesMut) -> R,
|
||||
{
|
||||
let mut state = self.state.lock();
|
||||
let r = f(&mut state.buf);
|
||||
state.buf.clear();
|
||||
|
||||
@@ -4,6 +4,7 @@ use crate::connect_tls::connect_tls;
|
||||
use crate::maybe_tls_stream::MaybeTlsStream;
|
||||
use crate::tls::{ChannelBinding, TlsConnect};
|
||||
use crate::{Client, Connection, Error};
|
||||
use bytes::BytesMut;
|
||||
use fallible_iterator::FallibleIterator;
|
||||
use futures::channel::mpsc;
|
||||
use futures::{ready, Sink, SinkExt, Stream, TryStreamExt};
|
||||
@@ -18,7 +19,6 @@ use std::pin::Pin;
|
||||
use std::task::{Context, Poll};
|
||||
use tokio::codec::Framed;
|
||||
use tokio::io::{AsyncRead, AsyncWrite};
|
||||
use bytes::BytesMut;
|
||||
|
||||
pub struct StartupStream<S, T> {
|
||||
inner: Framed<MaybeTlsStream<S, T>, PostgresCodec>,
|
||||
|
||||
@@ -3,9 +3,9 @@ use crate::maybe_tls_stream::MaybeTlsStream;
|
||||
use crate::tls::private::ForcePrivateApi;
|
||||
use crate::tls::{ChannelBinding, TlsConnect};
|
||||
use crate::Error;
|
||||
use bytes::BytesMut;
|
||||
use postgres_protocol::message::frontend;
|
||||
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
|
||||
use bytes::BytesMut;
|
||||
|
||||
pub async fn connect_tls<S, T>(
|
||||
mut stream: S,
|
||||
|
||||
@@ -5,6 +5,7 @@ use crate::error::SqlState;
|
||||
use crate::types::{Field, Kind, Oid, Type};
|
||||
use crate::{query, slice_iter};
|
||||
use crate::{Column, Error, Statement};
|
||||
use bytes::Bytes;
|
||||
use fallible_iterator::FallibleIterator;
|
||||
use futures::TryStreamExt;
|
||||
use pin_utils::pin_mut;
|
||||
@@ -14,7 +15,6 @@ use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::sync::Arc;
|
||||
use bytes::Bytes;
|
||||
|
||||
const TYPEINFO_QUERY: &str = "\
|
||||
SELECT t.typname, t.typtype, t.typelem, r.rngsubtype, t.typbasetype, n.nspname, t.typrelid
|
||||
|
||||
@@ -3,12 +3,12 @@ use crate::codec::FrontendMessage;
|
||||
use crate::connection::RequestMessages;
|
||||
use crate::types::{IsNull, ToSql};
|
||||
use crate::{Error, Portal, Row, Statement};
|
||||
use bytes::{Bytes, BytesMut};
|
||||
use futures::{ready, Stream};
|
||||
use postgres_protocol::message::backend::Message;
|
||||
use postgres_protocol::message::frontend;
|
||||
use std::pin::Pin;
|
||||
use std::task::{Context, Poll};
|
||||
use bytes::{Bytes, BytesMut};
|
||||
|
||||
pub async fn query<'a, I>(
|
||||
client: &InnerClient,
|
||||
@@ -102,7 +102,12 @@ where
|
||||
})
|
||||
}
|
||||
|
||||
pub fn encode_bind<'a, I>(statement: &Statement, params: I, portal: &str, buf: &mut BytesMut) -> Result<(), Error>
|
||||
pub fn encode_bind<'a, I>(
|
||||
statement: &Statement,
|
||||
params: I,
|
||||
portal: &str,
|
||||
buf: &mut BytesMut,
|
||||
) -> Result<(), Error>
|
||||
where
|
||||
I: IntoIterator<Item = &'a dyn ToSql>,
|
||||
I::IntoIter: ExactSizeIterator,
|
||||
|
||||
@@ -2,6 +2,7 @@ use crate::client::{InnerClient, Responses};
|
||||
use crate::codec::FrontendMessage;
|
||||
use crate::connection::RequestMessages;
|
||||
use crate::{Error, SimpleQueryMessage, SimpleQueryRow};
|
||||
use bytes::Bytes;
|
||||
use fallible_iterator::FallibleIterator;
|
||||
use futures::{ready, Stream};
|
||||
use postgres_protocol::message::backend::Message;
|
||||
@@ -9,7 +10,6 @@ use postgres_protocol::message::frontend;
|
||||
use std::pin::Pin;
|
||||
use std::sync::Arc;
|
||||
use std::task::{Context, Poll};
|
||||
use bytes::Bytes;
|
||||
|
||||
pub async fn simple_query(client: &InnerClient, query: &str) -> Result<SimpleQueryStream, Error> {
|
||||
let buf = encode(client, query)?;
|
||||
|
||||
@@ -14,9 +14,9 @@ use crate::{
|
||||
use bytes::IntoBuf;
|
||||
use futures::{TryStream, TryStreamExt};
|
||||
use postgres_protocol::message::frontend;
|
||||
use postgres_types::private::BytesMut;
|
||||
use std::error;
|
||||
use tokio::io::{AsyncRead, AsyncWrite};
|
||||
use postgres_types::private::BytesMut;
|
||||
|
||||
/// A representation of a PostgreSQL database transaction.
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user