English | 简体中文
taos is the official Rust language connector of TDengine, through which Rust developers can develop applications that access TDengine databases. It supports data writing, data query, data subscription, schemaless writing, parameter binding and other functions.
libtaos.so)/etc/taos/taos.cfg configuration file and add the following configuration:supportVnodes 256
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env
git clone https://github.com/taosdata/taos-connector-rust.git
cd taos-connector-rust
cargo build
# Build with specific feature
cargo build -p taos --features ws # WebSocket only
cargo build -p taos --features native # Native only
Run the test by executing the following command in the project directory:
cargo test
# Optional: run only the main crate with a specific transport
cargo test -p taos --features ws
cargo test -p taos --features native
The test case will connect to the local TDengine server and taosAdapter for testing. After the test is completed, you will see a result summary similar to the following. If all test cases pass, the failed item should be 0:
test result: ok. 101 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 1.21s
Create a test module: In the .rs file that needs to be tested, add a module with the #[cfg(test)] attribute. This attribute ensures that the test code is only compiled when the test is executed.
#[cfg(test)]
mod tests {
// Write your test cases here
}
Import the contents of the module under test: In the test module, use use super::*; to import all the contents of the external module into the scope of the test module so that you can access the functions and structures that need to be tested.
#[cfg(test)]
mod tests {
use super::*;
// Write your test cases here
}
Write test functions: In the test module, define functions with the #[test] attribute. Each test function should contain the following steps:
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_add() {
let result = add(2, 3);
assert_eq!(result, 5);
}
}
In the above example, the assert_eq! macro is used to check if result is equal to the expected value 5. If not, the test will fail and panic.
Asynchronous function testing: For asynchronous functions, you can use the #[tokio::test] attribute macro to mark the test function and provide it with the Tokio asynchronous runtime.
#[cfg(test)]
mod tests {
use super::*;
use tokio;
#[tokio::test]
async fn test_async_function() {
let result = async_function().await;
assert_eq!(result, expected_value);
}
}
To enable asynchronous testing support, make sure to include the Tokio dependency in your Cargo.toml. You can choose the appropriate asynchronous runtime and corresponding test property macros based on your project needs.
Test panic cases: For functions that are expected to panic, you can use the #[should_panic] attribute. This attribute optionally accepts an expected parameter to specify the expected panic message.
#[cfg(test)]
mod tests {
use super::*;
#[test]
#[should_panic(expected = "Divide by zero error")]
fn test_divide_by_zero() {
divide(1, 0);
}
}
In this example, the divide function should panic when the denominator is zero, and the message should be "Divide by zero error".
Ignore specific tests: For tests that take a long time or are not run often, you can use the #[ignore] attribute to mark them. By default, these tests will not be run unless explicitly run with the cargo test -- --ignored command.
#[cfg(test)]
mod tests {
use super::*;
#[test]
#[ignore]
fn test_long_running() {
// Long-running test code
}
}
Performance testing is under development.
cargo build --release
# For publishing to crates.io:
cargo publish -p taos --dry-run
We welcome the submission of GitHub Issue. When submitting, please provide the following information:
We welcome developers to contribute to this project. When submitting PRs, please follow these steps:
git checkout -b my_branch). Do not modify the main branch directly.git push origin my_branch).Rust
98.4%
C
1.6%
English | 简体中文
taos is the official Rust language connector of TDengine, through which Rust developers can develop applications that access TDengine databases. It supports data writing, data query, data subscription, schemaless writing, parameter binding and other functions.
libtaos.so)/etc/taos/taos.cfg configuration file and add the following configuration:supportVnodes 256
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env
git clone https://github.com/taosdata/taos-connector-rust.git
cd taos-connector-rust
cargo build
# Build with specific feature
cargo build -p taos --features ws # WebSocket only
cargo build -p taos --features native # Native only
Run the test by executing the following command in the project directory:
cargo test
# Optional: run only the main crate with a specific transport
cargo test -p taos --features ws
cargo test -p taos --features native
The test case will connect to the local TDengine server and taosAdapter for testing. After the test is completed, you will see a result summary similar to the following. If all test cases pass, the failed item should be 0:
test result: ok. 101 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 1.21s
Create a test module: In the .rs file that needs to be tested, add a module with the #[cfg(test)] attribute. This attribute ensures that the test code is only compiled when the test is executed.
#[cfg(test)]
mod tests {
// Write your test cases here
}
Import the contents of the module under test: In the test module, use use super::*; to import all the contents of the external module into the scope of the test module so that you can access the functions and structures that need to be tested.
#[cfg(test)]
mod tests {
use super::*;
// Write your test cases here
}
Write test functions: In the test module, define functions with the #[test] attribute. Each test function should contain the following steps:
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_add() {
let result = add(2, 3);
assert_eq!(result, 5);
}
}
In the above example, the assert_eq! macro is used to check if result is equal to the expected value 5. If not, the test will fail and panic.
Asynchronous function testing: For asynchronous functions, you can use the #[tokio::test] attribute macro to mark the test function and provide it with the Tokio asynchronous runtime.
#[cfg(test)]
mod tests {
use super::*;
use tokio;
#[tokio::test]
async fn test_async_function() {
let result = async_function().await;
assert_eq!(result, expected_value);
}
}
To enable asynchronous testing support, make sure to include the Tokio dependency in your Cargo.toml. You can choose the appropriate asynchronous runtime and corresponding test property macros based on your project needs.
Test panic cases: For functions that are expected to panic, you can use the #[should_panic] attribute. This attribute optionally accepts an expected parameter to specify the expected panic message.
#[cfg(test)]
mod tests {
use super::*;
#[test]
#[should_panic(expected = "Divide by zero error")]
fn test_divide_by_zero() {
divide(1, 0);
}
}
In this example, the divide function should panic when the denominator is zero, and the message should be "Divide by zero error".
Ignore specific tests: For tests that take a long time or are not run often, you can use the #[ignore] attribute to mark them. By default, these tests will not be run unless explicitly run with the cargo test -- --ignored command.
#[cfg(test)]
mod tests {
use super::*;
#[test]
#[ignore]
fn test_long_running() {
// Long-running test code
}
}
Performance testing is under development.
cargo build --release
# For publishing to crates.io:
cargo publish -p taos --dry-run
We welcome the submission of GitHub Issue. When submitting, please provide the following information:
We welcome developers to contribute to this project. When submitting PRs, please follow these steps:
git checkout -b my_branch). Do not modify the main branch directly.git push origin my_branch).Rust
98.4%
C
1.6%