diff --git a/src/lock.rs b/src/lock.rs index 18e9c67..0939218 100644 --- a/src/lock.rs +++ b/src/lock.rs @@ -119,7 +119,7 @@ async fn wait_lease(client: Client, name: &str) -> Result<(), kube::Error> { pub async fn lock_v1( lockheader: Result, data: rocket::form::Result<'_, Form>, -) -> Result<(), LockError> { +) -> Result { lockheader?; let data = data?; let client = Client::try_default().await.inspect_err(|e| { @@ -159,7 +159,10 @@ pub async fn lock_v1( Err(e) => return Err(e.into()), } } - Ok(()) + Ok(format!( + "Acquired reboot lock for group {}, host {}\n", + data.group, data.hostname + )) } #[rocket::post("/api/v1/unlock", data = "")] diff --git a/tests/integration/lock.rs b/tests/integration/lock.rs index 60c108f..77f5ccf 100644 --- a/tests/integration/lock.rs +++ b/tests/integration/lock.rs @@ -43,7 +43,12 @@ async fn test_lock_v1_success() { .dispatch() .await; assert_eq!(response.status(), Status::Ok); - assert_eq!(response.into_string().await, None); + assert_eq!( + response.into_string().await.as_deref(), + Some( + "Acquired reboot lock for group default, host test1.example.org\n" + ) + ); let lease = get_lease("reboot-lock-default").await.unwrap(); assert_eq!( lease.spec.unwrap().holder_identity.as_deref(), @@ -65,7 +70,12 @@ async fn test_lock_v1_custom_group() { .dispatch() .await; assert_eq!(response.status(), Status::Ok); - assert_eq!(response.into_string().await, None); + assert_eq!( + response.into_string().await.as_deref(), + Some( + "Acquired reboot lock for group testgroup, host test1.example.org\n" + ) + ); let lease = get_lease("reboot-lock-testgroup").await.unwrap(); assert_eq!( lease.spec.unwrap().holder_identity.as_deref(), @@ -88,7 +98,12 @@ async fn test_lock_v1_conflict() { .dispatch() .await; assert_eq!(response.status(), Status::Ok); - assert_eq!(response.into_string().await, None); + assert_eq!( + response.into_string().await.as_deref(), + Some( + "Acquired reboot lock for group default, host test1.example.org\n" + ) + ); let response = client .post("/api/v1/lock") .header(Header::new("K8s-Reboot-Lock", "lock")) @@ -129,7 +144,12 @@ async fn test_lock_v1_conflict_wait() { .dispatch() .await; assert_eq!(response.status(), Status::Ok); - assert_eq!(response.into_string().await, None); + assert_eq!( + response.into_string().await.as_deref(), + Some( + "Acquired reboot lock for group default, host test1.example.org\n" + ) + ); let lease = get_lease("reboot-lock-default").await.unwrap(); assert_eq!( lease.spec.unwrap().holder_identity.as_deref(), @@ -153,7 +173,12 @@ async fn test_lock_v1_conflict_wait() { .dispatch() .await; assert_eq!(response.status(), Status::Ok); - assert_eq!(response.into_string().await, None); + assert_eq!( + response.into_string().await.as_deref(), + Some( + "Acquired reboot lock for group default, host test2.example.org\n" + ) + ); let duration = timer.elapsed().as_millis(); assert!(duration > 1000 && duration < 2000); let lease = get_lease("reboot-lock-default").await.unwrap(); @@ -213,7 +238,6 @@ async fn test_unlock_v1_success() { .dispatch() .await; assert_eq!(response.status(), Status::Ok); - assert_eq!(response.into_string().await, None); let lease = get_lease("reboot-lock-default").await.unwrap(); assert_eq!( lease.spec.unwrap().holder_identity.as_deref(), @@ -269,7 +293,6 @@ async fn test_unlock_v1_not_mine() { .dispatch() .await; assert_eq!(response.status(), Status::Ok); - assert_eq!(response.into_string().await, None); let lease = get_lease("reboot-lock-default").await.unwrap(); assert_eq!( lease.spec.unwrap().holder_identity.as_deref(),