Skip to content

Commit

Permalink
Merge pull request #90 from h1alexbel/74
Browse files Browse the repository at this point in the history
74
  • Loading branch information
h1alexbel authored Jul 21, 2024
2 parents 977aab6 + 529eece commit 6874315
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 27 deletions.
3 changes: 3 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ edition = "2021"
name = "cli"
path = "src/main.rs"

[lints.clippy]
unwrap_used = "deny"

[dev-dependencies]
assert_cmd = "2.0.14"

Expand Down
6 changes: 6 additions & 0 deletions server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ path = "src/lib.rs"
[lints.rust]
missing_docs = "deny"

# @todo #74:30min\DEV Find way to spread clippy config
# We need to find way to spread clippy/rustfmt configuration
# through all workspaces to reduce duplications in child workspaces.
[lints.clippy]
unwrap_used = "deny"

[dependencies]
openapi = { path = "../github-mirror" }
anyhow = "1.0.86"
Expand Down
38 changes: 18 additions & 20 deletions server/src/handlers/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ use axum::response::IntoResponse;
use axum::Json;
use log::debug;

use crate::ServerConfig;
use openapi::models::MetaRoot200Response;

use crate::ServerConfig;

/// Home handler.
pub async fn home(State(config): State<ServerConfig>) -> impl IntoResponse {
let response = Json(
Expand Down Expand Up @@ -188,8 +189,6 @@ pub async fn home(State(config): State<ServerConfig>) -> impl IntoResponse {

#[cfg(test)]
mod tests {
use crate::handlers::home::home;
use crate::ServerConfig;
use anyhow::Result;
use axum::body::to_bytes;
use axum::extract::State;
Expand All @@ -198,6 +197,9 @@ mod tests {
use serde_json::{from_str, Value};
use tokio::fs;

use crate::handlers::home::home;
use crate::ServerConfig;

const BYTES_READ_LIMIT: usize = 10000;

#[tokio::test]
Expand All @@ -219,25 +221,21 @@ mod tests {

#[tokio::test]
async fn returns_root_response() -> Result<()> {
let actual: Value = from_str(
&String::from_utf8(
to_bytes(
IntoResponse::into_response(
home(State(ServerConfig {
host: String::from("test"),
port: 1234,
}))
.await,
)
.into_body(),
BYTES_READ_LIMIT,
let actual: Value = from_str(&String::from_utf8(
to_bytes(
IntoResponse::into_response(
home(State(ServerConfig {
host: String::from("test"),
port: 1234,
}))
.await,
)
.await
.unwrap()
.to_vec(),
.into_body(),
BYTES_READ_LIMIT,
)
.unwrap(),
)
.await?
.to_vec(),
)?)
.expect("Failed to parse JSON");
assert_that!(
actual.to_string(),
Expand Down
5 changes: 1 addition & 4 deletions server/src/objects/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,11 @@ impl User {
// apply it to the storage. Keep in mind that application function in the
// storage should be thread-safe (as well as #xml function). Don't forget to
// create unit tests that prove that.
// @todo #17:30min Configure clippy to reject code with #unwrap().
// We should prohibit to use #unwrap() function in our code. Let's configure
// clippy tool in the respective manner and get rid of all #unwrap() calls.
impl User {
/// Save user.
pub async fn save(self) -> Result<()> {
info!("saving user @{}", self.username);
let xml = to_string(&self).unwrap();
let xml = to_string(&self)?;
debug!("XMLed user: {}", xml);
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion server/src/xml/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ mod tests {
let temp = TempDir::new("temp")?;
let path = temp.path().join("fakehub.xml");
Storage::new(path.to_str());
let xml = fs::read_to_string(path).unwrap();
let xml = fs::read_to_string(path)?;
let expected = "<root>\n<github><users/></github>\n</root>\n";
assert_that!(xml, is(equal_to(String::from(expected))));
Ok(())
Expand Down
3 changes: 1 addition & 2 deletions server/tests/routes_it.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ mod routes_its {
let response = reqwest::Client::new()
.get(format!("http://localhost:{}/", port))
.send()
.await
.unwrap();
.await?;
assert_that!(response.status().as_u16(), is(equal_to(200)));
Ok(())
}
Expand Down

1 comment on commit 6874315

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 6874315 Jul 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 17-e45e524d disappeared from server/src/objects/user.rs), that's why I closed #74. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

Please sign in to comment.