Skip to content

Commit 25e10db

Browse files
committed
Add integration test for (optional) complex enums
1 parent 307e828 commit 25e10db

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

kube-derive/tests/crd_complex_enum_tests.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use schemars::JsonSchema;
55
use serde::{Deserialize, Serialize};
66
use serde_json::json;
77

8+
// Enum definitions
9+
810
/// A very simple enum with empty variants
911
#[derive(Serialize, Deserialize, Debug, Clone, JsonSchema)]
1012
enum NormalEnum {
@@ -18,6 +20,13 @@ enum NormalEnum {
1820
D,
1921
}
2022

23+
/// A complex enum with unit and struct variants
24+
#[derive(Serialize, Deserialize, Debug, Clone, JsonSchema)]
25+
enum ComplexEnum {
26+
Normal(NormalEnum),
27+
Hardcore { hard: String, core: NormalEnum },
28+
}
29+
2130
/// An untagged enum with a nested enum inside
2231
#[derive(Serialize, Deserialize, Debug, Clone, JsonSchema)]
2332
#[serde(untagged)]
@@ -37,6 +46,8 @@ struct FlattenedUntaggedEnum {
3746
inner: UntaggedEnum,
3847
}
3948

49+
// CRD definitions
50+
4051
#[derive(CustomResource, Serialize, Deserialize, Debug, Clone, JsonSchema)]
4152
#[kube(group = "clux.dev", version = "v1", kind = "NormalEnumTest")]
4253
struct NormalEnumTestSpec {
@@ -49,6 +60,18 @@ struct OptionalEnumTestSpec {
4960
foo: Option<NormalEnum>,
5061
}
5162

63+
#[derive(CustomResource, Serialize, Deserialize, Debug, Clone, JsonSchema)]
64+
#[kube(group = "clux.dev", version = "v1", kind = "ComplexEnumTest")]
65+
struct ComplexEnumTestSpec {
66+
foo: ComplexEnum,
67+
}
68+
69+
#[derive(CustomResource, Serialize, Deserialize, Debug, Clone, JsonSchema)]
70+
#[kube(group = "clux.dev", version = "v1", kind = "OptionalComplexEnumTest")]
71+
struct OptionalComplexEnumTestSpec {
72+
foo: Option<ComplexEnum>,
73+
}
74+
5275
#[derive(CustomResource, Serialize, Deserialize, Debug, Clone, JsonSchema)]
5376
#[kube(group = "clux.dev", version = "v1", kind = "UntaggedEnumTest")]
5477
struct UntaggedEnumTestSpec {
@@ -75,6 +98,13 @@ fn print_crds() {
7598
println!("---");
7699
println!("{}", serde_yaml::to_string(&OptionalEnumTest::crd()).unwrap());
77100
println!("---");
101+
println!("{}", serde_yaml::to_string(&ComplexEnumTest::crd()).unwrap());
102+
println!("---");
103+
println!(
104+
"{}",
105+
serde_yaml::to_string(&OptionalComplexEnumTest::crd()).unwrap()
106+
);
107+
println!("---");
78108
println!("{}", serde_yaml::to_string(&UntaggedEnumTest::crd()).unwrap());
79109
println!("---");
80110
println!(
@@ -218,6 +248,18 @@ fn optional_enum() {
218248
);
219249
}
220250

251+
252+
#[test]
253+
fn complex_enum() {
254+
assert_json_eq!(ComplexEnumTest::crd(), json!(42));
255+
}
256+
257+
258+
#[test]
259+
fn optional_complex_enum() {
260+
assert_json_eq!(OptionalComplexEnumTest::crd(), json!(42));
261+
}
262+
221263
#[test]
222264
fn untagged_enum() {
223265
assert_json_eq!(

0 commit comments

Comments
 (0)