diff --git a/crates/xline-client/examples/lease.rs b/crates/xline-client/examples/lease.rs index 24f1babe5..56e5dd012 100644 --- a/crates/xline-client/examples/lease.rs +++ b/crates/xline-client/examples/lease.rs @@ -1,10 +1,5 @@ use anyhow::Result; -use xline_client::{ - types::lease::{ - LeaseGrantRequest, LeaseKeepAliveRequest, LeaseRevokeRequest, LeaseTimeToLiveRequest, - }, - Client, ClientOptions, -}; +use xline_client::{Client, ClientOptions}; #[tokio::main] async fn main() -> Result<()> { @@ -16,24 +11,20 @@ async fn main() -> Result<()> { .lease_client(); // grant new lease - let resp1 = client.grant(LeaseGrantRequest::new(60)).await?; - let resp2 = client.grant(LeaseGrantRequest::new(60)).await?; + let resp1 = client.grant(60, None).await?; + let resp2 = client.grant(60, None).await?; let lease_id1 = resp1.id; let lease_id2 = resp2.id; println!("lease id 1: {}", lease_id1); println!("lease id 2: {}", lease_id2); // get the ttl of lease1 - let resp = client - .time_to_live(LeaseTimeToLiveRequest::new(lease_id1)) - .await?; + let resp = client.time_to_live(lease_id1, false).await?; println!("remaining ttl: {}", resp.ttl); // keep alive lease2 - let (mut keeper, mut stream) = client - .keep_alive(LeaseKeepAliveRequest::new(lease_id2)) - .await?; + let (mut keeper, mut stream) = client.keep_alive(lease_id2).await?; if let Some(resp) = stream.message().await? { println!("new ttl: {}", resp.ttl); @@ -48,8 +39,8 @@ async fn main() -> Result<()> { } // revoke the leases - let _resp = client.revoke(LeaseRevokeRequest::new(lease_id1)).await?; - let _resp = client.revoke(LeaseRevokeRequest::new(lease_id2)).await?; + let _resp = client.revoke(lease_id1).await?; + let _resp = client.revoke(lease_id2).await?; Ok(()) } diff --git a/crates/xline-client/src/clients/lease.rs b/crates/xline-client/src/clients/lease.rs index b09577744..42b7a1e18 100644 --- a/crates/xline-client/src/clients/lease.rs +++ b/crates/xline-client/src/clients/lease.rs @@ -10,10 +10,7 @@ use xlineapi::{ use crate::{ error::{Result, XlineClientError}, lease_gen::LeaseIdGenerator, - types::lease::{ - LeaseGrantRequest, LeaseKeepAliveRequest, LeaseKeeper, LeaseRevokeRequest, - LeaseTimeToLiveRequest, - }, + types::lease::LeaseKeeper, AuthService, CurpClient, }; @@ -70,6 +67,9 @@ impl LeaseClient { /// within a given time to live period. All keys attached to the lease will be expired and /// deleted if the lease expires. Each expired key generates a delete event in the event history. /// + /// `ttl` is the advisory time-to-live in seconds. Expired lease will return -1. + /// `id` is the requested ID for the lease. If ID is set to `None` or 0, the lessor chooses an ID. + /// /// # Errors /// /// This function will return an error if the inner CURP client encountered a propose failure @@ -77,7 +77,7 @@ impl LeaseClient { /// # Examples /// /// ```no_run - /// use xline_client::{types::lease::LeaseGrantRequest, Client, ClientOptions}; + /// use xline_client::{Client, ClientOptions}; /// use anyhow::Result; /// /// #[tokio::main] @@ -88,19 +88,22 @@ impl LeaseClient { /// .await? /// .lease_client(); /// - /// let resp = client.grant(LeaseGrantRequest::new(60)).await?; + /// let resp = client.grant(60, None).await?; /// println!("lease id: {}", resp.id); /// /// Ok(()) /// } /// ``` #[inline] - pub async fn grant(&self, mut request: LeaseGrantRequest) -> Result { - if request.inner.id == 0 { - request.inner.id = self.id_gen.next(); + pub async fn grant(&self, ttl: i64, id: Option) -> Result { + let mut id = id.unwrap_or_default(); + if id == 0 { + id = self.id_gen.next(); } - let request = RequestWrapper::from(xlineapi::LeaseGrantRequest::from(request)); - let cmd = Command::new(request); + let cmd = Command::new(RequestWrapper::from(xlineapi::LeaseGrantRequest { + ttl, + id, + })); let (cmd_res, _sync_res) = self .curp_client .propose(&cmd, self.token.as_ref(), true) @@ -110,6 +113,8 @@ impl LeaseClient { /// Revokes a lease. All keys attached to the lease will expire and be deleted. /// + /// `id` is the lease ID to revoke. When the ID is revoked, all associated keys will be deleted. + /// /// # Errors /// /// This function will return an error if the inner RPC client encountered a propose failure @@ -117,7 +122,7 @@ impl LeaseClient { /// # Examples /// /// ```no_run - /// use xline_client::{types::lease::LeaseRevokeRequest, Client, ClientOptions}; + /// use xline_client::{Client, ClientOptions}; /// use anyhow::Result; /// /// #[tokio::main] @@ -130,20 +135,25 @@ impl LeaseClient { /// /// // granted a lease id 1 /// - /// let _resp = client.revoke(LeaseRevokeRequest::new(1)).await?; + /// let _resp = client.revoke(1).await?; /// /// Ok(()) /// } /// ``` #[inline] - pub async fn revoke(&mut self, request: LeaseRevokeRequest) -> Result { - let res = self.lease_client.lease_revoke(request.inner).await?; + pub async fn revoke(&mut self, id: i64) -> Result { + let res = self + .lease_client + .lease_revoke(xlineapi::LeaseRevokeRequest { id }) + .await?; Ok(res.into_inner()) } /// Keeps the lease alive by streaming keep alive requests from the client /// to the server and streaming keep alive responses from the server to the client. /// + /// `id` is the lease ID for the lease to keep alive. + /// /// # Errors /// /// This function will return an error if the inner RPC client encountered a propose failure @@ -151,7 +161,7 @@ impl LeaseClient { /// # Examples /// /// ```no_run - /// use xline_client::{types::lease::LeaseKeepAliveRequest, Client, ClientOptions}; + /// use xline_client::{Client, ClientOptions}; /// use anyhow::Result; /// /// #[tokio::main] @@ -164,7 +174,7 @@ impl LeaseClient { /// /// // granted a lease id 1 /// - /// let (mut keeper, mut stream) = client.keep_alive(LeaseKeepAliveRequest::new(1)).await?; + /// let (mut keeper, mut stream) = client.keep_alive(1).await?; /// /// if let Some(resp) = stream.message().await? { /// println!("new ttl: {}", resp.ttl); @@ -178,12 +188,12 @@ impl LeaseClient { #[inline] pub async fn keep_alive( &mut self, - request: LeaseKeepAliveRequest, + id: i64, ) -> Result<(LeaseKeeper, Streaming)> { let (mut sender, receiver) = channel::(100); sender - .try_send(request.into()) + .try_send(xlineapi::LeaseKeepAliveRequest { id }) .map_err(|e| XlineClientError::LeaseError(e.to_string()))?; let mut stream = self @@ -192,7 +202,7 @@ impl LeaseClient { .await? .into_inner(); - let id = match stream.message().await? { + let resp_id = match stream.message().await? { Some(resp) => resp.id, None => { return Err(XlineClientError::LeaseError(String::from( @@ -201,11 +211,14 @@ impl LeaseClient { } }; - Ok((LeaseKeeper::new(id, sender), stream)) + Ok((LeaseKeeper::new(resp_id, sender), stream)) } /// Retrieves lease information. /// + /// `id` is the lease ID for the lease, + /// `keys` is true to query all the keys attached to this lease. + /// /// # Errors /// /// This function will return an error if the inner RPC client encountered a propose failure @@ -213,7 +226,7 @@ impl LeaseClient { /// # Examples /// /// ```no_run - /// use xline_client::{types::lease::LeaseTimeToLiveRequest, Client, ClientOptions}; + /// use xline_client::{Client, ClientOptions}; /// use anyhow::Result; /// /// #[tokio::main] @@ -226,7 +239,7 @@ impl LeaseClient { /// /// // granted a lease id 1 /// - /// let resp = client.time_to_live(LeaseTimeToLiveRequest::new(1)).await?; + /// let resp = client.time_to_live(1, false).await?; /// /// println!("remaining ttl: {}", resp.ttl); /// @@ -234,13 +247,10 @@ impl LeaseClient { /// } /// ``` #[inline] - pub async fn time_to_live( - &mut self, - request: LeaseTimeToLiveRequest, - ) -> Result { + pub async fn time_to_live(&mut self, id: i64, keys: bool) -> Result { Ok(self .lease_client - .lease_time_to_live(xlineapi::LeaseTimeToLiveRequest::from(request)) + .lease_time_to_live(xlineapi::LeaseTimeToLiveRequest { id, keys }) .await? .into_inner()) } diff --git a/crates/xline-client/src/clients/lock.rs b/crates/xline-client/src/clients/lock.rs index d5761f6ad..322c4ab09 100644 --- a/crates/xline-client/src/clients/lock.rs +++ b/crates/xline-client/src/clients/lock.rs @@ -16,11 +16,7 @@ use crate::{ clients::{lease::LeaseClient, watch::WatchClient, DEFAULT_SESSION_TTL}, error::{Result, XlineClientError}, lease_gen::LeaseIdGenerator, - types::{ - kv::TxnRequest as KvTxnRequest, - lease::{LeaseGrantRequest, LeaseKeepAliveRequest}, - watch::WatchRequest, - }, + types::{kv::TxnRequest as KvTxnRequest, watch::WatchRequest}, CurpClient, }; @@ -130,19 +126,14 @@ impl Xutex { let lease_id = if let Some(id) = lease_id { id } else { - let lease_response = client - .lease_client - .grant(LeaseGrantRequest::new(ttl)) - .await?; + let lease_response = client.lease_client.grant(ttl, None).await?; lease_response.id }; let mut lease_client = client.lease_client.clone(); let keep_alive = Some(tokio::spawn(async move { /// The renew interval factor of which value equals 60% of one second. const RENEW_INTERVAL_FACTOR: u64 = 600; - let (mut keeper, mut stream) = lease_client - .keep_alive(LeaseKeepAliveRequest::new(lease_id)) - .await?; + let (mut keeper, mut stream) = lease_client.keep_alive(lease_id).await?; loop { keeper.keep_alive()?; if let Some(resp) = stream.message().await? { diff --git a/crates/xline-client/src/types/lease.rs b/crates/xline-client/src/types/lease.rs index fbf39fad6..03fa80cc2 100644 --- a/crates/xline-client/src/types/lease.rs +++ b/crates/xline-client/src/types/lease.rs @@ -38,137 +38,7 @@ impl LeaseKeeper { #[inline] pub fn keep_alive(&mut self) -> Result<()> { self.sender - .try_send(LeaseKeepAliveRequest::new(self.id).into()) + .try_send(xlineapi::LeaseKeepAliveRequest { id: self.id }) .map_err(|e| XlineClientError::LeaseError(e.to_string())) } } - -/// Request for `LeaseGrant` -#[derive(Debug, PartialEq)] -pub struct LeaseGrantRequest { - /// Inner request - pub(crate) inner: xlineapi::LeaseGrantRequest, -} - -impl LeaseGrantRequest { - /// Creates a new `LeaseGrantRequest` - /// - /// `ttl` is the advisory time-to-live in seconds. Expired lease will return -1. - #[inline] - #[must_use] - pub fn new(ttl: i64) -> Self { - Self { - inner: xlineapi::LeaseGrantRequest { - ttl, - ..Default::default() - }, - } - } - - /// `id` is the requested ID for the lease. If ID is set to 0, the lessor chooses an ID. - #[inline] - #[must_use] - pub fn with_id(mut self, id: i64) -> Self { - self.inner.id = id; - self - } -} - -impl From for xlineapi::LeaseGrantRequest { - #[inline] - fn from(req: LeaseGrantRequest) -> Self { - req.inner - } -} - -/// Request for `LeaseRevoke` -#[derive(Debug, PartialEq)] -pub struct LeaseRevokeRequest { - /// Inner request - pub(crate) inner: xlineapi::LeaseRevokeRequest, -} - -impl LeaseRevokeRequest { - /// Creates a new `LeaseRevokeRequest` - /// - /// `id` is the lease ID to revoke. When the ID is revoked, all associated keys will be deleted. - #[inline] - #[must_use] - pub fn new(id: i64) -> Self { - Self { - inner: xlineapi::LeaseRevokeRequest { id }, - } - } -} - -impl From for xlineapi::LeaseRevokeRequest { - #[inline] - fn from(req: LeaseRevokeRequest) -> Self { - req.inner - } -} - -/// Request for `LeaseKeepAlive` -#[derive(Debug, PartialEq)] -pub struct LeaseKeepAliveRequest { - /// Inner request - pub(crate) inner: xlineapi::LeaseKeepAliveRequest, -} - -impl LeaseKeepAliveRequest { - /// Creates a new `LeaseKeepAliveRequest` - /// - /// `id` is the lease ID for the lease to keep alive. - #[inline] - #[must_use] - pub fn new(id: i64) -> Self { - Self { - inner: xlineapi::LeaseKeepAliveRequest { id }, - } - } -} - -impl From for xlineapi::LeaseKeepAliveRequest { - #[inline] - fn from(req: LeaseKeepAliveRequest) -> Self { - req.inner - } -} - -/// Request for `LeaseTimeToLive` -#[derive(Debug, PartialEq)] -pub struct LeaseTimeToLiveRequest { - /// Inner request - pub(crate) inner: xlineapi::LeaseTimeToLiveRequest, -} - -impl LeaseTimeToLiveRequest { - /// Creates a new `LeaseTimeToLiveRequest` - /// - /// `id` is the lease ID for the lease. - #[inline] - #[must_use] - pub fn new(id: i64) -> Self { - Self { - inner: xlineapi::LeaseTimeToLiveRequest { - id, - ..Default::default() - }, - } - } - - /// `keys` is true to query all the keys attached to this lease. - #[inline] - #[must_use] - pub fn with_keys(mut self, keys: bool) -> Self { - self.inner.keys = keys; - self - } -} - -impl From for xlineapi::LeaseTimeToLiveRequest { - #[inline] - fn from(req: LeaseTimeToLiveRequest) -> Self { - req.inner - } -} diff --git a/crates/xline-client/tests/it/lease.rs b/crates/xline-client/tests/it/lease.rs index 4bab8caba..445162eb3 100644 --- a/crates/xline-client/tests/it/lease.rs +++ b/crates/xline-client/tests/it/lease.rs @@ -1,9 +1,4 @@ -use xline_client::{ - error::Result, - types::lease::{ - LeaseGrantRequest, LeaseKeepAliveRequest, LeaseRevokeRequest, LeaseTimeToLiveRequest, - }, -}; +use xline_client::error::Result; use super::common::get_cluster_client; @@ -12,10 +7,10 @@ async fn grant_revoke_should_success_in_normal_path() -> Result<()> { let (_cluster, client) = get_cluster_client().await.unwrap(); let mut client = client.lease_client(); - let resp = client.grant(LeaseGrantRequest::new(123)).await?; + let resp = client.grant(123, None).await?; assert_eq!(resp.ttl, 123); let id = resp.id; - client.revoke(LeaseRevokeRequest::new(id)).await?; + client.revoke(id).await?; Ok(()) } @@ -25,18 +20,18 @@ async fn keep_alive_should_success_in_normal_path() -> Result<()> { let (_cluster, client) = get_cluster_client().await.unwrap(); let mut client = client.lease_client(); - let resp = client.grant(LeaseGrantRequest::new(60)).await?; + let resp = client.grant(60, None).await?; assert_eq!(resp.ttl, 60); let id = resp.id; - let (mut keeper, mut stream) = client.keep_alive(LeaseKeepAliveRequest::new(id)).await?; + let (mut keeper, mut stream) = client.keep_alive(id).await?; keeper.keep_alive()?; let resp = stream.message().await?.unwrap(); assert_eq!(resp.id, keeper.id()); assert_eq!(resp.ttl, 60); - client.revoke(LeaseRevokeRequest::new(id)).await?; + client.revoke(id).await?; Ok(()) } @@ -47,19 +42,15 @@ async fn time_to_live_ttl_is_consistent_in_normal_path() -> Result<()> { let mut client = client.lease_client(); let lease_id = 200; - let resp = client - .grant(LeaseGrantRequest::new(60).with_id(lease_id)) - .await?; + let resp = client.grant(60, Some(lease_id)).await?; assert_eq!(resp.ttl, 60); assert_eq!(resp.id, lease_id); - let resp = client - .time_to_live(LeaseTimeToLiveRequest::new(lease_id)) - .await?; + let resp = client.time_to_live(lease_id, false).await?; assert_eq!(resp.id, lease_id); assert_eq!(resp.granted_ttl, 60); - client.revoke(LeaseRevokeRequest::new(lease_id)).await?; + client.revoke(lease_id).await?; Ok(()) } @@ -73,21 +64,15 @@ async fn leases_should_include_granted_in_normal_path() -> Result<()> { let (_cluster, client) = get_cluster_client().await.unwrap(); let mut client = client.lease_client(); - let resp = client - .grant(LeaseGrantRequest::new(60).with_id(lease1)) - .await?; + let resp = client.grant(60, Some(lease1)).await?; assert_eq!(resp.ttl, 60); assert_eq!(resp.id, lease1); - let resp = client - .grant(LeaseGrantRequest::new(60).with_id(lease2)) - .await?; + let resp = client.grant(60, Some(lease2)).await?; assert_eq!(resp.ttl, 60); assert_eq!(resp.id, lease2); - let resp = client - .grant(LeaseGrantRequest::new(60).with_id(lease3)) - .await?; + let resp = client.grant(60, Some(lease3)).await?; assert_eq!(resp.ttl, 60); assert_eq!(resp.id, lease3); @@ -97,9 +82,9 @@ async fn leases_should_include_granted_in_normal_path() -> Result<()> { assert!(leases.contains(&lease2)); assert!(leases.contains(&lease3)); - client.revoke(LeaseRevokeRequest::new(lease1)).await?; - client.revoke(LeaseRevokeRequest::new(lease2)).await?; - client.revoke(LeaseRevokeRequest::new(lease3)).await?; + client.revoke(lease1).await?; + client.revoke(lease2).await?; + client.revoke(lease3).await?; Ok(()) } diff --git a/crates/xline/tests/it/lease_test.rs b/crates/xline/tests/it/lease_test.rs index 392e59027..df1bda72e 100644 --- a/crates/xline/tests/it/lease_test.rs +++ b/crates/xline/tests/it/lease_test.rs @@ -3,10 +3,7 @@ use std::{error::Error, time::Duration}; use test_macros::abort_on_panic; use tracing::info; use xline_test_utils::{ - types::{ - kv::{PutOptions, RangeRequest}, - lease::{LeaseGrantRequest, LeaseKeepAliveRequest}, - }, + types::kv::{PutOptions, RangeRequest}, Client, ClientOptions, Cluster, }; @@ -17,10 +14,7 @@ async fn test_lease_expired() -> Result<(), Box> { cluster.start().await; let client = cluster.client().await; - let res = client - .lease_client() - .grant(LeaseGrantRequest::new(1)) - .await?; + let res = client.lease_client().grant(1, None).await?; let lease_id = res.id; assert!(lease_id > 0); @@ -52,10 +46,7 @@ async fn test_lease_keep_alive() -> Result<(), Box> { let non_leader_ep = cluster.get_client_url(1); let client = cluster.client().await; - let res = client - .lease_client() - .grant(LeaseGrantRequest::new(1)) - .await?; + let res = client.lease_client().grant(1, None).await?; let lease_id = res.id; assert!(lease_id > 0); @@ -74,7 +65,7 @@ async fn test_lease_keep_alive() -> Result<(), Box> { let mut c = Client::connect(vec![non_leader_ep], ClientOptions::default()) .await? .lease_client(); - let (mut keeper, mut stream) = c.keep_alive(LeaseKeepAliveRequest::new(lease_id)).await?; + let (mut keeper, mut stream) = c.keep_alive(lease_id).await?; let handle = tokio::spawn(async move { loop { tokio::time::sleep(Duration::from_millis(500)).await; diff --git a/crates/xlinectl/src/command/lease/grant.rs b/crates/xlinectl/src/command/lease/grant.rs index 3b3107434..fe452e775 100644 --- a/crates/xlinectl/src/command/lease/grant.rs +++ b/crates/xlinectl/src/command/lease/grant.rs @@ -1,5 +1,5 @@ use clap::{arg, value_parser, ArgMatches, Command}; -use xline_client::{error::Result, types::lease::LeaseGrantRequest, Client}; +use xline_client::{error::Result, Client}; use crate::utils::printer::Printer; @@ -11,15 +11,15 @@ pub(super) fn command() -> Command { } /// Build request from matches -pub(super) fn build_request(matches: &ArgMatches) -> LeaseGrantRequest { +pub(super) fn build_request(matches: &ArgMatches) -> i64 { let ttl = matches.get_one::("ttl").expect("required"); - LeaseGrantRequest::new(*ttl) + *ttl } /// Execute the command pub(super) async fn execute(client: &mut Client, matches: &ArgMatches) -> Result<()> { - let request = build_request(matches); - let resp = client.lease_client().grant(request).await?; + let ttl = build_request(matches); + let resp = client.lease_client().grant(ttl, None).await?; resp.print(); Ok(()) @@ -30,14 +30,11 @@ mod tests { use super::*; use crate::test_case_struct; - test_case_struct!(LeaseGrantRequest); + test_case_struct!(i64); #[test] fn command_parse_should_be_valid() { - let test_cases = vec![TestCase::new( - vec!["grant", "100"], - Some(LeaseGrantRequest::new(100)), - )]; + let test_cases = vec![TestCase::new(vec!["grant", "100"], Some(100))]; for case in test_cases { case.run_test(); diff --git a/crates/xlinectl/src/command/lease/keep_alive.rs b/crates/xlinectl/src/command/lease/keep_alive.rs index 67a208b21..fddfbab8a 100644 --- a/crates/xlinectl/src/command/lease/keep_alive.rs +++ b/crates/xlinectl/src/command/lease/keep_alive.rs @@ -5,7 +5,7 @@ use tokio::signal::ctrl_c; use tonic::Streaming; use xline_client::{ error::{Result, XlineClientError}, - types::lease::{LeaseKeepAliveRequest, LeaseKeeper}, + types::lease::LeaseKeeper, Client, }; use xlineapi::LeaseKeepAliveResponse; @@ -21,9 +21,9 @@ pub(super) fn command() -> Command { } /// Build request from matches -pub(super) fn build_request(matches: &ArgMatches) -> LeaseKeepAliveRequest { +pub(super) fn build_request(matches: &ArgMatches) -> i64 { let lease_id = matches.get_one::("leaseId").expect("required"); - LeaseKeepAliveRequest::new(*lease_id) + *lease_id } /// Execute the command @@ -80,19 +80,13 @@ mod tests { use super::*; use crate::test_case_struct; - test_case_struct!(LeaseKeepAliveRequest); + test_case_struct!(i64); #[test] fn command_parse_should_be_valid() { let test_cases = vec![ - TestCase::new( - vec!["keep_alive", "123"], - Some(LeaseKeepAliveRequest::new(123)), - ), - TestCase::new( - vec!["keep_alive", "456", "--once"], - Some(LeaseKeepAliveRequest::new(456)), - ), + TestCase::new(vec!["keep_alive", "123"], Some(123)), + TestCase::new(vec!["keep_alive", "456", "--once"], Some(456)), ]; for case in test_cases { diff --git a/crates/xlinectl/src/command/lease/revoke.rs b/crates/xlinectl/src/command/lease/revoke.rs index 1ccbdaf4a..12c9b6cce 100644 --- a/crates/xlinectl/src/command/lease/revoke.rs +++ b/crates/xlinectl/src/command/lease/revoke.rs @@ -1,5 +1,5 @@ use clap::{arg, value_parser, ArgMatches, Command}; -use xline_client::{error::Result, types::lease::LeaseRevokeRequest, Client}; +use xline_client::{error::Result, Client}; use crate::utils::printer::Printer; @@ -11,9 +11,9 @@ pub(super) fn command() -> Command { } /// Build request from matches -pub(super) fn build_request(matches: &ArgMatches) -> LeaseRevokeRequest { +pub(super) fn build_request(matches: &ArgMatches) -> i64 { let lease_id = matches.get_one::("leaseId").expect("required"); - LeaseRevokeRequest::new(*lease_id) + *lease_id } /// Execute the command @@ -30,14 +30,11 @@ mod tests { use super::*; use crate::test_case_struct; - test_case_struct!(LeaseRevokeRequest); + test_case_struct!(i64); #[test] fn command_parse_should_be_valid() { - let test_cases = vec![TestCase::new( - vec!["revoke", "123"], - Some(LeaseRevokeRequest::new(123)), - )]; + let test_cases = vec![TestCase::new(vec!["revoke", "123"], Some(123))]; for case in test_cases { case.run_test(); diff --git a/crates/xlinectl/src/command/lease/timetolive.rs b/crates/xlinectl/src/command/lease/timetolive.rs index b9bad3262..2860285ff 100644 --- a/crates/xlinectl/src/command/lease/timetolive.rs +++ b/crates/xlinectl/src/command/lease/timetolive.rs @@ -1,5 +1,5 @@ use clap::{arg, value_parser, ArgMatches, Command}; -use xline_client::{error::Result, types::lease::LeaseTimeToLiveRequest, Client}; +use xline_client::{error::Result, Client}; use crate::utils::printer::Printer; @@ -11,15 +11,15 @@ pub(super) fn command() -> Command { } /// Build request from matches -pub(super) fn build_request(matches: &ArgMatches) -> LeaseTimeToLiveRequest { +pub(super) fn build_request(matches: &ArgMatches) -> i64 { let lease_id = matches.get_one::("leaseId").expect("required"); - LeaseTimeToLiveRequest::new(*lease_id) + *lease_id } /// Execute the command pub(super) async fn execute(client: &mut Client, matches: &ArgMatches) -> Result<()> { let req = build_request(matches); - let resp = client.lease_client().time_to_live(req).await?; + let resp = client.lease_client().time_to_live(req, false).await?; resp.print(); Ok(()) @@ -30,14 +30,11 @@ mod tests { use super::*; use crate::test_case_struct; - test_case_struct!(LeaseTimeToLiveRequest); + test_case_struct!(i64); #[test] fn command_parse_should_be_valid() { - let test_cases = vec![TestCase::new( - vec!["timetolive", "123"], - Some(LeaseTimeToLiveRequest::new(123)), - )]; + let test_cases = vec![TestCase::new(vec!["timetolive", "123"], Some(123))]; for case in test_cases { case.run_test();