diff --git a/.codecov.yml b/.codecov.yml index 7794ca3c5..12ab01f4d 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 a37415f17..865ee881b 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 000000000..9d840818f --- /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 d69ca788b..000000000 --- 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 deaa12350..4ce209e21 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 8de941c80..be16c2cde 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 cf74e8201..28e9d666a 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(),