Skip to content

Commit b1d4550

Browse files
committed
Fix tests
1 parent 191c68a commit b1d4550

File tree

3 files changed

+48
-9
lines changed

3 files changed

+48
-9
lines changed

crates/stackable-operator/src/cli.rs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -388,38 +388,61 @@ mod tests {
388388
"bar",
389389
"--watch-namespace",
390390
"foo",
391+
"--kubernetes-node-name",
392+
"baz",
391393
]);
392394
assert_eq!(
393395
opts,
394396
ProductOperatorRun {
395397
product_config: ProductConfigPath::from("bar".as_ref()),
396398
watch_namespace: WatchNamespace::One("foo".to_string()),
397-
cluster_info_opts: Default::default(),
399+
cluster_info_opts: KubernetesClusterInfoOpts {
400+
kubernetes_cluster_domain: None,
401+
kubernetes_node_name: "baz".to_string()
402+
},
398403
telemetry_arguments: Default::default(),
399404
}
400405
);
401406

402407
// no cli / no env
403-
let opts = ProductOperatorRun::parse_from(["run", "--product-config", "bar"]);
408+
let opts = ProductOperatorRun::parse_from([
409+
"run",
410+
"--product-config",
411+
"bar",
412+
"--kubernetes-node-name",
413+
"baz",
414+
]);
404415
assert_eq!(
405416
opts,
406417
ProductOperatorRun {
407418
product_config: ProductConfigPath::from("bar".as_ref()),
408419
watch_namespace: WatchNamespace::All,
409-
cluster_info_opts: Default::default(),
420+
cluster_info_opts: KubernetesClusterInfoOpts {
421+
kubernetes_cluster_domain: None,
422+
kubernetes_node_name: "baz".to_string()
423+
},
410424
telemetry_arguments: Default::default(),
411425
}
412426
);
413427

414428
// env with namespace
415429
unsafe { env::set_var(WATCH_NAMESPACE, "foo") };
416-
let opts = ProductOperatorRun::parse_from(["run", "--product-config", "bar"]);
430+
let opts = ProductOperatorRun::parse_from([
431+
"run",
432+
"--product-config",
433+
"bar",
434+
"--kubernetes-node-name",
435+
"baz",
436+
]);
417437
assert_eq!(
418438
opts,
419439
ProductOperatorRun {
420440
product_config: ProductConfigPath::from("bar".as_ref()),
421441
watch_namespace: WatchNamespace::One("foo".to_string()),
422-
cluster_info_opts: Default::default(),
442+
cluster_info_opts: KubernetesClusterInfoOpts {
443+
kubernetes_cluster_domain: None,
444+
kubernetes_node_name: "baz".to_string()
445+
},
423446
telemetry_arguments: Default::default(),
424447
}
425448
);

crates/stackable-operator/src/client.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -683,10 +683,26 @@ mod tests {
683683
};
684684
use tokio::time::error::Elapsed;
685685

686+
use crate::utils::cluster_info::KubernetesClusterInfoOpts;
687+
688+
async fn test_cluster_info_opts() -> KubernetesClusterInfoOpts {
689+
KubernetesClusterInfoOpts {
690+
// We have to hard-code a made-up cluster domain,
691+
// since kubernetes_node_name (probably) won't be a valid Node that we can query.
692+
kubernetes_cluster_domain: Some(
693+
"fake-cluster.local"
694+
.parse()
695+
.expect("hard-coded cluster domain must be valid"),
696+
),
697+
// Tests aren't running in a kubelet, so make up a name of one.
698+
kubernetes_node_name: "fake-node-name".to_string(),
699+
}
700+
}
701+
686702
#[tokio::test]
687703
#[ignore = "Tests depending on Kubernetes are not ran by default"]
688704
async fn k8s_test_wait_created() {
689-
let client = super::initialize_operator(None, &Default::default())
705+
let client = super::initialize_operator(None, &test_cluster_info_opts().await)
690706
.await
691707
.expect("KUBECONFIG variable must be configured.");
692708

@@ -764,7 +780,7 @@ mod tests {
764780
#[tokio::test]
765781
#[ignore = "Tests depending on Kubernetes are not ran by default"]
766782
async fn k8s_test_wait_created_timeout() {
767-
let client = super::initialize_operator(None, &Default::default())
783+
let client = super::initialize_operator(None, &test_cluster_info_opts().await)
768784
.await
769785
.expect("KUBECONFIG variable must be configured.");
770786

@@ -784,7 +800,7 @@ mod tests {
784800
#[tokio::test]
785801
#[ignore = "Tests depending on Kubernetes are not ran by default"]
786802
async fn k8s_test_list_with_label_selector() {
787-
let client = super::initialize_operator(None, &Default::default())
803+
let client = super::initialize_operator(None, &test_cluster_info_opts().await)
788804
.await
789805
.expect("KUBECONFIG variable must be configured.");
790806

crates/stackable-operator/src/utils/cluster_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct KubernetesClusterInfo {
1515
pub cluster_domain: DomainName,
1616
}
1717

18-
#[derive(clap::Parser, Debug, Default, PartialEq, Eq)]
18+
#[derive(clap::Parser, Debug, PartialEq, Eq)]
1919
pub struct KubernetesClusterInfoOpts {
2020
/// Kubernetes cluster domain, usually this is `cluster.local`.
2121
// We are not using a default value here, as we query the cluster if it is not specified.

0 commit comments

Comments
 (0)