Skip to content

Commit

Permalink
Better unwrapping of errors in test cases
Browse files Browse the repository at this point in the history
Signed-off-by: Kate Goldenring <kate.goldenring@fermyon.com>
  • Loading branch information
kate-goldenring committed Oct 9, 2023
1 parent 29c6ec6 commit 45303bf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
22 changes: 8 additions & 14 deletions src/commands/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,10 @@ mod link_tests {
.returning(move |_| Ok(dbs.to_owned()));

let result = command.link(mock, app_id).await;
match result {
Ok(_) => panic!("Expected error"),
Err(err) => assert_eq!(
err.to_string(),
r#"Database "does-not-exist" does not exist"#
),
}
assert_eq!(
result.unwrap_err().to_string(),
r#"Database "does-not-exist" does not exist"#
);
Ok(())
}

Expand Down Expand Up @@ -300,13 +297,10 @@ mod link_tests {
mock.expect_get_databases()
.returning(move |_| Ok(dbs.to_owned()));
let result = command.link(mock, app_id).await;
match result {
Ok(_) => panic!("Expected error"),
Err(err) => assert_eq!(
err.to_string(),
r#"Database "db1" is already linked to app "app" with the label "label""#
),
}
assert_eq!(
result.unwrap_err().to_string(),
r#"Database "db1" is already linked to app "app" with the label "label""#
);
Ok(())
}

Expand Down
16 changes: 8 additions & 8 deletions src/commands/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,10 +469,10 @@ mod sqlite_tests {
.returning(move |_| Ok(dbs.to_owned()));

let result = command.run(mock).await;
match result {
Ok(_) => panic!("Expected error"),
Err(err) => assert_eq!(err.to_string(), r#"Database "db1" already exists"#),
}
assert_eq!(
result.unwrap_err().to_string(),
r#"Database "db1" already exists"#
);
Ok(())
}

Expand Down Expand Up @@ -503,10 +503,10 @@ mod sqlite_tests {
mock.expect_get_databases().returning(move |_| Ok(vec![]));

let result = command.run(mock).await;
match result {
Ok(_) => panic!("Expected error"),
Err(err) => assert_eq!(err.to_string(), r#"No database found with name "db1""#),
}
assert_eq!(
result.unwrap_err().to_string(),
r#"No database found with name "db1""#
);
Ok(())
}

Expand Down

0 comments on commit 45303bf

Please sign in to comment.