Skip to content

Commit eb141e0

Browse files
committed
test: Add roundtrip generation via macro
1 parent 17ff823 commit eb141e0

File tree

16 files changed

+452
-23
lines changed

16 files changed

+452
-23
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ educe = { version = "0.6.0", default-features = false, features = ["Clone", "De
2525
either = "1.13.0"
2626
futures = "0.3.30"
2727
futures-util = "0.3.30"
28-
indexmap = "2.5"
28+
indexmap = "2.5.0"
29+
indoc = "2.0.6"
2930
insta = { version= "1.40", features = ["glob"] }
3031
hyper = { version = "1.4.1", features = ["full"] }
3132
hyper-util = "0.1.8"

crates/stackable-operator/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ dockerfile-parser.workspace = true
2828
either.workspace = true
2929
educe.workspace = true
3030
futures.workspace = true
31+
indoc.workspace = true
3132
indexmap.workspace = true
3233
json-patch.workspace = true
3334
k8s-openapi.workspace = true

crates/stackable-operator/src/crd/authentication/core/mod.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,61 @@ pub mod versioned {
153153
oidc: Option<oidc::v1alpha1::ClientAuthenticationOptions<O>>,
154154
}
155155
}
156+
157+
#[cfg(test)]
158+
impl stackable_versioned::flux_converter::test_utils::RoundtripTestData
159+
for v1alpha1::AuthenticationClassSpec
160+
{
161+
fn get_roundtrip_test_data() -> Vec<Self> {
162+
crate::utils::yaml_from_str_singleton_map(indoc::indoc! {"
163+
- provider:
164+
static:
165+
userCredentialsSecret:
166+
name: simple-users-credentials
167+
- provider:
168+
ldap:
169+
hostname: my.ldap.server
170+
port: 389
171+
searchBase: ou=users,dc=example,dc=org
172+
searchFilter: foo
173+
bindCredentials:
174+
secretClass: openldap-bind-credentials
175+
ldapFieldNames:
176+
email: email
177+
givenName: givenName
178+
group: group
179+
surname: surname
180+
uid: uid
181+
tls:
182+
verification:
183+
server:
184+
caCert:
185+
secretClass: s3-cert
186+
- provider:
187+
oidc:
188+
hostname: my.keycloak.server
189+
port: 8080
190+
rootPath: /realms/master
191+
scopes:
192+
- email
193+
- openid
194+
- profile
195+
principalClaim: preferred_username
196+
providerHint: Keycloak
197+
tls:
198+
verification:
199+
server:
200+
caCert:
201+
secretClass: s3-cert
202+
- provider:
203+
tls: {}
204+
- provider:
205+
tls:
206+
clientCertSecretClass: client-auth-tls
207+
- provider:
208+
kerberos:
209+
kerberosSecretClass: kerberos-auth
210+
"})
211+
.expect("Failed to parse AuthenticationClassSpec YAML")
212+
}
213+
}

crates/stackable-operator/src/crd/authentication/ldap/v1alpha1_impl.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ impl Default for FieldNames {
169169
#[cfg(test)]
170170
mod tests {
171171
use super::*;
172-
use crate::commons::secret_class::SecretClassVolume;
172+
use crate::{commons::secret_class::SecretClassVolume, utils::yaml_from_str_singleton_map};
173173

174174
#[test]
175175
fn minimal() {
@@ -213,9 +213,7 @@ mod tests {
213213
caCert:
214214
secretClass: ldap-ca-cert
215215
"#;
216-
let deserializer = serde_yaml::Deserializer::from_str(input);
217-
let ldap: AuthenticationProvider =
218-
serde_yaml::with::singleton_map_recursive::deserialize(deserializer).unwrap();
216+
let ldap: AuthenticationProvider = yaml_from_str_singleton_map(input).unwrap();
219217

220218
assert_eq!(ldap.port(), 42);
221219
assert!(ldap.tls.uses_tls());

crates/stackable-operator/src/crd/git_sync/v1alpha1_impl.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ mod tests {
365365
use super::*;
366366
use crate::{
367367
config::fragment::validate, product_config_utils::env_vars_from,
368-
product_logging::spec::default_container_log_config,
368+
product_logging::spec::default_container_log_config, utils::yaml_from_str_singleton_map,
369369
};
370370

371371
#[test]
@@ -435,9 +435,7 @@ mod tests {
435435
--git-config: key:value,safe.directory:/safe-dir
436436
"#;
437437

438-
let deserializer = serde_yaml::Deserializer::from_str(git_sync_spec);
439-
let git_syncs: Vec<GitSync> =
440-
serde_yaml::with::singleton_map_recursive::deserialize(deserializer).unwrap();
438+
let git_syncs: Vec<GitSync> = yaml_from_str_singleton_map(git_sync_spec).unwrap();
441439

442440
let resolved_product_image = ResolvedProductImage {
443441
image: "oci.stackable.tech/sdp/product:latest".to_string(),

crates/stackable-operator/src/crd/listener/class/mod.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,24 @@ pub mod versioned {
6868
pub preferred_address_type: core_v1alpha1::PreferredAddressType,
6969
}
7070
}
71+
72+
#[cfg(test)]
73+
impl stackable_versioned::flux_converter::test_utils::RoundtripTestData
74+
for v1alpha1::ListenerClassSpec
75+
{
76+
fn get_roundtrip_test_data() -> Vec<Self> {
77+
crate::utils::yaml_from_str_singleton_map(indoc::indoc! {"
78+
- serviceType: ClusterIP
79+
- serviceType: NodePort
80+
- serviceType: LoadBalancer
81+
- serviceType: ClusterIP
82+
loadBalancerAllocateNodePorts: false
83+
loadBalancerClass: foo
84+
serviceAnnotations:
85+
foo: bar
86+
serviceExternalTrafficPolicy: Local
87+
preferredAddressType: HostnameConservative
88+
"})
89+
.expect("Failed to parse ListenerClassSpec YAML")
90+
}
91+
}

crates/stackable-operator/src/crd/listener/listeners/mod.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,56 @@ pub mod versioned {
163163
Cluster,
164164
}
165165
}
166+
167+
#[cfg(test)]
168+
impl stackable_versioned::flux_converter::test_utils::RoundtripTestData for v1alpha1::ListenerSpec {
169+
fn get_roundtrip_test_data() -> Vec<Self> {
170+
crate::utils::yaml_from_str_singleton_map(indoc::indoc! {"
171+
- {}
172+
- className: cluster-internal
173+
extraPodLabelSelectorLabels: {}
174+
ports: []
175+
publishNotReadyAddresses: true
176+
- className: external-unstable
177+
extraPodLabelSelectorLabels:
178+
foo: bar
179+
ports:
180+
- name: http
181+
port: 8080
182+
protocol: TCP
183+
publishNotReadyAddresses: true
184+
"})
185+
.expect("Failed to parse ListenerSpec YAML")
186+
}
187+
}
188+
189+
#[cfg(test)]
190+
impl stackable_versioned::flux_converter::test_utils::RoundtripTestData
191+
for v1alpha1::PodListenersSpec
192+
{
193+
fn get_roundtrip_test_data() -> Vec<Self> {
194+
crate::utils::yaml_from_str_singleton_map(indoc::indoc! {"
195+
- listeners: {}
196+
- listeners:
197+
foo:
198+
scope: Node
199+
- listeners:
200+
foo:
201+
scope: Cluster
202+
ingressAddresses:
203+
- address: 1.2.3.4
204+
addressType: IP
205+
ports: {}
206+
- listeners:
207+
foo:
208+
scope: Cluster
209+
ingressAddresses:
210+
- address: foo.bar
211+
addressType: Hostname
212+
ports:
213+
http: 8080
214+
https: 8443
215+
"})
216+
.expect("Failed to parse PodListenersSpec YAML")
217+
}
218+
}

crates/stackable-operator/src/crd/s3/bucket/mod.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,34 @@ pub mod versioned {
4949
pub connection: conn_v1alpha1::ConnectionSpec,
5050
}
5151
}
52+
53+
#[cfg(test)]
54+
impl stackable_versioned::flux_converter::test_utils::RoundtripTestData for v1alpha1::BucketSpec {
55+
fn get_roundtrip_test_data() -> Vec<Self> {
56+
crate::utils::yaml_from_str_singleton_map(indoc::indoc! {"
57+
- bucketName: my-example-bucket
58+
connection:
59+
reference: my-connection-resource
60+
- bucketName: foo
61+
connection:
62+
inline:
63+
host: s3.example.com
64+
- bucketName: foo
65+
connection:
66+
inline:
67+
host: s3.example.com
68+
port: 1234
69+
accessStyle: VirtualHosted
70+
credentials:
71+
secretClass: s3-credentials
72+
region:
73+
name: eu-west-1
74+
tls:
75+
verification:
76+
server:
77+
caCert:
78+
secretClass: s3-cert
79+
"})
80+
.expect("Failed to parse BucketSpec YAML")
81+
}
82+
}

crates/stackable-operator/src/crd/s3/connection/mod.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,38 @@ pub mod versioned {
101101
}
102102
}
103103

104+
#[cfg(test)]
105+
impl stackable_versioned::flux_converter::test_utils::RoundtripTestData
106+
for v1alpha1::ConnectionSpec
107+
{
108+
fn get_roundtrip_test_data() -> Vec<Self> {
109+
crate::utils::yaml_from_str_singleton_map(indoc::indoc! {"
110+
- host: s3.example.com
111+
- host: s3.example.com
112+
port: 1234
113+
accessStyle: VirtualHosted
114+
credentials:
115+
secretClass: s3-credentials
116+
region:
117+
name: eu-west-1
118+
tls: null
119+
- host: s3.example.com
120+
region:
121+
name: us-east-1
122+
tls:
123+
verification:
124+
none: {}
125+
- host: s3.example.com
126+
tls:
127+
verification:
128+
server:
129+
caCert:
130+
secretClass: s3-cert
131+
"})
132+
.expect("Failed to parse ConnectionSpec YAML")
133+
}
134+
}
135+
104136
#[cfg(test)]
105137
mod tests {
106138
use std::collections::BTreeMap;

0 commit comments

Comments
 (0)