From d43d264e6dcaf97c367376ddbe020d08a9b4ef0f Mon Sep 17 00:00:00 2001 From: Miguel Duarte Barroso Date: Fri, 12 Jan 2024 10:25:50 +0100 Subject: [PATCH] linkAdd, test: rewrite test to use new methods If we make the `name` method of `LinkAddRequest` public we provide a better developer experience to the user, as shown in the refactored test. FWIW, in the `LinkSetRequest` structs, the `name` and `address` methods are already public. We also refactor the `name` method to re-use the `append_nla` method. Signed-off-by: Miguel Duarte Barroso --- src/link/add.rs | 5 ++--- src/link/test.rs | 15 +++++---------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/link/add.rs b/src/link/add.rs index 5714e1c..d3d5c31 100644 --- a/src/link/add.rs +++ b/src/link/add.rs @@ -790,9 +790,8 @@ impl LinkAddRequest { self.append_nla(LinkAttribute::LinkInfo(link_info_nlas)) } - fn name(mut self, name: String) -> Self { - self.message.attributes.push(LinkAttribute::IfName(name)); - self + pub fn name(self, name: String) -> Self { + self.append_nla(LinkAttribute::IfName(name)) } /// Define the hardware address of the link when creating it (equivalent to diff --git a/src/link/test.rs b/src/link/test.rs index c73fed4..a1d8725 100644 --- a/src/link/test.rs +++ b/src/link/test.rs @@ -120,16 +120,11 @@ async fn _create_macvlan( let (conn, handle, _) = new_connection().unwrap(); tokio::spawn(conn); let link_handle = handle.link(); - let mut req = - link_handle - .add() - .macvlan(name.to_string(), lower_device_index, mode); - req.message_mut() - .attributes - .push(LinkAttribute::IfName(name.to_owned())); - req.message_mut() - .attributes - .push(LinkAttribute::Address(mac)); + let req = link_handle + .add() + .macvlan(name.to_string(), lower_device_index, mode) + .name(name.to_owned()) + .address(mac); req.execute().await?; Ok(link_handle) }