From b1ddb4c029f979d1c7b93bc5d3c3cea81516e159 Mon Sep 17 00:00:00 2001 From: mkbeh Date: Fri, 28 Feb 2025 20:25:39 +0300 Subject: [PATCH 01/12] ci: add code cov pipe step --- .github/workflows/ci.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9b2bbb2..888bb2b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,10 +13,17 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - name: Checkout repository + uses: actions/checkout@v2 + - name: Build run: cargo build --verbose + - name: Run tests env: JWT_SECRET: ${{ secrets.JWT_SECRET }} - run: cargo test --verbose \ No newline at end of file + run: cargo test --verbose + + - name: Generate code coverage + run: | + cargo +nightly tarpaulin --verbose --all-features --workspace --timeout 120 \ No newline at end of file From 758f7831f75634d43e4b4fb21352e56bdbd4d0a7 Mon Sep 17 00:00:00 2001 From: mkbeh Date: Fri, 28 Feb 2025 20:31:05 +0300 Subject: [PATCH 02/12] ci: test cov pipe --- .github/workflows/ci.yml | 6 +++--- .github/workflows/coverage.yml | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/coverage.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 888bb2b..3923eb1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,6 +24,6 @@ jobs: JWT_SECRET: ${{ secrets.JWT_SECRET }} run: cargo test --verbose - - name: Generate code coverage - run: | - cargo +nightly tarpaulin --verbose --all-features --workspace --timeout 120 \ No newline at end of file +# - name: Generate code coverage +# run: | +# cargo +nightly tarpaulin --verbose --all-features --workspace --timeout 120 \ No newline at end of file diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 0000000..70deaf0 --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,25 @@ +name: coverage + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +env: + CARGO_TERM_COLOR: always + +jobs: + test: + 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 + run: | + cargo +nightly tarpaulin --verbose --all-features --workspace --timeout 120 \ No newline at end of file From 797ac84f7a6ac79c32ab1a2250e48a5c6f11190c Mon Sep 17 00:00:00 2001 From: mkbeh Date: Fri, 28 Feb 2025 20:33:35 +0300 Subject: [PATCH 03/12] ci: test cov pipe --- .github/workflows/ci.yml | 2 +- .github/workflows/coverage.yml | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3923eb1..3a4cc3c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: Rust +name: build and test on: push: diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 70deaf0..f8d076b 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -21,5 +21,7 @@ jobs: uses: actions/checkout@v2 - name: Generate code coverage + env: + JWT_SECRET: ${{ secrets.JWT_SECRET }} run: | cargo +nightly tarpaulin --verbose --all-features --workspace --timeout 120 \ No newline at end of file From 10bf6dfb1a7cf239d92f2279d56ba9ddf0d7e5ee Mon Sep 17 00:00:00 2001 From: mkbeh Date: Fri, 28 Feb 2025 20:49:31 +0300 Subject: [PATCH 04/12] ci: test cov pipe --- .github/workflows/ci.yml | 46 +++++++++++++++++++++++++++------- .github/workflows/coverage.yml | 27 -------------------- 2 files changed, 37 insertions(+), 36 deletions(-) delete mode 100644 .github/workflows/coverage.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3a4cc3c..4cc708d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,10 +1,14 @@ name: build and test on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] + workflow_run: + workflows: [ "build" ] + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + types: + - completed env: CARGO_TERM_COLOR: always @@ -17,13 +21,37 @@ jobs: uses: actions/checkout@v2 - name: Build - run: cargo build --verbose + run: | + cargo build --verbose + + test: + needs: [ "build" ] + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'success' }} + 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 + if: ${{ github.event.workflow_run.conclusion == 'success' }} + steps: + - name: Checkout repository + uses: actions/checkout@v2 -# - name: Generate code coverage -# run: | -# cargo +nightly tarpaulin --verbose --all-features --workspace --timeout 120 \ No newline at end of file + - name: Generate code coverage + env: + JWT_SECRET: ${{ secrets.JWT_SECRET }} + run: | + cargo +nightly tarpaulin --verbose --all-features --workspace --timeout 120 \ No newline at end of file diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml deleted file mode 100644 index f8d076b..0000000 --- a/.github/workflows/coverage.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: coverage - -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - -env: - CARGO_TERM_COLOR: always - -jobs: - test: - 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 \ No newline at end of file From ecd775813a9574c6e2d48e7309d9a5d7bab617a8 Mon Sep 17 00:00:00 2001 From: mkbeh Date: Fri, 28 Feb 2025 20:51:34 +0300 Subject: [PATCH 05/12] ci: test cov pipe --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4cc708d..2128acc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: build and test +name: build on: workflow_run: From 178e2a6df473a615df3cf19c14c84344abbcf3d1 Mon Sep 17 00:00:00 2001 From: mkbeh Date: Fri, 28 Feb 2025 20:53:23 +0300 Subject: [PATCH 06/12] ci: test cov pipe --- .github/workflows/ci.yml | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2128acc..88b1e2e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,14 +1,10 @@ -name: build +name: build and test on: - workflow_run: - workflows: [ "build" ] - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - types: - - completed + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] env: CARGO_TERM_COLOR: always From d93166e68c6d2b9a1020676c0307f60c9257f2a9 Mon Sep 17 00:00:00 2001 From: mkbeh Date: Fri, 28 Feb 2025 20:55:30 +0300 Subject: [PATCH 07/12] ci: test cov pipe --- .github/workflows/ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 88b1e2e..9c15558 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,6 @@ jobs: test: needs: [ "build" ] runs-on: ubuntu-latest - if: ${{ github.event.workflow_run.conclusion == 'success' }} steps: - name: Checkout repository uses: actions/checkout@v2 @@ -41,7 +40,6 @@ jobs: container: image: xd009642/tarpaulin:develop-nightly options: --security-opt seccomp=unconfined - if: ${{ github.event.workflow_run.conclusion == 'success' }} steps: - name: Checkout repository uses: actions/checkout@v2 From 09f41d9edcca52888ed84cd0ec9b0722747234cb Mon Sep 17 00:00:00 2001 From: mkbeh Date: Fri, 28 Feb 2025 21:03:53 +0300 Subject: [PATCH 08/12] ci: test cov pipe --- .github/workflows/ci.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9c15558..a77e6f9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,6 +10,16 @@ env: CARGO_TERM_COLOR: always jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Lint + run: | + cargo clippy + build: runs-on: ubuntu-latest steps: From 93365283f524b9420ecf62e1cfd10be689dcac3f Mon Sep 17 00:00:00 2001 From: mkbeh Date: Fri, 28 Feb 2025 21:04:42 +0300 Subject: [PATCH 09/12] ci: test cov pipe --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a77e6f9..5e831e7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,6 +21,7 @@ jobs: cargo clippy build: + needs: [ "lint" ] runs-on: ubuntu-latest steps: - name: Checkout repository From 72dbdeb28e0dccc8c8e8bbb3252605638cd196a2 Mon Sep 17 00:00:00 2001 From: mkbeh Date: Fri, 28 Feb 2025 21:10:23 +0300 Subject: [PATCH 10/12] ci: test cov pipe --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5e831e7..9add48b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ jobs: - name: Lint run: | - cargo clippy + cargo clippy -- -D warnings build: needs: [ "lint" ] From 4c183fa8d8c4fa5e41693b404dd1cc63e53f4474 Mon Sep 17 00:00:00 2001 From: mkbeh Date: Fri, 28 Feb 2025 22:08:37 +0300 Subject: [PATCH 11/12] build: fix linting --- src/api/query.rs | 4 ++-- src/api/v1/list_messages.rs | 2 +- src/api/v1/login.rs | 2 +- src/api/v1/post_message.rs | 2 +- src/core_utils/closer.rs | 6 ++++++ src/core_utils/postgres_pool.rs | 18 +++++++++--------- src/core_utils/swagger.rs | 7 ++----- src/infra/repositories/messages.rs | 5 +---- 8 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/api/query.rs b/src/api/query.rs index a9786c0..f8f70ae 100644 --- a/src/api/query.rs +++ b/src/api/query.rs @@ -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) } } diff --git a/src/api/v1/list_messages.rs b/src/api/v1/list_messages.rs index 2a3fb65..1dc8cfa 100644 --- a/src/api/v1/list_messages.rs +++ b/src/api/v1/list_messages.rs @@ -82,7 +82,7 @@ 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![]; diff --git a/src/api/v1/login.rs b/src/api/v1/login.rs index 278c2fc..36c7077 100644 --- a/src/api/v1/login.rs +++ b/src/api/v1/login.rs @@ -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()); } } diff --git a/src/api/v1/post_message.rs b/src/api/v1/post_message.rs index 9de15d8..61937b9 100644 --- a/src/api/v1/post_message.rs +++ b/src/api/v1/post_message.rs @@ -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) })); diff --git a/src/core_utils/closer.rs b/src/core_utils/closer.rs index ed8599a..c1909c3 100644 --- a/src/core_utils/closer.rs +++ b/src/core_utils/closer.rs @@ -4,6 +4,12 @@ pub struct Closer<'a> { closers: Vec>, } +impl Default for Closer<'_> { + fn default() -> Self { + Self::new() + } +} + impl<'a> Closer<'a> { pub fn new() -> Closer<'a> { Closer { closers: vec![] } diff --git a/src/core_utils/postgres_pool.rs b/src/core_utils/postgres_pool.rs index 6761c82..269a082 100644 --- a/src/core_utils/postgres_pool.rs +++ b/src/core_utils/postgres_pool.rs @@ -52,16 +52,16 @@ 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( - >::into(config.connect_timeout), + conn_opts.connect_timeout = Some(>::into( + config.connect_timeout, )); conn_opts.keepalives = Some(config.keepalives); - conn_opts.keepalives_idle = Some(Duration::from( - >::into(config.keepalives_idle), + conn_opts.keepalives_idle = Some(>::into( + config.keepalives_idle, )); conn_opts.target_session_attrs = Some(config.get_target_session_attrs()); conn_opts.manager = Some(deadpool_postgres::ManagerConfig { @@ -69,11 +69,11 @@ pub fn build_pool_from_config( }); conn_opts.pool = Some(deadpool_postgres::PoolConfig { timeouts: deadpool_postgres::Timeouts { - wait: Some(Duration::from( - >::into(config.wait_timeout), + wait: Some(>::into( + config.wait_timeout, )), - create: Some(Duration::from( - >::into(config.create_timeout), + create: Some(>::into( + config.create_timeout, )), ..Default::default() }, diff --git a/src/core_utils/swagger.rs b/src/core_utils/swagger.rs index feafeba..6f8dd71 100644 --- a/src/core_utils/swagger.rs +++ b/src/core_utils/swagger.rs @@ -17,7 +17,6 @@ pub fn get_openapi_router(router: OpenApiRouter) -> Router { (url = "http://localhost:9000", description = "local") ) )] - struct ApiDoc; pub struct SecurityAddon; @@ -42,7 +41,7 @@ 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 @@ -50,7 +49,5 @@ pub fn get_openapi_router(router: OpenApiRouter) -> Router { .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)) } diff --git a/src/infra/repositories/messages.rs b/src/infra/repositories/messages.rs index 48c3b9a..8ca33f0 100644 --- a/src/infra/repositories/messages.rs +++ b/src/infra/repositories/messages.rs @@ -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()) } } From 9412b3cba5fa8170b64d4273506573a58c286a26 Mon Sep 17 00:00:00 2001 From: mkbeh Date: Fri, 28 Feb 2025 22:16:39 +0300 Subject: [PATCH 12/12] build: fix linting --- src/api/v1/list_messages.rs | 7 ++----- src/bin/chat/entrypoint.rs | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/api/v1/list_messages.rs b/src/api/v1/list_messages.rs index 1dc8cfa..dbc940c 100644 --- a/src/api/v1/list_messages.rs +++ b/src/api/v1/list_messages.rs @@ -85,15 +85,12 @@ mod tests { 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) + }]) }) }); diff --git a/src/bin/chat/entrypoint.rs b/src/bin/chat/entrypoint.rs index 512ffdd..696ac3d 100644 --- a/src/bin/chat/entrypoint.rs +++ b/src/bin/chat/entrypoint.rs @@ -13,7 +13,7 @@ pub struct Entrypoint<'a> { closer: Closer<'a>, } -impl<'a> Entrypoint<'_> { +impl Entrypoint<'_> { pub fn new(config: Config) -> Self { Self { config,