Skip to content

Commit 2a3ba10

Browse files
committed
test: Adjust test modules, add negative K8s specific test
1 parent a3f75f9 commit 2a3ba10

File tree

4 files changed

+72
-24
lines changed

4 files changed

+72
-24
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use schemars::JsonSchema;
2+
use serde::{Deserialize, Serialize};
3+
4+
use stackable_versioned_macros::versioned;
5+
6+
#[allow(deprecated)]
7+
fn main() {
8+
#[versioned(
9+
version(name = "v1alpha1"),
10+
version(name = "v1beta1"),
11+
version(name = "v1"),
12+
k8s(group = "stackable.tech")
13+
)]
14+
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
15+
pub struct Foo {
16+
#[versioned(
17+
added(since = "v1beta1"),
18+
changed(since = "v1", from_name = "bah", from_type = "u16")
19+
)]
20+
bar: usize,
21+
baz: bool,
22+
}
23+
24+
let merged_crd = Foo::merged_crd("v1").unwrap();
25+
println!("{}", serde_yaml::to_string(&merged_crd).unwrap());
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: struct name needs to include the `Spec` suffix if Kubernetes features are enabled via `#[versioned(k8s())]`
2+
--> tests/k8s/fail/crd.rs:15:16
3+
|
4+
15 | pub struct Foo {
5+
| ^^^
6+
7+
error[E0433]: failed to resolve: use of undeclared type `Foo`
8+
--> tests/k8s/fail/crd.rs:24:22
9+
|
10+
24 | let merged_crd = Foo::merged_crd("v1").unwrap();
11+
| ^^^ use of undeclared type `Foo`

crates/stackable-versioned-macros/tests/trybuild.rs

+35-24
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,31 @@
77
//!
88
//! [1]: https://github.com/dtolnay/trybuild?tab=readme-ov-file#workflow
99
10-
// Enable the module below to get syntax highlighting and code completion.
10+
// Enable the 'pass' module below to get syntax highlighting and code completion.
1111
// Adjust the list of modules to enable syntax highlighting and code completion.
12-
// Unfortunately tests in subfolders aren't automatically included.
12+
// Unfortunately tests in sub-folders aren't automatically included.
1313
//
14-
// #[allow(dead_code)]
15-
// mod good {
16-
// mod attributes_enum;
17-
// mod attributes_struct;
18-
// mod basic;
14+
// Similar to the above 'pass' module, enable the 'fail' module below to get
15+
// syntax highlighting and code completion. You will need to comment them out
16+
// again but before running tests, otherwise compilation will fail (as expected).
17+
#[allow(dead_code)]
18+
mod default {
19+
// mod pass {
20+
// mod attributes_enum;
21+
// mod attributes_struct;
22+
// mod basic;
1923

20-
// #[cfg(feature = "k8s")]
21-
// mod crd;
22-
// mod deprecate;
23-
// mod rename;
24-
// mod skip_from_version;
25-
// }
24+
// mod deprecate;
25+
// mod rename;
26+
// mod skip_from_version;
27+
// }
2628

27-
// Similar to the above module, enable the module below to get syntax
28-
// highlighting and code completion. You will need to comment them out again but
29-
// before running tests, orherwise compilation will fail (as expected).
30-
//
31-
// #[allow(dead_code)]
32-
// mod bad {
33-
// mod deprecate;
34-
// mod skip_from_all;
35-
// mod skip_from_version;
36-
// }
29+
// mod fail {
30+
// mod deprecate;
31+
// mod skip_from_all;
32+
// mod skip_from_version;
33+
// }
34+
}
3735

3836
#[test]
3937
fn default_macros() {
@@ -42,9 +40,22 @@ fn default_macros() {
4240
t.compile_fail("tests/default/fail/*.rs");
4341
}
4442

43+
#[cfg(feature = "k8s")]
44+
#[allow(dead_code)]
45+
mod k8s {
46+
// mod pass {
47+
// mod crd;
48+
// }
49+
50+
// mod fail {
51+
// mod crd;
52+
// }
53+
}
54+
4555
#[cfg(feature = "k8s")]
4656
#[test]
4757
fn k8s_macros() {
4858
let t = trybuild::TestCases::new();
49-
t.pass("tests/k8s/*.rs");
59+
t.pass("tests/k8s/pass/*.rs");
60+
t.compile_fail("tests/k8s/fail/*.rs");
5061
}

0 commit comments

Comments
 (0)