This is an automated email from the ASF dual-hosted git repository.
aaronai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-clients.git
The following commit(s) were added to refs/heads/master by this push:
new 585f93e7 ci(rust): add test coverage ci (#489)
585f93e7 is described below
commit 585f93e740098f23a5873499438e1876fe7cb89e
Author: SSpirits <[email protected]>
AuthorDate: Fri Apr 21 14:50:20 2023 +0800
ci(rust): add test coverage ci (#489)
* ci(rust): add test coverage ci
* ci(rust): use actions-rs/cargo install llvm-cov
* ci(rust): fix working directory
* ci(rust): optimize codecov
---
.codecov.yml | 4 +++
.github/workflows/rust_build.yml | 1 -
.github/workflows/rust_coverage.yaml | 47 ++++++++++++++++++++++++++++++++++++
rust/src/main.rs | 20 ---------------
rust/src/model/common.rs | 8 +++---
rust/src/producer.rs | 15 ++++++++----
rust/src/simple_consumer.rs | 4 +--
7 files changed, 67 insertions(+), 32 deletions(-)
diff --git a/.codecov.yml b/.codecov.yml
index 7794ca3c..12ab01f4 100644
--- a/.codecov.yml
+++ b/.codecov.yml
@@ -26,3 +26,7 @@ flags:
carryforward: true
paths:
- "golang/**"
+ rust:
+ carryforward: true
+ paths:
+ - "rust/**"
diff --git a/.github/workflows/rust_build.yml b/.github/workflows/rust_build.yml
index a37415f1..865ee881 100644
--- a/.github/workflows/rust_build.yml
+++ b/.github/workflows/rust_build.yml
@@ -23,7 +23,6 @@ jobs:
- name: Build
working-directory: ./rust
run: cargo build
-
- name: Unit Test
working-directory: ./rust
run: cargo test -- --nocapture
\ No newline at end of file
diff --git a/.github/workflows/rust_coverage.yaml
b/.github/workflows/rust_coverage.yaml
new file mode 100644
index 00000000..9d840818
--- /dev/null
+++ b/.github/workflows/rust_coverage.yaml
@@ -0,0 +1,47 @@
+name: Rust Coverage
+on:
+ pull_request:
+ types: [opened, reopened, synchronize]
+ paths:
+ - 'rust/**'
+ push:
+ branches:
+ - master
+jobs:
+ calculate-coverage:
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v2
+ with:
+ submodules: true
+
+ - name: Install rust toolchain
+ uses: actions-rs/toolchain@v1
+ with:
+ toolchain: stable
+ override: true
+
+ - name: Install Protoc
+ uses: arduino/setup-protoc@v1
+ with:
+ version: '3.x'
+ repo-token: ${{ secrets.GITHUB_TOKEN }}
+
+ - name: Install cargo-llvm-cov
+ uses: actions-rs/cargo@v1
+ with:
+ command: install
+ args: cargo-llvm-cov
+
+ - name: Generate code coverage
+ working-directory: ./rust
+ run: cargo llvm-cov --all-features --workspace --ignore-filename-regex
pb/ --codecov --output-path codecov.json
+
+ - name: Upload to codecov.io
+ uses: codecov/codecov-action@v3
+ with:
+ files: ./rust/codecov.json
+ flags: rust
+ verbose: true
+ fail_ci_if_error: true
diff --git a/rust/src/main.rs b/rust/src/main.rs
deleted file mode 100644
index d69ca788..00000000
--- a/rust/src/main.rs
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-fn main() {
- println!("Hello, world!");
-}
diff --git a/rust/src/model/common.rs b/rust/src/model/common.rs
index deaa1235..4ce209e2 100644
--- a/rust/src/model/common.rs
+++ b/rust/src/model/common.rs
@@ -199,8 +199,8 @@ pub enum FilterType {
/// Filter expression for message filtering.
pub struct FilterExpression {
- pub(crate) filter_type: FilterType,
- pub(crate) expression: String,
+ filter_type: FilterType,
+ expression: String,
}
impl FilterExpression {
@@ -231,8 +231,8 @@ impl FilterExpression {
/// Send result returned by producer.
#[derive(Clone, Debug)]
pub struct SendReceipt {
- pub(crate) message_id: String,
- pub(crate) transaction_id: String,
+ message_id: String,
+ transaction_id: String,
}
impl SendReceipt {
diff --git a/rust/src/producer.rs b/rust/src/producer.rs
index 8de941c8..be16c2cd 100644
--- a/rust/src/producer.rs
+++ b/rust/src/producer.rs
@@ -390,12 +390,15 @@ mod tests {
}))
});
producer.client.expect_send_message().returning(|_, _| {
- Ok(vec![SendReceipt {
- message_id: "".to_string(),
- transaction_id: "".to_string(),
- }])
+ Ok(vec![SendReceipt::from_pb_send_result(
+ &pb::SendResultEntry {
+ message_id: "message_id".to_string(),
+ transaction_id: "transaction_id".to_string(),
+ ..pb::SendResultEntry::default()
+ },
+ )])
});
- producer
+ let result = producer
.send_one(
MessageBuilder::builder()
.set_topic("test_topic")
@@ -404,6 +407,8 @@ mod tests {
.unwrap(),
)
.await?;
+ assert_eq!(result.message_id(), "message_id");
+ assert_eq!(result.transaction_id(), "transaction_id");
Ok(())
}
}
diff --git a/rust/src/simple_consumer.rs b/rust/src/simple_consumer.rs
index cf74e820..28e9d666 100644
--- a/rust/src/simple_consumer.rs
+++ b/rust/src/simple_consumer.rs
@@ -144,8 +144,8 @@ impl SimpleConsumer {
&endpoints,
message_queue,
pb::FilterExpression {
- r#type: expression.filter_type as i32,
- expression: expression.expression.clone(),
+ r#type: expression.filter_type() as i32,
+ expression: expression.expression().to_string(),
},
batch_size,
prost_types::Duration::try_from(invisible_duration).unwrap(),