mirror of
https://github.com/launchbadge/sqlx.git
synced 2026-02-15 04:09:37 +00:00
fix tests and ensure all types are being tested in CI
This commit is contained in:
parent
2f6bab396a
commit
8454fa4e96
12
.github/workflows/rust.yml
vendored
12
.github/workflows/rust.yml
vendored
@ -39,25 +39,25 @@ jobs:
|
||||
|
||||
# check w/deny warnings in sqlx-core: async-std
|
||||
- working-directory: sqlx-core
|
||||
run: cargo rustc --no-default-features --features 'bigdecimal ipnetwork chrono time uuid postgres mysql tls runtime-async-std' -- -D warnings --emit=metadata
|
||||
run: cargo rustc --no-default-features --features 'all-type postgres mysql tls runtime-async-std' -- -D warnings --emit=metadata
|
||||
|
||||
# check w/deny warnings in sqlx-core: tokio
|
||||
# `cargo rustc -p sqlx-core` ignores `--no-default-features` and builds with `runtime-async-std` anyway
|
||||
# https://github.com/rust-lang/cargo/issues/5364
|
||||
- working-directory: sqlx-core
|
||||
run: cargo rustc --no-default-features --features 'bigdecimal ipnetwork chrono time uuid postgres mysql tls runtime-tokio' -- -D warnings --emit=metadata
|
||||
run: cargo rustc --no-default-features --features 'all-type postgres mysql tls runtime-tokio' -- -D warnings --emit=metadata
|
||||
|
||||
# check w/deny warnings: async-std
|
||||
- run: cargo rustc --no-default-features --features 'bigdecimal ipnetwork chrono time uuid postgres mysql macros tls runtime-async-std' -- -D warnings --emit=metadata
|
||||
- run: cargo rustc --no-default-features --features 'all-type postgres mysql macros tls runtime-async-std' -- -D warnings --emit=metadata
|
||||
|
||||
# check w/deny warnings: tokio
|
||||
- run: cargo rustc --no-default-features --features 'bigdecimal ipnetwork chrono time uuid postgres mysql macros tls runtime-tokio' -- -D warnings --emit=metadata
|
||||
- run: cargo rustc --no-default-features --features 'all-type postgres mysql macros tls runtime-tokio' -- -D warnings --emit=metadata
|
||||
|
||||
# unit test: async-std
|
||||
- run: cargo test --manifest-path sqlx-core/Cargo.toml --no-default-features --features 'bigdecimal ipnetwork chrono time uuid postgres mysql tls runtime-async-std'
|
||||
- run: cargo test --manifest-path sqlx-core/Cargo.toml --no-default-features --features 'all-type postgres mysql tls runtime-async-std'
|
||||
|
||||
# unit test: tokio
|
||||
- run: cargo test --manifest-path sqlx-core/Cargo.toml --no-default-features --features 'bigdecimal ipnetwork chrono time uuid postgres mysql tls runtime-tokio'
|
||||
- run: cargo test --manifest-path sqlx-core/Cargo.toml --no-default-features --features 'all-type postgres mysql tls runtime-tokio'
|
||||
|
||||
# integration test: sqlite + async-std
|
||||
- run: cargo test --no-default-features --features 'runtime-async-std sqlite macros tls'
|
||||
|
||||
@ -260,15 +260,27 @@ fn test_encode_date_time() {
|
||||
fn test_decode_date_time() {
|
||||
// test values from https://dev.mysql.com/doc/internals/en/binary-protocol-value.html
|
||||
let buf = [11, 218, 7, 10, 17, 19, 27, 30, 1, 0, 0, 0];
|
||||
let date1 = <NaiveDateTime as Decode<MySql>>::decode(Some(MySqlData::Binary(&buf))).unwrap();
|
||||
let date1 = <NaiveDateTime as Decode<MySql>>::decode(MySqlValue::binary(
|
||||
MySqlTypeInfo::default(),
|
||||
&buf,
|
||||
))
|
||||
.unwrap();
|
||||
assert_eq!(date1.to_string(), "2010-10-17 19:27:30.000001");
|
||||
|
||||
let buf = [7, 218, 7, 10, 17, 19, 27, 30];
|
||||
let date2 = <NaiveDateTime as Decode<MySql>>::decode(Some(MySqlData::Binary(&buf))).unwrap();
|
||||
let date2 = <NaiveDateTime as Decode<MySql>>::decode(MySqlValue::binary(
|
||||
MySqlTypeInfo::default(),
|
||||
&buf,
|
||||
))
|
||||
.unwrap();
|
||||
assert_eq!(date2.to_string(), "2010-10-17 19:27:30");
|
||||
|
||||
let buf = [4, 218, 7, 10, 17];
|
||||
let date3 = <NaiveDateTime as Decode<MySql>>::decode(Some(MySqlData::Binary(&buf))).unwrap();
|
||||
let date3 = <NaiveDateTime as Decode<MySql>>::decode(MySqlValue::binary(
|
||||
MySqlTypeInfo::default(),
|
||||
&buf,
|
||||
))
|
||||
.unwrap();
|
||||
assert_eq!(date3.to_string(), "2010-10-17 00:00:00");
|
||||
}
|
||||
|
||||
@ -283,6 +295,8 @@ fn test_encode_date() {
|
||||
#[test]
|
||||
fn test_decode_date() {
|
||||
let buf = [4, 218, 7, 10, 17];
|
||||
let date = <NaiveDate as Decode<MySql>>::decode(Some(MySqlData::Binary(&buf))).unwrap();
|
||||
let date =
|
||||
<NaiveDate as Decode<MySql>>::decode(MySqlValue::binary(MySqlTypeInfo::default(), &buf))
|
||||
.unwrap();
|
||||
assert_eq!(date.to_string(), "2010-10-17");
|
||||
}
|
||||
|
||||
@ -283,18 +283,27 @@ fn test_encode_date_time() {
|
||||
fn test_decode_date_time() {
|
||||
// test values from https://dev.mysql.com/doc/internals/en/binary-protocol-value.html
|
||||
let buf = [11, 218, 7, 10, 17, 19, 27, 30, 1, 0, 0, 0];
|
||||
let date1 =
|
||||
<PrimitiveDateTime as Decode<MySql>>::decode(Some(MySqlData::Binary(&buf))).unwrap();
|
||||
let date1 = <PrimitiveDateTime as Decode<MySql>>::decode(MySqlValue::binary(
|
||||
MySqlTypeInfo::default(),
|
||||
&buf,
|
||||
))
|
||||
.unwrap();
|
||||
assert_eq!(date1.to_string(), "2010-10-17 19:27:30.000001");
|
||||
|
||||
let buf = [7, 218, 7, 10, 17, 19, 27, 30];
|
||||
let date2 =
|
||||
<PrimitiveDateTime as Decode<MySql>>::decode(Some(MySqlData::Binary(&buf))).unwrap();
|
||||
let date2 = <PrimitiveDateTime as Decode<MySql>>::decode(MySqlValue::binary(
|
||||
MySqlTypeInfo::default(),
|
||||
&buf,
|
||||
))
|
||||
.unwrap();
|
||||
assert_eq!(date2.to_string(), "2010-10-17 19:27:30");
|
||||
|
||||
let buf = [4, 218, 7, 10, 17];
|
||||
let date3 =
|
||||
<PrimitiveDateTime as Decode<MySql>>::decode(Some(MySqlData::Binary(&buf))).unwrap();
|
||||
let date3 = <PrimitiveDateTime as Decode<MySql>>::decode(MySqlValue::binary(
|
||||
MySqlTypeInfo::default(),
|
||||
&buf,
|
||||
))
|
||||
.unwrap();
|
||||
assert_eq!(date3.to_string(), "2010-10-17 0:00");
|
||||
}
|
||||
|
||||
@ -309,6 +318,7 @@ fn test_encode_date() {
|
||||
#[test]
|
||||
fn test_decode_date() {
|
||||
let buf = [4, 218, 7, 10, 17];
|
||||
let date = <Date as Decode<MySql>>::decode(Some(MySqlData::Binary(&buf))).unwrap();
|
||||
let date = <Date as Decode<MySql>>::decode(MySqlValue::binary(MySqlTypeInfo::default(), &buf))
|
||||
.unwrap();
|
||||
assert_eq!(date, date!(2010 - 10 - 17));
|
||||
}
|
||||
|
||||
@ -264,18 +264,18 @@ fn test_encode_time() {
|
||||
#[test]
|
||||
fn test_decode_time() {
|
||||
let buf = [0u8; 8];
|
||||
let time: NaiveTime = Decode::<Postgres>::decode(Some(PgData::Binary(&buf))).unwrap();
|
||||
let time: NaiveTime = Decode::<Postgres>::decode(PgValue::bytes(TypeId(0), &buf)).unwrap();
|
||||
assert_eq!(time, NaiveTime::from_hms(0, 0, 0),);
|
||||
|
||||
// half an hour
|
||||
let buf = (1_000_000i64 * 60 * 30).to_be_bytes();
|
||||
let time: NaiveTime = Decode::<Postgres>::decode(Some(PgData::Binary(&buf))).unwrap();
|
||||
let time: NaiveTime = Decode::<Postgres>::decode(PgValue::bytes(TypeId(0), &buf)).unwrap();
|
||||
assert_eq!(time, NaiveTime::from_hms(0, 30, 0),);
|
||||
|
||||
// 12:53:05.125305
|
||||
let buf = (1_000_000i64 * 60 * 60 * 12 + 1_000_000i64 * 60 * 53 + 1_000_000i64 * 5 + 125305)
|
||||
.to_be_bytes();
|
||||
let time: NaiveTime = Decode::<Postgres>::decode(Some(PgData::Binary(&buf))).unwrap();
|
||||
let time: NaiveTime = Decode::<Postgres>::decode(PgValue::bytes(TypeId(0), &buf)).unwrap();
|
||||
assert_eq!(time, NaiveTime::from_hms_micro(12, 53, 5, 125305),);
|
||||
}
|
||||
|
||||
@ -307,15 +307,15 @@ fn test_encode_datetime() {
|
||||
#[test]
|
||||
fn test_decode_datetime() {
|
||||
let buf = [0u8; 8];
|
||||
let date: NaiveDateTime = Decode::<Postgres>::decode(Some(PgData::Binary(&buf))).unwrap();
|
||||
let date: NaiveDateTime = Decode::<Postgres>::decode(PgValue::bytes(TypeId(0), &buf)).unwrap();
|
||||
assert_eq!(date.to_string(), "2000-01-01 00:00:00");
|
||||
|
||||
let buf = 3_600_000_000i64.to_be_bytes();
|
||||
let date: NaiveDateTime = Decode::<Postgres>::decode(Some(PgData::Binary(&buf))).unwrap();
|
||||
let date: NaiveDateTime = Decode::<Postgres>::decode(PgValue::bytes(TypeId(0), &buf)).unwrap();
|
||||
assert_eq!(date.to_string(), "2000-01-01 01:00:00");
|
||||
|
||||
let buf = 629_377_265_000_000i64.to_be_bytes();
|
||||
let date: NaiveDateTime = Decode::<Postgres>::decode(Some(PgData::Binary(&buf))).unwrap();
|
||||
let date: NaiveDateTime = Decode::<Postgres>::decode(PgValue::bytes(TypeId(0), &buf)).unwrap();
|
||||
assert_eq!(date.to_string(), "2019-12-11 11:01:05");
|
||||
}
|
||||
|
||||
@ -343,14 +343,14 @@ fn test_encode_date() {
|
||||
#[test]
|
||||
fn test_decode_date() {
|
||||
let buf = [0; 4];
|
||||
let date: NaiveDate = Decode::<Postgres>::decode(Some(PgData::Binary(&buf))).unwrap();
|
||||
let date: NaiveDate = Decode::<Postgres>::decode(PgValue::bytes(TypeId(0), &buf)).unwrap();
|
||||
assert_eq!(date.to_string(), "2000-01-01");
|
||||
|
||||
let buf = 366i32.to_be_bytes();
|
||||
let date: NaiveDate = Decode::<Postgres>::decode(Some(PgData::Binary(&buf))).unwrap();
|
||||
let date: NaiveDate = Decode::<Postgres>::decode(PgValue::bytes(TypeId(0), &buf)).unwrap();
|
||||
assert_eq!(date.to_string(), "2001-01-01");
|
||||
|
||||
let buf = 7284i32.to_be_bytes();
|
||||
let date: NaiveDate = Decode::<Postgres>::decode(Some(PgData::Binary(&buf))).unwrap();
|
||||
let date: NaiveDate = Decode::<Postgres>::decode(PgValue::bytes(TypeId(0), &buf)).unwrap();
|
||||
assert_eq!(date.to_string(), "2019-12-11");
|
||||
}
|
||||
|
||||
@ -171,7 +171,8 @@ where
|
||||
mod tests {
|
||||
use super::PgArrayDecoder;
|
||||
use super::PgArrayEncoder;
|
||||
use crate::postgres::{PgData, PgValue, Postgres};
|
||||
use crate::postgres::protocol::TypeId;
|
||||
use crate::postgres::{PgValue, Postgres};
|
||||
|
||||
const BUF_BINARY_I32: &[u8] = b"\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x17\x00\x00\x00\x04\x00\x00\x00\x01\x00\x00\x00\x04\x00\x00\x00\x01\x00\x00\x00\x04\x00\x00\x00\x02\x00\x00\x00\x04\x00\x00\x00\x03\x00\x00\x00\x04\x00\x00\x00\x04";
|
||||
|
||||
@ -192,7 +193,7 @@ mod tests {
|
||||
#[test]
|
||||
fn it_decodes_text_i32() -> crate::Result<Postgres, ()> {
|
||||
let s = "{1,152,-12412}";
|
||||
let mut decoder = PgArrayDecoder::<i32>::new(Some(PgData::Text(s)))?;
|
||||
let mut decoder = PgArrayDecoder::<i32>::new(PgValue::str(TypeId(0), s))?;
|
||||
|
||||
assert_eq!(decoder.decode()?, Some(1));
|
||||
assert_eq!(decoder.decode()?, Some(152));
|
||||
@ -205,7 +206,7 @@ mod tests {
|
||||
#[test]
|
||||
fn it_decodes_text_str() -> crate::Result<Postgres, ()> {
|
||||
let s = "{\"\",\"\\\"\"}";
|
||||
let mut decoder = PgArrayDecoder::<String>::new(Some(PgData::Text(s)))?;
|
||||
let mut decoder = PgArrayDecoder::<String>::new(PgValue::str(TypeId(0), s))?;
|
||||
|
||||
assert_eq!(decoder.decode()?, Some("".to_string()));
|
||||
assert_eq!(decoder.decode()?, Some("\"".to_string()));
|
||||
@ -216,9 +217,9 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn it_decodes_binary_nulls() -> crate::Result<Postgres, ()> {
|
||||
let mut decoder = PgArrayDecoder::<Option<bool>>::new(Some(PgData::Binary(
|
||||
b"\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x10\x00\x00\x00\x04\x00\x00\x00\x01\xff\xff\xff\xff\x00\x00\x00\x01\x01\xff\xff\xff\xff\x00\x00\x00\x01\x00", 0,
|
||||
)))?;
|
||||
let mut decoder = PgArrayDecoder::<Option<bool>>::new(PgValue::bytes(TypeId(0),
|
||||
b"\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x10\x00\x00\x00\x04\x00\x00\x00\x01\xff\xff\xff\xff\x00\x00\x00\x01\x01\xff\xff\xff\xff\x00\x00\x00\x01\x00",
|
||||
))?;
|
||||
|
||||
assert_eq!(decoder.decode()?, Some(None));
|
||||
assert_eq!(decoder.decode()?, Some(Some(true)));
|
||||
@ -230,7 +231,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn it_decodes_binary_i32() -> crate::Result<Postgres, ()> {
|
||||
let mut decoder = PgArrayDecoder::<i32>::new(Some(PgData::Binary(BUF_BINARY_I32, 0)))?;
|
||||
let mut decoder = PgArrayDecoder::<i32>::new(PgValue::bytes(TypeId(0), BUF_BINARY_I32))?;
|
||||
|
||||
let val_1 = decoder.decode()?;
|
||||
let val_2 = decoder.decode()?;
|
||||
|
||||
@ -88,6 +88,8 @@ impl<'de> PgRecordDecoder<'de> {
|
||||
|
||||
#[test]
|
||||
fn test_encode_field() {
|
||||
use std::convert::TryInto;
|
||||
|
||||
let value = "Foo Bar";
|
||||
let mut raw_encoded = Vec::new();
|
||||
<&str as Encode<Postgres>>::encode(&value, &mut raw_encoded);
|
||||
@ -111,6 +113,8 @@ fn test_encode_field() {
|
||||
|
||||
#[test]
|
||||
fn test_decode_field() {
|
||||
use crate::postgres::protocol::TypeId;
|
||||
|
||||
let value = "Foo Bar".to_string();
|
||||
|
||||
let mut buf = Vec::new();
|
||||
@ -118,7 +122,7 @@ fn test_decode_field() {
|
||||
encoder.encode(&value);
|
||||
|
||||
let buf = buf.as_slice();
|
||||
let mut decoder = PgRecordDecoder::new(Some(PgData::Binary(buf, 0))).unwrap();
|
||||
let mut decoder = PgRecordDecoder::new(PgValue::bytes(TypeId(0), buf)).unwrap();
|
||||
|
||||
let value_decoded: String = decoder.decode().unwrap();
|
||||
assert_eq!(value_decoded, value);
|
||||
|
||||
@ -285,18 +285,18 @@ fn test_encode_time() {
|
||||
#[test]
|
||||
fn test_decode_time() {
|
||||
let buf = [0u8; 8];
|
||||
let time: Time = Decode::<Postgres>::decode(Some(PgData::Binary(&buf))).unwrap();
|
||||
let time: Time = Decode::<Postgres>::decode(PgValue::bytes(TypeId(0), &buf)).unwrap();
|
||||
assert_eq!(time, time!(0:00));
|
||||
|
||||
// half an hour
|
||||
let buf = (1_000_000i64 * 60 * 30).to_be_bytes();
|
||||
let time: Time = Decode::<Postgres>::decode(Some(PgData::Binary(&buf))).unwrap();
|
||||
let time: Time = Decode::<Postgres>::decode(PgValue::bytes(TypeId(0), &buf)).unwrap();
|
||||
assert_eq!(time, time!(0:30));
|
||||
|
||||
// 12:53:05.125305
|
||||
let buf = (1_000_000i64 * 60 * 60 * 12 + 1_000_000i64 * 60 * 53 + 1_000_000i64 * 5 + 125305)
|
||||
.to_be_bytes();
|
||||
let time: Time = Decode::<Postgres>::decode(Some(PgData::Binary(&buf))).unwrap();
|
||||
let time: Time = Decode::<Postgres>::decode(PgValue::bytes(TypeId(0), &buf)).unwrap();
|
||||
assert_eq!(time, time!(12:53:05.125305));
|
||||
}
|
||||
|
||||
@ -325,21 +325,24 @@ fn test_encode_datetime() {
|
||||
#[test]
|
||||
fn test_decode_datetime() {
|
||||
let buf = [0u8; 8];
|
||||
let date: PrimitiveDateTime = Decode::<Postgres>::decode(Some(PgData::Binary(&buf))).unwrap();
|
||||
let date: PrimitiveDateTime =
|
||||
Decode::<Postgres>::decode(PgValue::bytes(TypeId(0), &buf)).unwrap();
|
||||
assert_eq!(
|
||||
date,
|
||||
PrimitiveDateTime::new(date!(2000 - 01 - 01), time!(00:00:00))
|
||||
);
|
||||
|
||||
let buf = 3_600_000_000i64.to_be_bytes();
|
||||
let date: PrimitiveDateTime = Decode::<Postgres>::decode(Some(PgData::Binary(&buf))).unwrap();
|
||||
let date: PrimitiveDateTime =
|
||||
Decode::<Postgres>::decode(PgValue::bytes(TypeId(0), &buf)).unwrap();
|
||||
assert_eq!(
|
||||
date,
|
||||
PrimitiveDateTime::new(date!(2000 - 01 - 01), time!(01:00:00))
|
||||
);
|
||||
|
||||
let buf = 629_377_265_000_000i64.to_be_bytes();
|
||||
let date: PrimitiveDateTime = Decode::<Postgres>::decode(Some(PgData::Binary(&buf))).unwrap();
|
||||
let date: PrimitiveDateTime =
|
||||
Decode::<Postgres>::decode(PgValue::bytes(TypeId(0), &buf)).unwrap();
|
||||
assert_eq!(
|
||||
date,
|
||||
PrimitiveDateTime::new(date!(2019 - 12 - 11), time!(11:01:05))
|
||||
@ -372,21 +375,21 @@ fn test_encode_offsetdatetime() {
|
||||
#[test]
|
||||
fn test_decode_offsetdatetime() {
|
||||
let buf = [0u8; 8];
|
||||
let date: OffsetDateTime = Decode::<Postgres>::decode(Some(PgData::Binary(&buf))).unwrap();
|
||||
let date: OffsetDateTime = Decode::<Postgres>::decode(PgValue::bytes(TypeId(0), &buf)).unwrap();
|
||||
assert_eq!(
|
||||
date,
|
||||
PrimitiveDateTime::new(date!(2000 - 01 - 01), time!(00:00:00)).assume_utc()
|
||||
);
|
||||
|
||||
let buf = 3_600_000_000i64.to_be_bytes();
|
||||
let date: OffsetDateTime = Decode::<Postgres>::decode(Some(PgData::Binary(&buf))).unwrap();
|
||||
let date: OffsetDateTime = Decode::<Postgres>::decode(PgValue::bytes(TypeId(0), &buf)).unwrap();
|
||||
assert_eq!(
|
||||
date,
|
||||
PrimitiveDateTime::new(date!(2000 - 01 - 01), time!(01:00:00)).assume_utc()
|
||||
);
|
||||
|
||||
let buf = 629_377_265_000_000i64.to_be_bytes();
|
||||
let date: OffsetDateTime = Decode::<Postgres>::decode(Some(PgData::Binary(&buf))).unwrap();
|
||||
let date: OffsetDateTime = Decode::<Postgres>::decode(PgValue::bytes(TypeId(0), &buf)).unwrap();
|
||||
assert_eq!(
|
||||
date,
|
||||
PrimitiveDateTime::new(date!(2019 - 12 - 11), time!(11:01:05)).assume_utc()
|
||||
@ -417,14 +420,14 @@ fn test_encode_date() {
|
||||
#[test]
|
||||
fn test_decode_date() {
|
||||
let buf = [0; 4];
|
||||
let date: Date = Decode::<Postgres>::decode(Some(PgData::Binary(&buf))).unwrap();
|
||||
let date: Date = Decode::<Postgres>::decode(PgValue::bytes(TypeId(0), &buf)).unwrap();
|
||||
assert_eq!(date, date!(2000 - 01 - 01));
|
||||
|
||||
let buf = 366i32.to_be_bytes();
|
||||
let date: Date = Decode::<Postgres>::decode(Some(PgData::Binary(&buf))).unwrap();
|
||||
let date: Date = Decode::<Postgres>::decode(PgValue::bytes(TypeId(0), &buf)).unwrap();
|
||||
assert_eq!(date, date!(2001 - 01 - 01));
|
||||
|
||||
let buf = 7284i32.to_be_bytes();
|
||||
let date: Date = Decode::<Postgres>::decode(Some(PgData::Binary(&buf))).unwrap();
|
||||
let date: Date = Decode::<Postgres>::decode(PgValue::bytes(TypeId(0), &buf)).unwrap();
|
||||
assert_eq!(date, date!(2019 - 12 - 11));
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user