Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .codecov.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# https://docs.codecov.com/docs/codecovyml-reference
# curl -X POST --data-binary @.codecov.yaml https://codecov.io/validate
coverage:
status:
patch:
default:
target: 100%
threshold: 0%
informational: true
9 changes: 7 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@ jobs:
RUST_BACKTRACE: full
run: |
mkdir -p tests/.tmp
cargo llvm-cov --codecov --output-path target/llvm-cov-target/codecov.json -- --nocapture
cargo llvm-cov \
--ignore-filename-regex "bin/.*|lib\.rs" \
--cobertura \
--output-path target/llvm-cov-target/cobertura.xml \
-- \
--nocapture
- name: Upload to codecov.io
uses: codecov/codecov-action@v5
with:
fail_ci_if_error: true
files: target/llvm-cov-target/codecov.json
files: target/llvm-cov-target/cobertura.xml
verbose: true
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[![orcapod API docs](https://img.shields.io/website?url=https://walkerlab.github.io/orcapod/&label=docs)
](https://walkerlab.github.io/orcapod/)
[![codecov](https://codecov.io/github/walkerlab/orcapod/graph/badge.svg)](https://codecov.io/github/walkerlab/orcapod)

# orcapod

Expand All @@ -9,12 +10,13 @@

```bash
#!/bin/bash
set -e # stop early on non-zero exit
set -e # fail early on non-zero exit
cargo clippy --all-targets -- -D warnings # syntax and style tests
cargo fmt --check # formatting test
cargo llvm-cov -- --nocapture # integration tests w/ stdout coverage summary
cargo llvm-cov --html -- --nocapture # integration tests w/ HTML coverage report (target/llvm-cov/html/index.html)
cargo llvm-cov --codecov --output-path target/llvm-cov-target/codecov.json -- --nocapture # integration tests w/ coverage report prepared for codecov
cargo llvm-cov --ignore-filename-regex "bin/.*|lib\.rs" -- --nocapture # integration tests w/ stdout coverage summary
cargo llvm-cov --ignore-filename-regex "bin/.*|lib\.rs" --html -- --nocapture # integration tests w/ HTML coverage report (target/llvm-cov/html/index.html)
cargo llvm-cov --ignore-filename-regex "bin/.*|lib\.rs" --codecov --output-path target/llvm-cov-target/codecov.json -- --nocapture # integration tests w/ codecov coverage report
cargo llvm-cov --ignore-filename-regex "bin/.*|lib\.rs" --cobertura --output-path target/llvm-cov-target/cobertura.xml -- --nocapture # integration tests w/ cobertura coverage report
```

## Docs
Expand Down
67 changes: 53 additions & 14 deletions tests/error.rs
Original file line number Diff line number Diff line change
@@ -1,51 +1,90 @@
#![expect(missing_docs, clippy::expect_used, reason = "OK in tests.")]
#![expect(missing_docs, clippy::panic_in_result_fn, reason = "OK in tests.")]

pub mod fixture;
use fixture::{NAMESPACE_LOOKUP_READ_ONLY, pod_job_style};
use glob::glob;
use orcapod::uniffi::{
error::{OrcaError, Result},
orchestrator::{Orchestrator as _, docker::LocalDockerOrchestrator},
use orcapod::{
core::crypto::hash_file,
uniffi::{
error::{OrcaError, Result},
orchestrator::{Orchestrator as _, docker::LocalDockerOrchestrator},
},
};
use serde_json;
use serde_yaml;
use std::{collections::HashMap, fmt, fs, path::PathBuf, result};
use std::{collections::HashMap, fs, path::PathBuf};

fn check<A: fmt::Debug, B: Into<OrcaError>>(value: result::Result<A, B>) -> String {
let error: OrcaError = value.expect_err("Did not return an expected error.").into();
format!("{error:?}")
fn contains_debug(error: impl Into<OrcaError>) -> bool {
!format!("{:?}", error.into()).is_empty()
}

#[test]
fn external_bollard() -> Result<()> {
let orch = LocalDockerOrchestrator::new()?;
let mut pod_job = pod_job_style(&NAMESPACE_LOOKUP_READ_ONLY)?;
pod_job.pod.image = "nonexistent_image".to_owned();
check(orch.start_blocking(&NAMESPACE_LOOKUP_READ_ONLY, &pod_job));
assert!(
orch.start_blocking(&NAMESPACE_LOOKUP_READ_ONLY, &pod_job)
.is_err_and(contains_debug),
"Did not raise a bollard error."
);
Ok(())
}

#[test]
fn external_glob() {
check(glob("a**/b"));
assert!(
glob("a**/b").is_err_and(contains_debug),
"Did not raise a glob error."
);
}

#[test]
fn external_io() {
check(fs::read_to_string("nonexistent_file.txt"));
assert!(
fs::read_to_string("nonexistent_file.txt").is_err_and(contains_debug),
"Did not raise an I/O error."
);
}

#[test]
fn external_path_prefix() {
check(PathBuf::from("/fake/path").strip_prefix("/missing/path"));
assert!(
PathBuf::from("/fake/path")
.strip_prefix("/missing/path")
.is_err_and(contains_debug),
"Did not raise a path prefix error."
);
}

#[test]
fn external_json() {
check(serde_json::from_str::<HashMap<String, String>>("{"));
assert!(
serde_json::from_str::<HashMap<String, String>>("{").is_err_and(contains_debug),
"Did not raise a serde json error."
);
}

#[test]
fn external_yaml() {
check(serde_yaml::from_str::<HashMap<String, String>>(":"));
assert!(
serde_yaml::from_str::<HashMap<String, String>>(":").is_err_and(contains_debug),
"Did not raise a serde yaml error."
);
}

#[test]
fn internal_invalid_filepath() {
assert!(
hash_file("nonexistent_file.txt").is_err_and(contains_debug),
"Did not raise an invalid filepath error."
);
}

#[test]
fn internal_key_missing() {
assert!(
pod_job_style(&HashMap::new()).is_err_and(contains_debug),
"Did not raise a key missing error."
);
}
12 changes: 3 additions & 9 deletions tests/orchestrator.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
#![expect(
clippy::expect_used,
missing_docs,
clippy::panic_in_result_fn,
reason = "OK in tests."
)]
#![expect(missing_docs, clippy::panic_in_result_fn, reason = "OK in tests.")]

pub mod fixture;
use fixture::{TestContainerImage, TestDirs, container_image_style, pod_job_style};
Expand Down Expand Up @@ -75,9 +70,8 @@ where
assert!(
orchestrator
.get_info_blocking(&pod_run)
.expect_err("Unexpectedly succeeded.")
.is_purged_pod_run(),
"Returned a different OrcaError than one expected when getting info of a purged pod run."
.is_err_and(|error| error.is_purged_pod_run() && !format!("{error:?}").is_empty()),
"Did not raise a purged pod run error."
);
Ok(())
}
Expand Down
5 changes: 2 additions & 3 deletions tests/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,8 @@ fn pod_annotation_delete() -> Result<()> {
assert!(
store
.delete_annotation::<Pod>("style-transfer", "9.9.9")
.expect_err("Unexpectedly succeeded.")
.is_invalid_annotation(),
"Returned a different OrcaError than one expected when deleting an invalid annotation."
.is_err_and(|error| error.is_invalid_annotation() && !format!("{error:?}").is_empty()),
"Did not raise an invalid annotation error."
);
Ok(())
}
Expand Down