Skip to content

Commit

Permalink
Added CI for running unit tests. (#112)
Browse files Browse the repository at this point in the history
* Added CI for running unit tests.

Signed-off-by: dblock <[email protected]>

* Rename integration to _integration.

Signed-off-by: dblock <[email protected]>

* Added unittest target to Makefile with code coverage.

Signed-off-by: dblock <[email protected]>

---------

Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock authored Feb 1, 2023
1 parent ec224bf commit 215aa45
Show file tree
Hide file tree
Showing 15 changed files with 65 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/changelog_verifier.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: "Changelog Verifier"
name: Changelog Verifier

on:
pull_request:
types: [opened, edited, review_requested, synchronize, reopened, ready_for_review, labeled, unlabeled]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/clippy_check.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
on: push
name: Clippy check
name: Clippy Check
jobs:
clippy_check:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/delete_backport_branch.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Delete merged branch of the backport PRs
name: Delete Merged Branch of the Backport PRs
on:
pull_request:
types:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dependabot_pr.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Dependabot PR actions
name: Dependabot PR Actions
on:
pull_request:
types:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/test-integrations-unreleased.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name: Integration with Unreleased OpenSearch
name: Integration Tests with Unreleased OpenSearch

on: [push, pull_request]

jobs:
test:
name: Test
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test-integrations.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Integration tests
name: Integration Tests

on: [push, pull_request]

Expand All @@ -17,6 +17,7 @@ jobs:
- { version: '1.2.4' }
- { version: '1.3.4' }
- { version: '2.2.0' }
- { version: '2.4.0' }
secured: ["true", "false"]

steps:
Expand All @@ -28,11 +29,10 @@ jobs:
sudo sysctl -w vm.swappiness=1
sudo sysctl -w fs.file-max=262144
sudo sysctl -w vm.max_map_count=262144
- name: Install latest nightly
- name: Install latest stable toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
toolchain: stable
components: rustfmt, clippy
- name: Integ OpenSearch ${{ matrix.entry.version }} secured=${{ matrix.secured }}
run: "./.ci/run-tests opensearch ${{ matrix.entry.version }} ${{ matrix.secured }}"
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Unit Tests
on: [push, pull_request]
jobs:
tests:
name: Test
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install latest stable toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: rustfmt, clippy, llvm-tools-preview
- name: Setup Tools
run: cargo install grcov cargo-make
- name: Run Tests
run: |
cargo make unittest
- name: Upload Coverage Data
uses: codecov/codecov-action@v3
with:
files: ./test_results/opensearch.lcov
flags: unit
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

### Added
- Adds Github workflow for changelog verification ([#89](https://github.com/opensearch-project/opensearch-rs/pull/89))
- Adds Github workflow for unit tests ([#112](https://github.com/opensearch-project/opensearch-rs/pull/112))

### Dependencies
- Bumps `simple_logger` from 2.3.0 to 4.0.0
Expand Down
14 changes: 13 additions & 1 deletion Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ category = "OpenSearch"
private = true
condition = { env_set = [ "OPENSEARCH_URL" ]}
command = "cargo"
args = ["test", "-p", "opensearch"]
args = ["test", "--features", "_integration", "-p", "opensearch"]
dependencies = ["start-opensearch"]

[tasks.run-api-generator]
Expand Down Expand Up @@ -154,6 +154,18 @@ description = "Runs opensearch package tests against a given OpenSearch version"
dependencies = ["test-opensearch"]
run_task = "stop-opensearch"

[tasks.run-unittest]
private = true
command = "cargo"
args = ["test"]

[tasks.unittest]
category = "OpenSearch"
clear = true
description = "Runs workspace unit tests"
dependencies = ["set-coverage-vars", "create-test-results-dir", "run-unittest"]
run_task = "convert-coverage-data"

[tasks.generate-yaml-tests]
category = "OpenSearch"
description = "Generates OpenSearch client tests from YAML tests"
Expand Down
3 changes: 3 additions & 0 deletions opensearch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ rustls-tls = ["reqwest/rustls-tls"]
# AWS SigV4 Auth support
aws-auth = ["aws-credential-types", "aws-sigv4", "aws-types"]

# Integration tests against an actual instance of OpenSearch
_integration = []

[dependencies]
base64 = "^0.21"
bytes = "^1.0"
Expand Down
7 changes: 6 additions & 1 deletion opensearch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,19 +340,24 @@
//! ```
//!
//! ```rust,no_run
//! # use aws_config::meta::region::RegionProviderChain;
//! # use opensearch::{
//! # auth::Credentials,
//! # Error, OpenSearch,
//! # http::transport::{TransportBuilder,SingleNodeConnectionPool},
//! # };
//! # use url::Url;
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! # use std::convert::TryInto;
//! # #[tokio::main]
//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let creds = aws_config::load_from_env().await;
//! let url = Url::parse("https://example.com")?;
//! let conn_pool = SingleNodeConnectionPool::new(url);
//! # #[cfg(feature = "aws-auth")] {
//! let transport = TransportBuilder::new(conn_pool)
//! .auth(creds.try_into()?).build()?;
//! let client = OpenSearch::new(transport);
//! # }
//! # Ok(())
//! # }
//! ```
Expand Down
2 changes: 1 addition & 1 deletion opensearch/tests/cert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
//!
//!
//! DETACH=true .ci/run-opensearch.sh
#![cfg(any(feature = "native-tls", feature = "rustls-tls"))]
#![cfg(all(feature = "_integration", any(feature = "native-tls", feature = "rustls-tls")))]

pub mod common;
use common::*;
Expand Down
1 change: 1 addition & 0 deletions opensearch/tests/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/
#![cfg(feature = "_integration")]

pub mod common;
use common::*;
Expand Down
2 changes: 2 additions & 0 deletions opensearch/tests/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
* GitHub history for details.
*/

#![cfg(feature = "_integration")]

pub mod common;
use common::*;

Expand Down
2 changes: 1 addition & 1 deletion yaml_test_runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ serde_yaml = "0.9"
serde_json = { version = "~1", features = ["arbitrary_precision"] }
simple_logger = "4.0.0"
syn = { version = "~1.0", features = ["full"] }
sysinfo = "0.26"
sysinfo = "0.26.4"
url = "2.1.1"
yaml-rust = "0.4.3"
tar = "~0.4"
Expand Down

0 comments on commit 215aa45

Please sign in to comment.