Skip to content

Commit 53ad9ee

Browse files
authored
Unit/Integration CI test cleanup (#1143)
* Tweak integration tests to always run all ignored tests Also upgrade tarpaulin to see if there are any changes Signed-off-by: clux <[email protected]> * less recent tarpaulin... action seems abandoned Signed-off-by: clux <[email protected]> * fix doctests for remote_command Signed-off-by: clux <[email protected]> * different tarpaulin incantation Signed-off-by: clux <[email protected]> * make remote_command tests not ignored Signed-off-by: clux <[email protected]> * fix admission doc tests Signed-off-by: clux <[email protected]> * big test revamp Signed-off-by: clux <[email protected]> * revert most tarpaulin actions changes and limit rg check to ubuntu Signed-off-by: clux <[email protected]> * revert tarpaulin settings + run less stuff on windows windows build slow Signed-off-by: clux <[email protected]> * remove references to deprecated '--all' flag Signed-off-by: clux <[email protected]> * back to older tarpaulin for now.. Signed-off-by: clux <[email protected]> * also fix deprecation warning for gha set-output Signed-off-by: clux <[email protected]> * lol managed to screw up even that Signed-off-by: clux <[email protected]> * can use -j6 everywhere on ci Signed-off-by: clux <[email protected]> * avoid double ripgrep in release scripts Signed-off-by: clux <[email protected]> * dependencies link to tools Signed-off-by: clux <[email protected]> * use a more precise cargo tree Signed-off-by: clux <[email protected]> --------- Signed-off-by: clux <[email protected]>
1 parent 7e77855 commit 53ad9ee

File tree

12 files changed

+112
-73
lines changed

12 files changed

+112
-73
lines changed

.github/workflows/ci.yml

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -42,29 +42,28 @@ jobs:
4242
- name: Build workspace
4343
run: cargo build
4444

45-
# Workspace tests
46-
- name: Run workspace unit tests
47-
run: cargo test --lib --all -j6
48-
- name: Run workspace doc tests
49-
run: cargo test --doc --all -j6
50-
- name: Test examples
51-
run: cargo test -p kube-examples --examples -j6
52-
- name: Compile check remaining examples
53-
# No OS specific code in examples, run this on fastest executor
45+
# Workspace unit tests with various feature sets
46+
- name: Run workspace unit tests (no default features)
47+
run: cargo test --workspace --lib --no-default-features -j6
5448
if: matrix.os == 'ubuntu-latest'
55-
run: cargo build -j4 -p kube-examples
56-
57-
# Feature tests
58-
- name: Test kube with features rustls-tls,ws,oauth
59-
run: cargo test -p kube --lib --no-default-features --features=rustls-tls,ws,oauth
49+
- name: Run workspace unit tests (default features)
50+
run: cargo test --workspace --lib --exclude kube-examples --exclude e2e -j6
6051
if: matrix.os == 'ubuntu-latest'
61-
- name: Test kube with features openssl-tls,ws,oauth
62-
run: cargo test -p kube --lib --no-default-features --features=openssl-tls,ws,oauth
63-
if: matrix.os == 'ubuntu-latest'
64-
# Feature tests in examples
65-
- name: Test crd_derive_no_schema example
66-
run: cargo test -p kube-examples --example crd_derive_no_schema --no-default-features --features=openssl-tls,latest
52+
- name: Run workspace unit tests (all features)
53+
run: cargo test --workspace --lib --all-features --exclude kube-examples --exclude e2e -j6
54+
# Workspace documentation (all features only)
55+
- name: Run workspace doc tests
56+
run: cargo test --workspace --doc --all-features --exclude kube-examples --exclude e2e -j6
57+
- name: Run ad-hoc doc test verification
58+
run: |
59+
if rg "\`\`\`ignored"; then
60+
echo "ignored doctests are not allowed, use compile_fail or no_run"
61+
exit 1
62+
fi
6763
if: matrix.os == 'ubuntu-latest'
64+
# Examples
65+
- name: Test examples
66+
run: cargo test -p kube-examples --examples -j6
6867

6968
msrv:
7069
# Run `cargo check` on our minimum supported Rust version
@@ -76,7 +75,7 @@ jobs:
7675
run: |
7776
MSRV=$(grep MSRV README.md | grep -oE "[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+")
7877
echo $MSRV
79-
echo ::set-output name=msrv::${MSRV}
78+
echo "msrv=${MSRV}" >> $GITHUB_OUTPUT
8079
- uses: actions-rs/toolchain@v1
8180
with:
8281
toolchain: ${{ steps.msrv.outputs.msrv }}
@@ -87,7 +86,7 @@ jobs:
8786
uses: actions-rs/cargo@v1
8887
with:
8988
command: check
90-
args: --all
89+
args: --workspace
9190

9291
- name: Check rust-version keys matches MSRV consistently
9392
run: |
@@ -148,18 +147,12 @@ jobs:
148147
run: cargo build
149148

150149
# Run the equivalent of `just integration`
151-
- name: Run all default features integration library tests
152-
run: cargo test --lib --all -- --ignored
153-
- name: Run all facade integration library tests with extra features
154-
run: cargo test -p kube --lib --features=derive,runtime -- --ignored --nocapture
150+
- name: Run all integration library tests
151+
run: cargo test --lib --workspace --exclude e2e --all-features -j6 -- --ignored
155152
- name: Run crd example tests
156153
run: cargo run -p kube-examples --example crd_api
157-
- name: Run all client integration library tests with rustls and ws
158-
run: cargo test -p kube-client --lib --features=rustls-tls,ws -- --ignored
159154
- name: Run derive example tests
160155
run: cargo run -p kube-examples --example crd_derive
161-
- name: Run crd example tests
162-
run: cargo run -p kube-examples --example crd_api
163156

164157
mk8sv:
165158
# comile check e2e tests against mk8sv
@@ -172,8 +165,8 @@ jobs:
172165
run: |
173166
MK8SV=$(grep MK8SV README.md | grep -oE "[[:digit:]]+\.[[:digit:]]+" | head -n 1)
174167
echo $MK8SV
175-
echo ::set-output name=mk8sv::${MK8SV}
176-
echo ::set-output name=mk8svdash::v${MK8SV/\./_}
168+
echo "mk8sv=${MK8SV}" >> $GITHUB_OUTPUT
169+
echo "mk8svdash=v${MK8SV/\./_}" >> $GITHUB_OUTPUT
177170
178171
- name: Check ci jobs run against advertised MK8SV
179172
run: |

.github/workflows/rustfmt.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# When pushed to main, run `cargo +nightly fmt --all` and open a PR.
1+
# When pushed to main, run `cargo +nightly fmt` against all files and open a PR.
22
name: rustfmt
33
on:
44
push:

CONTRIBUTING.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ The easiest way set up a minimal Kubernetes cluster for these is with [`k3d`](ht
4545

4646
### Unit Tests & Documentation Tests
4747

48-
**Most** unit/doc tests are run from `cargo test --lib --doc --all`, but because of feature-sets, and examples, you will need a couple of extra invocations to replicate our CI.
48+
Unit and doc tests are run against a particular crate with `cargo test -p KUBECRATE --lib --doc`, but because of feature-sets, you will need a couple of extra flags and invocations to replicate all our CI conditions.
4949

50-
For the complete variations, run the `just test` target in the `justfile`.
50+
To run **all** unit tests, call: `just test`
5151

5252
All public interfaces must be documented, and most should have minor documentation examples to show usage.
5353

@@ -57,7 +57,9 @@ Slower set of tests within the crates marked with an **`#[ignore]`** attribute.
5757

5858
:warning: These **WILL** try to modify resources in your current cluster :warning:
5959

60-
Most integration tests are run with `cargo test --all --lib -- --ignored`, but because of feature-sets, you will need a few invocations of these to replicate our CI. See `just test-integration`
60+
Integration tests are run against a crate with `cargo test -p KUBECRATE --lib -- --ignored`, but because of feature-sets, you will need a few invocations of these to replicate our CI.
61+
62+
To run **all** integration tests, call: `just test-integration`
6163

6264
### End to End Tests
6365

@@ -75,7 +77,7 @@ All public interfaces should have doc tests with examples for [docs.rs](https://
7577

7678
When adding new non-trivial pieces of logic that results in a drop in coverage you should add a test.
7779

78-
Cross-reference with the coverage build [![coverage build](https://codecov.io/gh/kube-rs/kube/branch/main/graph/badge.svg?token=9FCqEcyDTZ)](https://codecov.io/gh/kube-rs/kube) and go to your branch. Coverage can also be run locally with [`cargo tarpaulin`](https://github.com/xd009642/tarpaulin) at project root. This will use our [tarpaulin.toml](https://github.com/kube-rs/kube/blob/main/tarpaulin.toml) config, and **will run both unit and integration** tests.
80+
Cross-reference with the coverage build [![coverage build](https://codecov.io/gh/kube-rs/kube/branch/main/graph/badge.svg?token=9FCqEcyDTZ)](https://app.codecov.io/gh/kube-rs/kube/tree/main) and go to your branch. Coverage can also be run locally with [`cargo tarpaulin`](https://github.com/xd009642/tarpaulin) at project root. This will use our [tarpaulin.toml](https://github.com/kube-rs/kube/blob/main/tarpaulin.toml) config, and **will run both unit and integration** tests.
7981

8082
#### What type of test
8183

justfile

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
VERSION := `git rev-parse HEAD`
2+
open := if os() == "macos" { "open" } else { "xdg-open" }
23

34
[private]
45
default:
@@ -22,25 +23,31 @@ deny:
2223

2324
# Unit tests
2425
test:
25-
cargo test --lib --all
26-
cargo test --doc --all
26+
#!/usr/bin/env bash
27+
if rg "\`\`\`ignored"; then
28+
echo "ignored doctests are not allowed, use compile_fail or no_run"
29+
exit 1
30+
fi
31+
# no default features
32+
cargo test --workspace --lib --no-default-features
33+
# default features
34+
cargo test --workspace --lib --exclude kube-examples --exclude e2e
35+
# all features
36+
cargo test --workspace --lib --all-features --exclude kube-examples --exclude e2e
37+
cargo test --workspace --doc --all-features --exclude kube-examples --exclude e2e
2738
cargo test -p kube-examples --examples
28-
cargo test -p kube --lib --no-default-features --features=rustls-tls,ws,oauth
29-
cargo test -p kube --lib --no-default-features --features=openssl-tls,ws,oauth
30-
cargo test -p kube --lib --no-default-features
3139

3240
# Integration tests (will modify your current context's cluster)
3341
test-integration:
34-
kubectl delete pod -lapp=kube-rs-test
35-
cargo test --lib --all -- --ignored # also run tests that fail on github actions
36-
cargo test -p kube --lib --features=derive,runtime -- --ignored
37-
cargo test -p kube-client --lib --features=rustls-tls,ws -- --ignored
42+
kubectl delete pod -lapp=kube-rs-test > /dev/null
43+
cargo test --lib --workspace --exclude e2e --all-features -- --ignored
44+
# some examples are canonical tests
3845
cargo run -p kube-examples --example crd_derive
3946
cargo run -p kube-examples --example crd_api
4047

4148
coverage:
4249
cargo tarpaulin --out=Html --output-dir=.
43-
#xdg-open tarpaulin-report.html
50+
{{open}} tarpaulin-report.html
4451

4552
readme:
4653
rustdoc README.md --test --edition=2021

kube-client/src/api/remote_command.rs

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,15 @@ impl AttachedProcess {
161161
}
162162

163163
/// Async writer to stdin.
164-
/// ```ignore
164+
/// ```no_run
165+
/// # use kube_client::api::AttachedProcess;
166+
/// # use tokio::io::{AsyncReadExt, AsyncWriteExt};
167+
/// # async fn wrapper() -> Result<(), Box<dyn std::error::Error>> {
168+
/// # let attached: AttachedProcess = todo!();
165169
/// let mut stdin_writer = attached.stdin().unwrap();
166170
/// stdin_writer.write(b"foo\n").await?;
171+
/// # Ok(())
172+
/// # }
167173
/// ```
168174
/// Only available if [`AttachParams`](super::AttachParams) had `stdin`.
169175
pub fn stdin(&mut self) -> Option<impl AsyncWrite + Unpin> {
@@ -174,9 +180,16 @@ impl AttachedProcess {
174180
}
175181

176182
/// Async reader for stdout outputs.
177-
/// ```ignore
183+
/// ```no_run
184+
/// # use kube_client::api::AttachedProcess;
185+
/// # use tokio::io::{AsyncReadExt, AsyncWriteExt};
186+
/// # async fn wrapper() -> Result<(), Box<dyn std::error::Error>> {
187+
/// # let attached: AttachedProcess = todo!();
178188
/// let mut stdout_reader = attached.stdout().unwrap();
179-
/// let next_stdout = stdout_reader.read().await?;
189+
/// let mut buf = [0u8; 4];
190+
/// stdout_reader.read_exact(&mut buf).await?;
191+
/// # Ok(())
192+
/// # }
180193
/// ```
181194
/// Only available if [`AttachParams`](super::AttachParams) had `stdout`.
182195
pub fn stdout(&mut self) -> Option<impl AsyncRead + Unpin> {
@@ -187,9 +200,16 @@ impl AttachedProcess {
187200
}
188201

189202
/// Async reader for stderr outputs.
190-
/// ```ignore
203+
/// ```no_run
204+
/// # use kube_client::api::AttachedProcess;
205+
/// # use tokio::io::{AsyncReadExt, AsyncWriteExt};
206+
/// # async fn wrapper() -> Result<(), Box<dyn std::error::Error>> {
207+
/// # let attached: AttachedProcess = todo!();
191208
/// let mut stderr_reader = attached.stderr().unwrap();
192-
/// let next_stderr = stderr_reader.read().await?;
209+
/// let mut buf = [0u8; 4];
210+
/// stderr_reader.read_exact(&mut buf).await?;
211+
/// # Ok(())
212+
/// # }
193213
/// ```
194214
/// Only available if [`AttachParams`](super::AttachParams) had `stderr`.
195215
pub fn stderr(&mut self) -> Option<impl AsyncRead + Unpin> {
@@ -218,12 +238,19 @@ impl AttachedProcess {
218238
}
219239

220240
/// Async writer to change the terminal size
221-
/// ```ignore
241+
/// ```no_run
242+
/// # use kube_client::api::{AttachedProcess, TerminalSize};
243+
/// # use tokio::io::{AsyncReadExt, AsyncWriteExt};
244+
/// # use futures::SinkExt;
245+
/// # async fn wrapper() -> Result<(), Box<dyn std::error::Error>> {
246+
/// # let attached: AttachedProcess = todo!();
222247
/// let mut terminal_size_writer = attached.terminal_size().unwrap();
223248
/// terminal_size_writer.send(TerminalSize{
224249
/// height: 100,
225250
/// width: 200,
226251
/// }).await?;
252+
/// # Ok(())
253+
/// # }
227254
/// ```
228255
/// Only available if [`AttachParams`](super::AttachParams) had `tty`.
229256
pub fn terminal_size(&mut self) -> Option<TerminalSizeSender> {

kube-client/src/config/file_config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ pub struct ExecConfig {
270270
/// Specifies which environment variables the host should avoid passing to the auth plugin.
271271
///
272272
/// This does currently not exist upstream and cannot be specified on disk.
273-
/// It has been suggested in client-go via https://github.com/kubernetes/client-go/issues/1177
273+
/// It has been suggested in client-go via <https://github.com/kubernetes/client-go/issues/1177>
274274
#[serde(skip)]
275275
pub drop_env: Option<Vec<String>>,
276276

kube-core/src/admission.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ impl<T: Resource> TryInto<AdmissionRequest<T>> for AdmissionReview<T> {
7676
///
7777
/// In an admission controller scenario, this is extracted from an [`AdmissionReview`] via [`TryInto`]
7878
///
79-
/// ```ignore
79+
/// ```no_run
8080
/// use kube::api::{admission::{AdmissionRequest, AdmissionReview}, DynamicObject};
8181
///
8282
/// // The incoming AdmissionReview received by the controller.
83-
/// let body: AdmissionReview<DynamicObject>;
83+
/// let body: AdmissionReview<DynamicObject> = todo!();
8484
/// let req: AdmissionRequest<_> = body.try_into().unwrap();
8585
/// ```
8686
///
@@ -204,14 +204,14 @@ pub enum Operation {
204204

205205
/// An outgoing [`AdmissionReview`] response. Constructed from the corresponding
206206
/// [`AdmissionRequest`].
207-
/// ```ignore
207+
/// ```no_run
208208
/// use kube::api::{
209209
/// admission::{AdmissionRequest, AdmissionResponse, AdmissionReview},
210210
/// DynamicObject,
211211
/// };
212212
///
213213
/// // The incoming AdmissionReview received by the controller.
214-
/// let body: AdmissionReview<DynamicObject>;
214+
/// let body: AdmissionReview<DynamicObject> = todo!();
215215
/// let req: AdmissionRequest<_> = body.try_into().unwrap();
216216
///
217217
/// // A normal response with no side effects.

kube-derive/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ proc-macro = true
2828
[dev-dependencies]
2929
serde = { version = "1.0.130", features = ["derive"] }
3030
serde_yaml = "0.8.21"
31-
kube = { path = "../kube", default-features = false, version = "<1.0.0, >=0.61.0", features = ["derive"] }
31+
kube = { path = "../kube", version = "<1.0.0, >=0.61.0", features = ["derive", "client"] }
3232
k8s-openapi = { version = "0.17.0", default-features = false, features = ["v1_26"] }
3333
schemars = { version = "0.8.6", features = ["chrono"] }
3434
validator = { version = "0.16.0", features = ["derive"] }

kube-derive/src/lib.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,22 @@ mod custom_resource;
4242
/// and optionally status. The **generated** type `Foo` can be used with the [`kube`] crate
4343
/// as an `Api<Foo>` object (`FooSpec` can not be used with [`Api`][`kube::Api`]).
4444
///
45-
/// ```rust,ignore
46-
/// let client = Client::try_default().await?;
47-
/// let foos: Api<Foo> = Api::namespaced(client.clone(), "default");
48-
///
45+
/// ```no_run
46+
/// # use k8s_openapi::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceDefinition;
47+
/// # use kube_derive::CustomResource;
48+
/// # use kube::{api::{Api, Patch, PatchParams}, Client, CustomResourceExt};
49+
/// # use serde::{Deserialize, Serialize};
50+
/// # async fn wrapper() -> Result<(), Box<dyn std::error::Error>> {
51+
/// # #[derive(CustomResource, Clone, Debug, Deserialize, Serialize, schemars::JsonSchema)]
52+
/// # #[kube(group = "clux.dev", version = "v1", kind = "Foo", namespaced)]
53+
/// # struct FooSpec {}
54+
/// # let client: Client = todo!();
55+
/// let foos: Api<Foo> = Api::default_namespaced(client.clone());
4956
/// let crds: Api<CustomResourceDefinition> = Api::all(client.clone());
50-
/// crds.patch("foos.clux.dev", &ssapply, serde_yaml::to_vec(&Foo::crd())?).await
57+
/// let crd_yaml = serde_yaml::to_vec(&Foo::crd())?;
58+
/// crds.patch("foos.clux.dev", &PatchParams::apply("myapp"), &Patch::Apply(crd_yaml)).await;
59+
/// # Ok(())
60+
/// # }
5161
/// ```
5262
///
5363
/// This example posts the generated `::crd` to the `CustomResourceDefinition` API.
@@ -177,8 +187,8 @@ mod custom_resource;
177187
///
178188
/// # Generated code
179189
///
180-
/// The example above will roughly generate:
181-
/// ```ignore
190+
/// The example above will **roughly** generate:
191+
/// ```compile_fail
182192
/// #[derive(Serialize, Deserialize, Debug, PartialEq, Clone, JsonSchema)]
183193
/// #[serde(rename_all = "camelCase")]
184194
/// pub struct FooCrd {
@@ -188,11 +198,11 @@ mod custom_resource;
188198
/// spec: FooSpec,
189199
/// status: Option<FooStatus>,
190200
/// }
191-
/// impl kube::Resource for FooCrd {...}
201+
/// impl kube::Resource for FooCrd { .. }
192202
///
193203
/// impl FooCrd {
194-
/// pub fn new(name: &str, spec: FooSpec) -> Self { ... }
195-
/// pub fn crd() -> k8s_openapi::...::CustomResourceDefinition { ... }
204+
/// pub fn new(name: &str, spec: FooSpec) -> Self { .. }
205+
/// pub fn crd() -> CustomResourceDefinition { .. }
196206
/// }
197207
/// ```
198208
///

release.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Release process :: cargo-release >= 0.18.3
22
#
3-
# Dependencies: cargo-release, cargo-tree, sd, ripgrep
3+
# Dependencies: https://kube.rs/tools
44
#
55
# 0. (optional) cargo release minor ; verify readme + changelog bumped; then git reset --hard
66
# 1. PUBLISH_GRACE_SLEEP=20 cargo release minor --execute

scripts/release-post.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -euo pipefail
33

44
main() {
55
cd "$(dirname "${BASH_SOURCE[0]}")" && cd .. # aka $WORKSPACE_ROOT
6-
local -r CURRENT_VER="$(rg "kube =" README.md | head -n 1 | rg 'version = "(\S*)"' -or '$1')"
6+
local -r CURRENT_VER="$(rg 'kube = \{ version = "(\S*)"' -or '$1' README.md | head -n1)"
77
git tag -a "${CURRENT_VER}" -m "${CURRENT_VER}"
88
git push
99
git push --tags

scripts/release-pre.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ replace-docs() {
1616
}
1717

1818
sanity() {
19-
CARGO_TREE_OPENAPI="$(cargo tree -i k8s-openapi | head -n 1 | choose 1)"
19+
CARGO_TREE_OPENAPI="$(cargo tree -i k8s-openapi --depth=0 -e=normal | choose 1)"
2020
USED_K8S_OPENAPI="${CARGO_TREE_OPENAPI:1}"
2121
RECOMMENDED_K8S_OPENAPI="$(rg "k8s-openapi =" README.md | head -n 1)" # only check first instance
2222
if ! [[ $RECOMMENDED_K8S_OPENAPI =~ $USED_K8S_OPENAPI ]]; then
@@ -29,7 +29,7 @@ sanity() {
2929
main() {
3030
# We only want this to run ONCE at workspace level
3131
cd "$(dirname "${BASH_SOURCE[0]}")" && cd .. # aka $WORKSPACE_ROOT
32-
local -r CURRENT_VER="$(rg "kube =" README.md | head -n 1 | rg 'version = "(\S*)"' -or '$1')"
32+
local -r CURRENT_VER="$(rg 'kube = \{ version = "(\S*)"' -or '$1' README.md | head -n1)"
3333

3434
# If the main README has been bumped, assume we are done:
3535
if [[ "${NEW_VERSION}" = "${CURRENT_VER}" ]]; then

0 commit comments

Comments
 (0)