Skip to content

Commit d2d2447

Browse files
committed
tests: upgraded tarpaulin and added derive macro coverage
Upgraded tarpaulin to new the new maintainer, added coverage for derive macro, and added an example. Fixes: kube-rs#1144 Signed-off-by: tyrone-wu <[email protected]>
1 parent bf62f56 commit d2d2447

File tree

6 files changed

+41
-20
lines changed

6 files changed

+41
-20
lines changed

.github/workflows/coverage.yml

+14-8
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@ jobs:
1717
- name: Checkout
1818
uses: actions/checkout@v4
1919
- name: Install stable toolchain
20-
uses: actions-rs/toolchain@v1
21-
with:
22-
toolchain: stable
23-
override: true
20+
uses: dtolnay/rust-toolchain@stable
2421
- uses: Swatinem/rust-cache@v2
22+
# - name: Install tarpaulin
23+
# uses: taiki-e/install-action@v2
24+
# with:
25+
# tool: cargo-tarpaulin
26+
- name: Install tarpaulin # Use dev tarpaulin from git repo for now, until it's pushed to release
27+
run: |
28+
rustup run stable cargo install --git https://github.com/xd009642/tarpaulin.git cargo-tarpaulin
2529
- uses: AbsaOSS/k3d-action@v2
2630
name: "Create Single Cluster"
2731
with:
@@ -31,8 +35,10 @@ jobs:
3135
-p 10250:10250
3236
--k3s-arg "--no-deploy=traefik,servicelb,metrics-server@server:*"
3337
- name: Run cargo-tarpaulin
34-
uses: actions-rs/[email protected]
38+
run: |
39+
rustup run stable cargo tarpaulin -o xml --skip-clean
40+
- name: Upload coverage reports to Codecov
41+
uses: codecov/codecov-action@v4
3542
with:
36-
version: '0.18.5'
37-
out-type: Xml
38-
- uses: codecov/codecov-action@v3
43+
token: ${{ secrets.CODECOV_TOKEN }}
44+
fail_ci_if_error: true

justfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ k3d:
8888
--k3s-arg "--disable=traefik,servicelb,metrics-server@server:*" \
8989
--k3s-arg '--kubelet-arg=eviction-hard=imagefs.available<1%,nodefs.available<1%@agent:*' \
9090
--k3s-arg '--kubelet-arg=eviction-minimum-reclaim=imagefs.available=1%,nodefs.available=1%@agent:*' \
91-
--k3s-arg '--kube-apiserver-arg=feature-gates=WatchList=true'
91+
--k3s-arg '--kube-apiserver-arg=feature-gates=WatchList=true@server:*'
9292

9393
## RELEASE RELATED
9494

kube-derive/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ schemars = { workspace = true, features = ["chrono"] }
3333
chrono.workspace = true
3434
trybuild.workspace = true
3535
assert-json-diff.workspace = true
36+
runtime-macros = { git = "https://github.com/tyrone-wu/runtime-macros.git" }

kube-derive/src/custom_resource.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -599,8 +599,9 @@ fn to_plural(word: &str) -> String {
599599

600600
#[cfg(test)]
601601
mod tests {
602+
use std::{env, fs};
603+
602604
use super::*;
603-
// TODO Unit test `derive`
604605

605606
#[test]
606607
fn test_parse_default() {
@@ -616,4 +617,19 @@ mod tests {
616617
assert_eq!(kube_attrs.kind, "Foo".to_string());
617618
assert!(kube_attrs.namespaced);
618619
}
620+
621+
#[test]
622+
fn test_derive_crd() {
623+
let path = env::current_dir().unwrap()
624+
.join("tests")
625+
.join("crd_enum_test.rs");
626+
let file = fs::File::open(path).unwrap();
627+
runtime_macros::emulate_derive_macro_expansion(file, &[("CustomResource", derive)]).unwrap();
628+
629+
let path = env::current_dir().unwrap()
630+
.join("tests")
631+
.join("crd_schema_test.rs");
632+
let file = fs::File::open(path).unwrap();
633+
runtime_macros::emulate_derive_macro_expansion(file, &[("CustomResource", derive)]).unwrap();
634+
}
619635
}

kube-derive/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
//! A crate for kube's derive macros.
22
#![recursion_limit = "1024"]
33
extern crate proc_macro;
4-
#[macro_use] extern crate quote;
4+
#[macro_use]
5+
extern crate quote;
56

67
mod custom_resource;
78

tarpaulin.toml

+6-9
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,18 @@
77

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

2119
# We could potentially pass in examples here
2220
# but: they don't help in covering kube-derive, and they force a full recompile
23-
#[example_pass]
24-
#features = "default"
25-
#packages = ["kube-examples"]
26-
#excluded_files = ["examples/"]
27-
#example = ["crd_derive_schema"]
21+
[example_pass]
22+
packages = ["kube-examples"]
23+
exclude-files = ["examples/"]
24+
example = ["crd_derive_schema"]

0 commit comments

Comments
 (0)