-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from h1alexbel/13
feat(multi-module): splitted to modules
- Loading branch information
Showing
16 changed files
with
271 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,25 +19,9 @@ | |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
|
||
[package] | ||
name = "fakehub" | ||
version = "0.0.0" | ||
edition = "2021" | ||
license = "MIT" | ||
description = """ | ||
GitHub API Server Stub. Fully functional fake version of a GitHub API that | ||
supports all the features and works locally, with no connection to GitHub at | ||
all. | ||
""" | ||
authors = ["Aliaksei Bialíauski <[email protected]>", "Ivanchuk Ivan <[email protected]>"] | ||
|
||
[dependencies] | ||
anyhow = "1.0.86" | ||
serde = { version = "1.0.203", features = ["derive"] } | ||
serde_json = "1.0.117" | ||
tokio = { version = "1.0.0", features = ["rt", "rt-multi-thread", "macros", "fs"] } | ||
axum = "0.7.5" | ||
log = { version = "0.4.21", features = [] } | ||
env_logger = "0.11.3" | ||
tempdir = "0.3.7" | ||
[workspace] | ||
members = [ | ||
"server", | ||
"cli", | ||
] | ||
resolver = "1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# The MIT License (MIT) | ||
# | ||
# Copyright (c) 2024 Aliaksei Bialiauski | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included | ||
# in all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
[package] | ||
name = "cli" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[[bin]] | ||
name = "cli" | ||
path = "src/main.rs" | ||
|
||
[dev-dependencies] | ||
assert_cmd = "2.0.14" | ||
|
||
[dependencies] | ||
anyhow = "1.0.86" | ||
clap = { version = "4.5.7", features = ["derive"] } | ||
server = { path = "../server" } | ||
tokio = { version = "1.0.0", features = ["rt", "rt-multi-thread", "macros"] } | ||
log = "0.4.21" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// The MIT License (MIT) | ||
// | ||
// Copyright (c) 2024 Aliaksei Bialiauski | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included | ||
// in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
use clap::Parser; | ||
|
||
// @todo #13:15min Handle port argument | ||
// We should process the port argument and | ||
// pass it to the server on `start` command. | ||
// Start command should be added also with clap | ||
#[derive(Parser, Debug)] | ||
pub(crate) struct Args { | ||
/// The port to run | ||
#[arg(short, long, default_value_t = 3000)] | ||
pub(crate) port: usize, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// The MIT License (MIT) | ||
// | ||
// Copyright (c) 2024 Aliaksei Bialiauski | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included | ||
// in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
use std::str; | ||
|
||
use anyhow::Result; | ||
use assert_cmd::Command; | ||
|
||
#[test] | ||
fn should_output_help() -> Result<()> { | ||
env!("CARGO_BIN_EXE_cli"); | ||
let assertion = Command::cargo_bin("cli")?.arg("--help").assert(); | ||
let bytes = assertion.get_output().stdout.as_slice(); | ||
let output = str::from_utf8(bytes)?; | ||
assert!(output.contains("The port to run")); | ||
assert!(output.contains("3000")); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// The MIT License (MIT) | ||
// | ||
// Copyright (c) 2024 Aliaksei Bialiauski | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included | ||
// in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
mod integration_test; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# The MIT License (MIT) | ||
# | ||
# Copyright (c) 2024 Aliaksei Bialiauski | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included | ||
# in all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
[package] | ||
name = "server" | ||
version = "0.0.0" | ||
edition = "2021" | ||
license = "MIT" | ||
description = """ | ||
GitHub API Server Stub. Fully functional fake version of a GitHub API that | ||
supports all the features and works locally, with no connection to GitHub at | ||
all. | ||
""" | ||
authors = ["Aliaksei Bialíauski <[email protected]>", "Ivanchuk Ivan <[email protected]>"] | ||
|
||
[lib] | ||
path = "src/lib.rs" | ||
|
||
[dependencies] | ||
anyhow = "1.0.86" | ||
serde = { version = "1.0.203", features = ["derive"] } | ||
serde_json = "1.0.117" | ||
tokio = { version = "1.0.0", features = ["rt", "rt-multi-thread", "macros", "fs"] } | ||
axum = "0.7.5" | ||
log = { version = "0.4.21", features = [] } | ||
env_logger = "0.11.3" | ||
tempdir = "0.3.7" |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// The MIT License (MIT) | ||
// | ||
// Copyright (c) 2024 Aliaksei Bialiauski | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included | ||
// in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
use std::io; | ||
|
||
use anyhow::Result; | ||
use axum::routing::get; | ||
use axum::Router; | ||
use tokio::net::TcpListener; | ||
|
||
use crate::routes::home; | ||
use crate::xml::storage::touch_storage; | ||
|
||
mod routes; | ||
mod xml; | ||
|
||
#[derive(Default)] | ||
pub struct Server { | ||
port: usize, | ||
} | ||
|
||
impl Server { | ||
pub fn new(port: usize) -> Server { | ||
Server { port } | ||
} | ||
} | ||
|
||
impl Server { | ||
pub async fn start(self) -> Result<()> { | ||
touch_storage(Some("fakehub.xml")); | ||
let app: Router = Router::new().route("/", get(home::home)); | ||
let addr: String = format!("0.0.0.0:{}", self.port); | ||
let started: io::Result<TcpListener> = TcpListener::bind(addr.clone()).await; | ||
match started { | ||
Ok(listener) => axum::serve(listener, app).await?, | ||
Err(err) => { | ||
panic!("Can't bind address {}: '{}'", addr.clone(), err) | ||
} | ||
}; | ||
Ok(()) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use anyhow::Result; | ||
|
||
#[test] | ||
fn creates_the_server() -> Result<()> { | ||
let server = crate::Server::new(1234); | ||
assert_eq!(server.port, 1234); | ||
Ok(()) | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f8bde4e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
13-97a91bb1
discovered incli/src/args.rs
) and submitted as #43. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.