From 7444aae66d272b29b7c4e50d04e4042a13a8adc5 Mon Sep 17 00:00:00 2001 From: tyrone-wu Date: Tue, 2 Apr 2024 22:26:47 +0000 Subject: [PATCH 1/2] 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: #1144 Signed-off-by: tyrone-wu --- .github/workflows/coverage.yml | 21 ++++++++++++--------- justfile | 2 +- kube-derive/Cargo.toml | 1 + kube-derive/src/custom_resource.rs | 17 ++++++++++++++++- tarpaulin.toml | 15 ++++++--------- 5 files changed, 36 insertions(+), 20 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index c9c71bc21..6dbccb87b 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -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: @@ -31,8 +35,7 @@ jobs: -p 10250:10250 --k3s-arg "--no-deploy=traefik,servicelb,metrics-server@server:*" - name: Run cargo-tarpaulin - uses: actions-rs/tarpaulin@v0.1 - 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 diff --git a/justfile b/justfile index eba15879b..4f33d6393 100644 --- a/justfile +++ b/justfile @@ -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 diff --git a/kube-derive/Cargo.toml b/kube-derive/Cargo.toml index fa43a8951..b7309bdfa 100644 --- a/kube-derive/Cargo.toml +++ b/kube-derive/Cargo.toml @@ -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" } diff --git a/kube-derive/src/custom_resource.rs b/kube-derive/src/custom_resource.rs index 891369bfc..3332b4558 100644 --- a/kube-derive/src/custom_resource.rs +++ b/kube-derive/src/custom_resource.rs @@ -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() { @@ -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(); + } } diff --git a/tarpaulin.toml b/tarpaulin.toml index 30bf94c4a..06571508b 100644 --- a/tarpaulin.toml +++ b/tarpaulin.toml @@ -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"] From 080943fd56a590fb910a826b521691a736e21f8d Mon Sep 17 00:00:00 2001 From: tyrone-wu Date: Fri, 12 Apr 2024 18:08:12 +0000 Subject: [PATCH 2/2] pin commit for git dependencies and appease deny.toml Signed-off-by: tyrone-wu --- .github/workflows/coverage.yml | 2 +- deny.toml | 2 +- kube-derive/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 6dbccb87b..cd6191c71 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -25,7 +25,7 @@ jobs: # 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 + rustup run stable cargo install --git https://github.com/xd009642/tarpaulin.git --rev 2b05ebd4f809eeeeb590f68efb8e62758eb59214 cargo-tarpaulin - uses: AbsaOSS/k3d-action@v2 name: "Create Single Cluster" with: diff --git a/deny.toml b/deny.toml index b8d32fdaa..1e1b71905 100644 --- a/deny.toml +++ b/deny.toml @@ -51,7 +51,7 @@ license-files = [ unknown-registry = "deny" unknown-git = "deny" allow-registry = ["https://github.com/rust-lang/crates.io-index"] -allow-git = [] +allow-git = ["https://github.com/tyrone-wu/runtime-macros.git"] [bans] multiple-versions = "deny" diff --git a/kube-derive/Cargo.toml b/kube-derive/Cargo.toml index b7309bdfa..0b89ea2f0 100644 --- a/kube-derive/Cargo.toml +++ b/kube-derive/Cargo.toml @@ -33,4 +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" } +runtime-macros = { git = "https://github.com/tyrone-wu/runtime-macros.git", rev = "e31f4de52e078d41aba4792a7ea30139606c1362" }