Skip to content

Commit

Permalink
linkAdd, test: rewrite test to use new methods
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
maiqueb committed Jan 12, 2024
1 parent 5806489 commit d43d264
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
5 changes: 2 additions & 3 deletions src/link/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 5 additions & 10 deletions src/link/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit d43d264

Please sign in to comment.