Skip to content

Commit

Permalink
Remove should_panic unit tests Azure#307
Browse files Browse the repository at this point in the history
  • Loading branch information
u5surf committed Jun 22, 2021
1 parent e1fc0ea commit 485749d
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 38 deletions.
9 changes: 5 additions & 4 deletions sdk/core/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use http::StatusCode;
use std::cmp::PartialEq;
#[cfg(feature = "enable_hyper")]
use hyper::{self, body, Body};
#[cfg(feature = "enable_hyper")]
Expand All @@ -7,7 +8,7 @@ type HttpClientError = hyper::Error;
type HttpClientError = reqwest::Error;

#[non_exhaustive]
#[derive(Debug, thiserror::Error)]
#[derive(Debug, PartialEq, thiserror::Error)]
pub enum ParsingError {
#[error("Element not found: {0}")]
ElementNotFound(String),
Expand All @@ -25,7 +26,7 @@ pub enum ParseError {
}

#[non_exhaustive]
#[derive(Debug, thiserror::Error)]
#[derive(Debug, PartialEq, thiserror::Error)]
pub enum AzurePathParseError {
#[error("Path separator not found")]
PathSeparatorNotFoundError,
Expand Down Expand Up @@ -138,7 +139,7 @@ impl HttpError {
}
}
}
#[derive(Debug, thiserror::Error)]
#[derive(Debug, PartialEq, thiserror::Error)]
pub enum Not512ByteAlignedError {
#[error("start range not 512-byte aligned: {0}")]
StartRange(u64),
Expand All @@ -157,7 +158,7 @@ pub enum PermissionError {
},
}

#[derive(Debug, thiserror::Error)]
#[derive(Debug, PartialEq, thiserror::Error)]
pub enum Parse512AlignedError {
#[error("split not found")]
SplitNotFound,
Expand Down
5 changes: 3 additions & 2 deletions sdk/core/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ macro_rules! response_from_headers {
mod test {
create_enum!(Colors, (Black, "Black"), (White, "White"), (Red, "Red"));
create_enum!(ColorsMonochrome, (Black, "Black"), (White, "White"));
use crate::ParsingError;

struct Options {
a: Option<String>,
Expand Down Expand Up @@ -203,9 +204,9 @@ mod test {
}

#[test]
#[should_panic(expected = "ElementNotFound(\"Red\")")]
fn test_color_parse_err_1() {
"Red".parse::<ColorsMonochrome>().unwrap();
let err = "Red".parse::<ColorsMonochrome>().unwrap_err();
assert_eq!(err, ParsingError::ElementNotFound("Red".to_string()));
}

#[test]
Expand Down
18 changes: 10 additions & 8 deletions sdk/core/src/request_options/ba512_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ impl fmt::Display for BA512Range {
#[cfg(test)]
mod test {
use super::*;
use crate::Not512ByteAlignedError::StartRange;
use crate::Not512ByteAlignedError::EndRange;

#[test]
fn test_512range_parse() {
Expand All @@ -102,27 +104,27 @@ mod test {
}

#[test]
#[should_panic(expected = "ParseIntError(ParseIntError { kind: InvalidDigit })")]
fn test_512range_parse_panic_1() {
"abba/2000".parse::<BA512Range>().unwrap();
let err = "abba/2000".parse::<BA512Range>().unwrap_err();
assert_eq!(err.to_string(), "parse int error: invalid digit found in string".to_string());
}

#[test]
#[should_panic(expected = "SplitNotFound")]
fn test_512range_parse_panic_2() {
"1000-2000".parse::<BA512Range>().unwrap();
let err = "1000-2000".parse::<BA512Range>().unwrap_err();
assert_eq!(err, Parse512AlignedError::SplitNotFound);
}

#[test]
#[should_panic(expected = "Not512ByteAlignedError(StartRange(7))")]
fn test_512range_invalid_start_range() {
"7/511".parse::<BA512Range>().unwrap();
let err ="7/511".parse::<BA512Range>().unwrap_err();
assert_eq!(err, Parse512AlignedError::Not512ByteAlignedError(StartRange(7)));
}

#[test]
#[should_panic(expected = "Not512ByteAlignedError(EndRange(100))")]
fn test_512range_invalid_end_range() {
"0/100".parse::<BA512Range>().unwrap();
let err = "0/100".parse::<BA512Range>().unwrap_err();
assert_eq!(err, Parse512AlignedError::Not512ByteAlignedError(EndRange(100)));
}

#[test]
Expand Down
12 changes: 6 additions & 6 deletions sdk/core/src/request_options/content_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,21 @@ mod test {
}

#[test]
#[should_panic(expected = "TokenNotFound(\"bytes \")")]
fn test_parse_no_starting_token() {
"something else".parse::<ContentRange>().unwrap();
let err = "something else".parse::<ContentRange>().unwrap_err();
assert_eq!(err, ParseError::TokenNotFound("bytes ".to_string()));
}

#[test]
#[should_panic(expected = "SplitNotFound('-')")]
fn test_parse_no_dash() {
"bytes 100".parse::<ContentRange>().unwrap();
let err = "bytes 100".parse::<ContentRange>().unwrap_err();
assert_eq!(err, ParseError::SplitNotFound('-'));
}

#[test]
#[should_panic(expected = "SplitNotFound('/')")]
fn test_parse_no_slash() {
"bytes 100-500".parse::<ContentRange>().unwrap();
let err = "bytes 100-500".parse::<ContentRange>().unwrap_err();
assert_eq!(err, ParseError::SplitNotFound('/'));
}

#[test]
Expand Down
8 changes: 4 additions & 4 deletions sdk/core/src/request_options/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@ mod test {
}

#[test]
#[should_panic(expected = "ParseIntError(ParseIntError { kind: InvalidDigit })")]
fn test_range_parse_panic_1() {
"abba/2000".parse::<Range>().unwrap();
let err = "abba/2000".parse::<Range>().unwrap_err();
assert_eq!(err.to_string(), "Parse int error invalid digit found in string".to_string());
}

#[test]
#[should_panic(expected = "SplitNotFound")]
fn test_range_parse_panic_2() {
"1000-2000".parse::<Range>().unwrap();
let err = "1000-2000".parse::<Range>();
assert_eq!(err, Err(ParseError::SplitNotFound('/')));
}

#[test]
Expand Down
24 changes: 12 additions & 12 deletions sdk/storage/src/core/into_azure_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,38 +72,38 @@ mod test {
}

#[test]
#[should_panic(expected = "PathSeparatorNotFoundError")]
fn no_slash() {
let path = "containerblob";
let p = &path;
assert!(p.container_name().unwrap() == "container");
assert!(path.blob_name().unwrap() == "blob");
let _e = AzurePathParseError::PathSeparatorNotFoundError;
assert_eq!(p.container_name().unwrap_err(), _e);
assert_eq!(p.blob_name().unwrap_err(), _e);
}

#[test]
#[should_panic(expected = "MultiplePathSeparatorsFoundError")]
fn three_slashes() {
let path = "container/blob/extra";
let p = &path;
assert!(p.container_name().unwrap() == "container");
assert!(path.blob_name().unwrap() == "blob");
let _e = AzurePathParseError::MultiplePathSeparatorsFoundError;
assert_eq!(p.container_name().unwrap_err(), _e);
assert_eq!(p.blob_name().unwrap_err(), _e);
}

#[test]
#[should_panic(expected = "MissingContainerError")]
fn missing_container() {
let path = "/blob";
let p = &path;
assert!(p.container_name().unwrap() == "container");
assert!(path.blob_name().unwrap() == "blob");
let _e = AzurePathParseError::MissingContainerError;
assert_eq!(p.container_name().unwrap_err(), _e);
assert_eq!(p.blob_name().unwrap_err(), _e);
}

#[test]
#[should_panic(expected = "MissingBlobError")]
fn missing_blob() {
let path = "container/";
let p = &path;
assert!(p.container_name().unwrap() == "container");
assert!(path.blob_name().unwrap() == "blob");
let _e = AzurePathParseError::MissingBlobError;
assert_eq!(p.container_name().unwrap_err(), _e);
assert_eq!(p.blob_name().unwrap_err(), _e);
}
}
3 changes: 1 addition & 2 deletions services/autorust/codegen/src/config_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,6 @@ input-file:
}

#[test]
#[should_panic]
fn literate_config_should_fail_for_invalid_heading() {
let invalid_input = "
## INVALID_HEADING
Expand All @@ -316,7 +315,7 @@ input-file:
- Microsoft.Storage/stable/2019-06-01/storage.json
```
";
parse_configurations_from_cmark_config(invalid_input);
assert!(parse_configurations_from_cmark_config(invalid_input).is_empty());
}

#[test]
Expand Down

0 comments on commit 485749d

Please sign in to comment.