From 0305a5be2d456ae521149c0d37a60709a226fde0 Mon Sep 17 00:00:00 2001 From: Ren MinMin Date: Fri, 25 Oct 2024 06:44:10 +0000 Subject: [PATCH] proxy: fix unittest failed Fix proxy unittest failed Signed-off-by: Ren MinMin --- .../proxy/src/controller/apiserver_mock.rs | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/KubeOS-Rust/proxy/src/controller/apiserver_mock.rs b/KubeOS-Rust/proxy/src/controller/apiserver_mock.rs index 679096d3..a0382369 100644 --- a/KubeOS-Rust/proxy/src/controller/apiserver_mock.rs +++ b/KubeOS-Rust/proxy/src/controller/apiserver_mock.rs @@ -39,7 +39,7 @@ use super::{ use crate::controller::{ apiclient::{ApplyApi, ControllerClient}, crd::{Config, Content, OSInstance, OSInstanceSpec, OSSpec, OS}, - values::{LABEL_OSINSTANCE, LABEL_UPGRADING, NODE_STATUS_IDLE}, + values::{LABEL_OSINSTANCE, LABEL_UPGRADING, NODE_STATUS_IDLE, LABEL_CONFIGURING}, ProxyController, }; @@ -89,7 +89,7 @@ impl ApiServerVerifier { .handler_osinstance_get_exist(osi.clone()) .await .unwrap() - .handler_node_get_with_label(osi.clone()) + .handler_node_get_with_label(osi.clone(), LABEL_UPGRADING) .await .unwrap() .handler_osinstance_patch_upgradeconfig_v2(osi.clone()) @@ -108,7 +108,7 @@ impl ApiServerVerifier { .handler_osinstance_get_exist(osi.clone()) .await .unwrap() - .handler_node_get_with_label(osi.clone()) + .handler_node_get_with_label(osi.clone(), LABEL_UPGRADING) .await .unwrap() .handler_node_update_delete_label(osi.clone()) @@ -127,7 +127,7 @@ impl ApiServerVerifier { .handler_osinstance_get_exist(osi.clone()) .await .unwrap() - .handler_node_get_with_label(osi.clone()) + .handler_node_get_with_label(osi.clone(), LABEL_UPGRADING) .await }, Testcases::UpgradeOSInstaceNodestatusIdle(osi) => { @@ -137,7 +137,7 @@ impl ApiServerVerifier { .handler_osinstance_get_exist(osi.clone()) .await .unwrap() - .handler_node_get_with_label(osi.clone()) + .handler_node_get_with_label(osi.clone(), LABEL_UPGRADING) .await .unwrap() .handler_node_update_delete_label(osi.clone()) @@ -153,12 +153,18 @@ impl ApiServerVerifier { .handler_osinstance_get_exist(osi.clone()) .await .unwrap() - .handler_node_get(osi.clone()) + .handler_node_get_with_label(osi.clone(), LABEL_CONFIGURING) .await .unwrap() .handler_osinstance_patch_sysconfig_v2(osi.clone()) .await .unwrap() + .handler_node_update_delete_label(osi.clone()) + .await + .unwrap() + .handler_node_cordon(osi.clone()) + .await + .unwrap() .handler_osinstance_patch_nodestatus_idle(osi) .await }, @@ -195,7 +201,7 @@ impl ApiServerVerifier { .handler_osinstance_get_exist(osi.clone()) .await .unwrap() - .handler_node_get_with_label(osi.clone()) + .handler_node_get_with_label(osi.clone(), LABEL_UPGRADING) .await .unwrap() .handler_osinstance_patch_upgradeconfig_v2(osi.clone()) @@ -378,7 +384,7 @@ impl ApiServerVerifier { Ok(self) } - async fn handler_node_get_with_label(mut self, osinstance: OSInstance) -> Result { + async fn handler_node_get_with_label(mut self, osinstance: OSInstance, label: &str) -> Result { // return node with name = openeuler, osimage = KubeOS v1,has upgrade label let (request, send) = self.0.next_request().await.expect("service not called"); assert_eq!(request.method(), http::Method::GET); @@ -392,10 +398,10 @@ impl ApiServerVerifier { }), }; let node_labels = node.labels_mut(); - node_labels.insert(LABEL_UPGRADING.to_string(), "".to_string()); + node_labels.insert(label.to_string(), "".to_string()); assert_eq!(node.name(), String::from("openeuler")); assert_eq!(node.status.as_ref().unwrap().node_info.as_ref().unwrap().os_image, String::from("KubeOS v1")); - assert!(node.labels().contains_key(LABEL_UPGRADING)); + assert!(node.labels().contains_key(label)); dbg!("handler_node_get_with_label"); let response = serde_json::to_vec(&node.clone()).unwrap(); send.send_response(Response::builder().body(Body::from(response)).unwrap()); -- Gitee