Skip to content

Commit

Permalink
fix(mysql): correct Capabilities assertions in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
abonander committed Aug 22, 2024
1 parent 37f53cc commit 59f5cd0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
11 changes: 8 additions & 3 deletions sqlx-mysql/src/protocol/connect/auth_switch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,14 @@ fn test_decode_auth_switch_cleartext_disabled() {

let e = AuthSwitchRequest::decode_with(AUTH_SWITCH_CLEARTEXT.into(), false).unwrap_err();

assert_eq!(
e.to_string(),
"encountered unexpected or invalid data: mysql_cleartext_plugin disabled"
let e_str = e.to_string();

let expected = "encountered unexpected or invalid data: mysql_cleartext_plugin disabled";

assert!(
// Don't want to assert the full string since it contains the module path now.
e_str.starts_with(expected),
"expected error string to start with {expected:?}, got {e_str:?}"
);
}

Expand Down
19 changes: 10 additions & 9 deletions sqlx-mysql/src/protocol/connect/handshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,12 @@ impl ProtocolDecode<'_> for Handshake {
fn test_decode_handshake_mysql_8_0_18() {
const HANDSHAKE_MYSQL_8_0_18: &[u8] = b"\n8.0.18\x00\x19\x00\x00\x00\x114aB0c\x06g\x00\xff\xff\xff\x02\x00\xff\xc7\x15\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00tL\x03s\x0f[4\rl4. \x00caching_sha2_password\x00";

let mut p = Handshake::decode(HANDSHAKE_MYSQL_8_0_18.into()).unwrap();
let p = Handshake::decode(HANDSHAKE_MYSQL_8_0_18.into()).unwrap();

assert_eq!(p.protocol_version, 10);

p.server_capabilities.toggle(
assert_eq!(
p.server_capabilities,
Capabilities::MYSQL
| Capabilities::FOUND_ROWS
| Capabilities::LONG_FLAG
Expand Down Expand Up @@ -128,8 +129,6 @@ fn test_decode_handshake_mysql_8_0_18() {
| Capabilities::REMEMBER_OPTIONS,
);

assert!(p.server_capabilities.is_empty());

assert_eq!(p.server_default_collation, 255);
assert!(p.status.contains(Status::SERVER_STATUS_AUTOCOMMIT));

Expand All @@ -148,7 +147,7 @@ fn test_decode_handshake_mysql_8_0_18() {
fn test_decode_handshake_mariadb_10_4_7() {
const HANDSHAKE_MARIA_DB_10_4_7: &[u8] = b"\n5.5.5-10.4.7-MariaDB-1:10.4.7+maria~bionic\x00\x0b\x00\x00\x00t6L\\j\"dS\x00\xfe\xf7\x08\x02\x00\xff\x81\x15\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00U14Oph9\"<H5n\x00mysql_native_password\x00";

let mut p = Handshake::decode(HANDSHAKE_MARIA_DB_10_4_7.into()).unwrap();
let p = Handshake::decode(HANDSHAKE_MARIA_DB_10_4_7.into()).unwrap();

assert_eq!(p.protocol_version, 10);

Expand All @@ -157,7 +156,8 @@ fn test_decode_handshake_mariadb_10_4_7() {
"5.5.5-10.4.7-MariaDB-1:10.4.7+maria~bionic"
);

p.server_capabilities.toggle(
assert_eq!(
p.server_capabilities,
Capabilities::FOUND_ROWS
| Capabilities::LONG_FLAG
| Capabilities::CONNECT_WITH_DB
Expand All @@ -179,11 +179,12 @@ fn test_decode_handshake_mariadb_10_4_7() {
| Capabilities::CAN_HANDLE_EXPIRED_PASSWORDS
| Capabilities::SESSION_TRACK
| Capabilities::DEPRECATE_EOF
| Capabilities::REMEMBER_OPTIONS,
| Capabilities::REMEMBER_OPTIONS
| Capabilities::MARIADB_CLIENT_PROGRESS
| Capabilities::MARIADB_CLIENT_MULTI
| Capabilities::MARIADB_CLIENT_STMT_BULK_OPERATIONS
);

assert!(p.server_capabilities.is_empty());

assert_eq!(p.server_default_collation, 8);
assert!(p.status.contains(Status::SERVER_STATUS_AUTOCOMMIT));
assert!(matches!(
Expand Down

0 comments on commit 59f5cd0

Please sign in to comment.