Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: upgraded tarpaulin and added derive macro coverage #1466

Merged
merged 2 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
clux marked this conversation as resolved.
Show resolved Hide resolved
- 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
clux marked this conversation as resolved.
Show resolved Hide resolved
- 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" }
clux marked this conversation as resolved.
Show resolved Hide resolved
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();
clux marked this conversation as resolved.
Show resolved Hide resolved

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"]
Loading