Skip to content

Commit ab4f3c0

Browse files
committed
extend coverage for built elements
1 parent 2af477a commit ab4f3c0

1 file changed

Lines changed: 70 additions & 0 deletions

File tree

rust/operator-binary/src/controller/validate.rs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,81 @@ pub fn validate(
240240

241241
#[cfg(test)]
242242
mod tests {
243+
use serde_json::json;
243244
use stackable_operator::product_logging::spec::{
244245
AutomaticContainerLogConfig, ContainerLogConfig, ContainerLogConfigChoice,
245246
};
246247

247248
use super::*;
249+
use crate::controller::build::properties::test_support::app_version_label;
250+
251+
/// Locks every value the validate step itself derives from the minimal fixture — so a
252+
/// validation regression fails here, with a validate-shaped message, instead of surfacing as
253+
/// a confusing build-test failure downstream.
254+
///
255+
/// The merged per-role-group config (resources, affinity, logging defaults, …) is produced by
256+
/// the config merge machinery, whose contracts are tested in operator-rs and the properties
257+
/// tests; only the values this module derives on top are re-asserted here.
258+
#[test]
259+
fn validate_ok_derives_expected_values() {
260+
let opa: v1alpha2::OpaCluster = serde_json::from_value(json!({
261+
"apiVersion": "opa.stackable.tech/v1alpha2",
262+
"kind": "OpaCluster",
263+
"metadata": {
264+
"name": "test-opa",
265+
"namespace": "default",
266+
"uid": "c27b3971-ca72-42c1-80a4-abdfc1db0ddd",
267+
},
268+
"spec": {
269+
"image": { "productVersion": "1.2.3" },
270+
"servers": { "roleGroups": { "default": {} } },
271+
},
272+
}))
273+
.expect("valid test input");
274+
let operator_environment = OperatorEnvironmentOptions {
275+
operator_namespace: "stackable-operators".to_string(),
276+
operator_service_name: "opa-operator".to_string(),
277+
image_repository: "oci.example.org".to_string(),
278+
};
279+
280+
let cluster = validate(&opa, &operator_environment).expect("the minimal fixture validates");
281+
282+
assert_eq!(cluster.name.to_string(), "test-opa");
283+
assert_eq!(cluster.namespace.to_string(), "default");
284+
assert_eq!(
285+
cluster.uid.to_string(),
286+
"c27b3971-ca72-42c1-80a4-abdfc1db0ddd"
287+
);
288+
assert_eq!(
289+
cluster.image.image,
290+
format!("oci.example.org/opa:{}", app_version_label("1.2.3"))
291+
);
292+
assert_eq!(cluster.image.product_version, "1.2.3");
293+
assert_eq!(
294+
cluster.product_version.to_string(),
295+
app_version_label("1.2.3")
296+
);
297+
298+
// The minimal fixture configures no user-info fetcher and no TLS; the listener class
299+
// falls back to its default.
300+
assert_eq!(cluster.cluster_config.user_info, None);
301+
assert_eq!(cluster.cluster_config.tls, None);
302+
assert_eq!(
303+
cluster.cluster_config.listener_class,
304+
v1alpha2::CurrentlySupportedListenerClasses::ClusterInternal
305+
);
306+
307+
// A single `server` role with the single `default` role group; the Vector agent is off.
308+
assert_eq!(cluster.role_group_configs.len(), 1);
309+
let role_groups = &cluster.role_group_configs[&OpaRole::Server];
310+
let role_group_names: Vec<String> = role_groups.keys().map(ToString::to_string).collect();
311+
assert_eq!(role_group_names, ["default"]);
312+
let role_group = role_groups
313+
.values()
314+
.next()
315+
.expect("the default role group exists");
316+
assert_eq!(role_group.config.logging.vector_container, None);
317+
}
248318

249319
/// A [`Logging`] with an automatic log config for every container, as the (defaulted) merged
250320
/// config provides at runtime. `validate_logging` validates all containers, so all must be

0 commit comments

Comments
 (0)