Skip to content

Commit

Permalink
tests: upgraded tarpaulin and added derive macro coverage
Browse files Browse the repository at this point in the history
Upgraded tarpaulin to new the new maintainer, added coverage for derive
macro, and added an example.

Fixes: #1144

Signed-off-by: tyrone-wu <[email protected]>
  • Loading branch information
tyrone-wu committed Apr 11, 2024
1 parent bf62f56 commit 7444aae
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 20 deletions.
21 changes: 12 additions & 9 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
# - name: Install tarpaulin
# uses: taiki-e/install-action@v2
# with:
# tool: cargo-tarpaulin
- name: Install tarpaulin # Use dev tarpaulin from git repo for now, until it's pushed to release
run: |
rustup run stable cargo install --git https://github.com/xd009642/tarpaulin.git cargo-tarpaulin
- uses: AbsaOSS/k3d-action@v2
name: "Create Single Cluster"
with:
Expand All @@ -31,8 +35,7 @@ jobs:
-p 10250:10250
--k3s-arg "--no-deploy=traefik,servicelb,metrics-server@server:*"
- name: Run cargo-tarpaulin
uses: actions-rs/[email protected]
with:
version: '0.18.5'
out-type: Xml
- uses: codecov/codecov-action@v3
run: |
rustup run stable cargo tarpaulin -o xml --skip-clean
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ k3d:
--k3s-arg "--disable=traefik,servicelb,metrics-server@server:*" \
--k3s-arg '--kubelet-arg=eviction-hard=imagefs.available<1%,nodefs.available<1%@agent:*' \
--k3s-arg '--kubelet-arg=eviction-minimum-reclaim=imagefs.available=1%,nodefs.available=1%@agent:*' \
--k3s-arg '--kube-apiserver-arg=feature-gates=WatchList=true'
--k3s-arg '--kube-apiserver-arg=feature-gates=WatchList=true@server:*'

## RELEASE RELATED

Expand Down
1 change: 1 addition & 0 deletions kube-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ schemars = { workspace = true, features = ["chrono"] }
chrono.workspace = true
trybuild.workspace = true
assert-json-diff.workspace = true
runtime-macros = { git = "https://github.com/tyrone-wu/runtime-macros.git" }
17 changes: 16 additions & 1 deletion kube-derive/src/custom_resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,9 @@ fn to_plural(word: &str) -> String {

#[cfg(test)]
mod tests {
use std::{env, fs};

use super::*;
// TODO Unit test `derive`

#[test]
fn test_parse_default() {
Expand All @@ -616,4 +617,18 @@ mod tests {
assert_eq!(kube_attrs.kind, "Foo".to_string());
assert!(kube_attrs.namespaced);
}

#[test]
fn test_derive_crd() {
let path = env::current_dir().unwrap().join("tests").join("crd_enum_test.rs");
let file = fs::File::open(path).unwrap();
runtime_macros::emulate_derive_macro_expansion(file, &[("CustomResource", derive)]).unwrap();

let path = env::current_dir()
.unwrap()
.join("tests")
.join("crd_schema_test.rs");
let file = fs::File::open(path).unwrap();
runtime_macros::emulate_derive_macro_expansion(file, &[("CustomResource", derive)]).unwrap();
}
}
15 changes: 6 additions & 9 deletions tarpaulin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,18 @@

[one_pass_coverage]
workspace = true
features = "kube/derive kube/runtime kube/ws"
all-features = true
color = "Always"
ignored = true
timeout = "600s"
exclude = ["e2e"]
# NB: proc macro code is not picked up by tarpaulin - so could maybe skip kube-derive completely
excluded_files = ["kube-derive/tests"]
include-tests = true
# NB: skipping Doctests because they are slow to build and generally marked no_run
run-types = ["Tests"]
ignore_tests = true

# We could potentially pass in examples here
# but: they don't help in covering kube-derive, and they force a full recompile
#[example_pass]
#features = "default"
#packages = ["kube-examples"]
#excluded_files = ["examples/"]
#example = ["crd_derive_schema"]
[example_pass]
packages = ["kube-examples"]
exclude-files = ["examples/"]
example = ["crd_derive_schema"]

0 comments on commit 7444aae

Please sign in to comment.