Execute a SQL statement expecting an error containing the given substring.
(&self, sql: &str, expected_substring: &str)
| 165 | |
| 166 | /// Execute a SQL statement expecting an error containing the given substring. |
| 167 | pub async fn expect_error(&self, sql: &str, expected_substring: &str) { |
| 168 | let client = self.client.as_ref(); |
| 169 | match client.simple_query(sql).await { |
| 170 | Ok(_) => panic!("expected error containing '{expected_substring}', got success"), |
| 171 | Err(e) => { |
| 172 | let msg = pg_error_detail(&e); |
| 173 | assert!( |
| 174 | msg.to_lowercase() |
| 175 | .contains(&expected_substring.to_lowercase()), |
| 176 | "expected error containing '{expected_substring}', got: {msg}" |
| 177 | ); |
| 178 | } |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | /// Extract a detailed error message from a tokio-postgres error. |