From 742946a66ae2f7d7d1acaf839977102a57ab9c8a Mon Sep 17 00:00:00 2001 From: Ryan Leckey Date: Fri, 26 Jul 2019 09:22:50 -0700 Subject: [PATCH] Add a couple of regression tests for encoding --- src/postgres/protocol/execute.rs | 11 +++++++++++ src/postgres/protocol/sync.rs | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/postgres/protocol/execute.rs b/src/postgres/protocol/execute.rs index e75d4f99..cf03f98c 100644 --- a/src/postgres/protocol/execute.rs +++ b/src/postgres/protocol/execute.rs @@ -15,3 +15,14 @@ pub fn execute(buf: &mut Vec, portal: &str, limit: i32) { // limit buf.extend_from_slice(&limit.to_be_bytes()); } + +#[cfg(test)] +mod tests { + #[test] + fn it_encodes_execute() { + let mut buf = Vec::new(); + super::execute(&mut buf, "", 0); + + assert_eq!(&*buf, b"E\0\0\0\t\0\0\0\0\0"); + } +} diff --git a/src/postgres/protocol/sync.rs b/src/postgres/protocol/sync.rs index f3d06e8a..fd751b26 100644 --- a/src/postgres/protocol/sync.rs +++ b/src/postgres/protocol/sync.rs @@ -5,3 +5,14 @@ pub fn sync(buf: &mut Vec) { buf.push(b'S'); buf.extend_from_slice(&4_i32.to_be_bytes()); } + +#[cfg(test)] +mod tests { + #[test] + fn it_encodes_sync() { + let mut buf = Vec::new(); + super::sync(&mut buf); + + assert_eq!(&*buf, b"S\0\0\0\x04"); + } +}