Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 44 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Rust
name: build and test

on:
push:
Expand All @@ -10,13 +10,53 @@ env:
CARGO_TERM_COLOR: always

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Lint
run: |
cargo clippy -- -D warnings

build:
needs: [ "lint" ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Checkout repository
uses: actions/checkout@v2

- name: Build
run: cargo build --verbose
run: |
cargo build --verbose

test:
needs: [ "build" ]
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Run tests
env:
JWT_SECRET: ${{ secrets.JWT_SECRET }}
run: cargo test --verbose
run: |
cargo test --verbose

coverage:
needs: [ "build" ]
name: coverage
runs-on: ubuntu-latest
container:
image: xd009642/tarpaulin:develop-nightly
options: --security-opt seccomp=unconfined
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Generate code coverage
env:
JWT_SECRET: ${{ secrets.JWT_SECRET }}
run: |
cargo +nightly tarpaulin --verbose --all-features --workspace --timeout 120
4 changes: 2 additions & 2 deletions src/api/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ pub struct Pagination {

impl Pagination {
pub fn get_offset(&self) -> i64 {
self.offset.unwrap_or_else(|| DEFAULT_PAGINATION_OFFSET)
self.offset.unwrap_or(DEFAULT_PAGINATION_OFFSET)
}

pub fn get_limit(&self) -> i64 {
self.limit.unwrap_or_else(|| DEFAULT_PAGINATION_LIMIT)
self.limit.unwrap_or(DEFAULT_PAGINATION_LIMIT)
}
}

Expand Down
9 changes: 3 additions & 6 deletions src/api/v1/list_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,15 @@ mod tests {
.returning(|_, _| {
Box::pin(async {
let posted_at =
DateTime::parse_from_rfc3339("2020-04-12T22:10:57+02:00".as_ref()).unwrap();
DateTime::parse_from_rfc3339("2020-04-12T22:10:57+02:00").unwrap();
let posted_at_utc = posted_at.with_timezone(&Utc);

let mut exp_messages = vec![];
exp_messages.push(domain::message::Message {
Ok(vec![domain::message::Message {
message_id: 1,
message_content: "test".to_string(),
user_id: 123,
posted_at: posted_at_utc,
});

Ok(exp_messages)
}])
})
});

Expand Down
2 changes: 1 addition & 1 deletion src/api/v1/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ mod tests {
let body = response.into_body().collect().await.unwrap().to_bytes();
let login_response: entities::auth::LoginResponse = serde_json::from_slice(&body).unwrap();

assert!(login_response.token.len() > 0);
assert!(!login_response.token.is_empty());
}
}
2 changes: 1 addition & 1 deletion src/api/v1/post_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ mod tests {

messages_repository
.expect_create_message()
.withf(|x| x.content == "test-msg".to_string() && x.user_id == 123)
.withf(|x| x.content == *"test-msg" && x.user_id == 123)
.once()
.returning(|_| Box::pin(async { Ok(1) }));

Expand Down
2 changes: 1 addition & 1 deletion src/bin/chat/entrypoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct Entrypoint<'a> {
closer: Closer<'a>,
}

impl<'a> Entrypoint<'_> {
impl Entrypoint<'_> {
pub fn new(config: Config) -> Self {
Self {
config,
Expand Down
6 changes: 6 additions & 0 deletions src/core_utils/closer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ pub struct Closer<'a> {
closers: Vec<CloserFunc<'a>>,
}

impl Default for Closer<'_> {
fn default() -> Self {
Self::new()
}
}

impl<'a> Closer<'a> {
pub fn new() -> Closer<'a> {
Closer { closers: vec![] }
Expand Down
18 changes: 9 additions & 9 deletions src/core_utils/postgres_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,28 @@ pub fn build_pool_from_config(
let mut conn_opts = deadpool_postgres::Config::new();
conn_opts.application_name = Some(client_id);
conn_opts.host = Some(config.host.clone());
conn_opts.port = Some(config.port.clone());
conn_opts.port = Some(config.port);
conn_opts.user = Some(config.user.clone());
conn_opts.password = Some(config.password.clone());
conn_opts.dbname = Some(config.db.clone());
conn_opts.connect_timeout = Some(Duration::from(
<humantime::Duration as Into<Duration>>::into(config.connect_timeout),
conn_opts.connect_timeout = Some(<humantime::Duration as Into<Duration>>::into(
config.connect_timeout,
));
conn_opts.keepalives = Some(config.keepalives);
conn_opts.keepalives_idle = Some(Duration::from(
<humantime::Duration as Into<Duration>>::into(config.keepalives_idle),
conn_opts.keepalives_idle = Some(<humantime::Duration as Into<Duration>>::into(
config.keepalives_idle,
));
conn_opts.target_session_attrs = Some(config.get_target_session_attrs());
conn_opts.manager = Some(deadpool_postgres::ManagerConfig {
recycling_method: deadpool_postgres::RecyclingMethod::Fast,
});
conn_opts.pool = Some(deadpool_postgres::PoolConfig {
timeouts: deadpool_postgres::Timeouts {
wait: Some(Duration::from(
<humantime::Duration as Into<Duration>>::into(config.wait_timeout),
wait: Some(<humantime::Duration as Into<Duration>>::into(
config.wait_timeout,
)),
create: Some(Duration::from(
<humantime::Duration as Into<Duration>>::into(config.create_timeout),
create: Some(<humantime::Duration as Into<Duration>>::into(
config.create_timeout,
)),
..Default::default()
},
Expand Down
7 changes: 2 additions & 5 deletions src/core_utils/swagger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ pub fn get_openapi_router(router: OpenApiRouter) -> Router {
(url = "http://localhost:9000", description = "local")
)
)]

struct ApiDoc;

pub struct SecurityAddon;
Expand All @@ -42,15 +41,13 @@ pub fn get_openapi_router(router: OpenApiRouter) -> Router {
.merge(router)
.split_for_parts();

let router = router
router
.merge(SwaggerUi::new("/swagger-ui").url("/api-docs/openapi.json", api.clone()))
.merge(Redoc::with_url("/redoc", api.clone()))
// There is no need to create `RapiDoc::with_openapi` because the OpenApi is served
// via SwaggerUi instead we only make rapidoc to point to the existing doc.
.merge(RapiDoc::new("/api-docs/openapi.json").path("/rapidoc"))
// Alternative to above
// .merge(RapiDoc::with_openapi("/api-docs/openapi2.json", api).path("/rapidoc"))
.merge(Scalar::with_url("/scalar", api));

router
.merge(Scalar::with_url("/scalar", api))
}
5 changes: 1 addition & 4 deletions src/infra/repositories/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ impl MessagesRepositoryTrait for MessagesRepository {

let rows = client.query(&stmt, &[&offset, &limit]).await?;

Ok(rows
.iter()
.map(|row| message::Message::try_from(row).unwrap())
.collect())
Ok(rows.iter().map(message::Message::from).collect())
}
}