Skip to content

Commit b883879

Browse files
committed
added tests using tarpaulin, fixed minor issues, updated README
1 parent 1db46ba commit b883879

7 files changed

Lines changed: 471 additions & 82 deletions

File tree

Cargo.lock

Lines changed: 66 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ url = "2.2"
1616
chrono = "0.4.38"
1717
clap = { version = "4.3.24", features = ["derive"] }
1818
dotenvy = "0.15.7"
19+
ctrlc = "3.5.1"
1920

2021
[build-dependencies]
2122
chrono = "0.4.31"

README.md

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,102 @@ n.b. to view command line options e.g. available settings for environment ("--en
143143
144144
The rust client can be configured to listen for any of the three content types below by setting the environment variable named "PT_SERVER_URL" to the URLs below in the relevant configuration file for development (".env.dev"), test (".env.test") or production (".env.prod").
145145
146-
N.B. Current Rust client only supports one of the three content types per installed Rust code (under /target/release/ folder).
146+
N.B. Current Rust client only supports one of the three content types per installed Rust code (under /target/release/ folder).
147147
Listening for more than one set of content from list below requires multiple copies of the Rust runtime files and a custom configuration per instance.
148148
149+
### Testing
150+
151+
The project includes comprehensive unit tests with **19.18% code coverage** (47/245 lines covered).
152+
153+
#### Running Tests
154+
155+
Run all tests with proper test isolation:
156+
```bash
157+
cargo test -- --test-threads=1
158+
```
159+
160+
Run tests with verbose output:
161+
```bash
162+
cargo test -- --test-threads=1 --nocapture
163+
```
164+
165+
Run a specific test:
166+
```bash
167+
cargo test test_from_env_success -- --nocapture
168+
```
169+
170+
Run tests for a specific module:
171+
```bash
172+
cargo test config::tests -- --test-threads=1
173+
```
174+
175+
#### Test Coverage
176+
177+
Generate a detailed coverage report using `cargo-tarpaulin`:
178+
179+
1. Install cargo-tarpaulin (one-time setup):
180+
```bash
181+
cargo install cargo-tarpaulin
182+
```
183+
184+
2. Generate coverage report:
185+
```bash
186+
cargo tarpaulin --verbose --timeout 120 -- --test-threads=1
187+
```
188+
189+
3. Generate HTML coverage report:
190+
```bash
191+
cargo tarpaulin --out Html --output-dir coverage -- --test-threads=1
192+
```
193+
Then open `coverage/index.html` in your browser.
194+
195+
#### Current Test Coverage
196+
197+
| Module | Coverage | Lines Covered |
198+
|--------|----------|---------------|
199+
| `src/config.rs` | 96.7% | 29/30 |
200+
| `src/utils/mod.rs` | 22.2% | 4/18 |
201+
| `src/websocket.rs` | 23.3% | 14/60 |
202+
| `src/error.rs` | 0% | 0/13 |
203+
| `src/logging.rs` | 0% | 0/17 |
204+
| `src/main.rs` | 0% | 0/107 |
205+
| **Overall** | **19.18%** | **47/245** |
206+
207+
#### Test Suites
208+
209+
**Configuration Tests** (13 tests)
210+
- Environment variable parsing and validation
211+
- Credential masking for security
212+
- Default value handling
213+
- Error handling for missing/invalid configuration
214+
215+
**JWT Generation Tests** (3 tests)
216+
- Invalid private key handling
217+
- Empty key validation
218+
- Malformed PEM format detection
219+
220+
**WebSocket Client Tests** (8 tests)
221+
- Configuration validation
222+
- URL format validation
223+
- Parameter validation (epoch count, sleep duration)
224+
225+
#### Code Quality
226+
227+
Run linting checks:
228+
```bash
229+
cargo clippy --all-targets --all-features -- -D warnings
230+
```
231+
232+
Format code:
233+
```bash
234+
cargo fmt
235+
```
236+
237+
Check formatting without making changes:
238+
```bash
239+
cargo fmt -- --check
240+
```
241+
149242
### Endpoint Links
150243

151244
#### _Balances & Positions_

0 commit comments

Comments
 (0)