epp_client/host/
delete.rs

1//! Types for EPP host delete request
2
3use super::XMLNS;
4use crate::common::{NoExtension, StringValue};
5use crate::request::{Command, Transaction};
6use serde::Serialize;
7
8impl<'a> Transaction<NoExtension> for HostDelete<'a> {}
9
10impl<'a> Command for HostDelete<'a> {
11    type Response = ();
12    const COMMAND: &'static str = "delete";
13}
14
15impl<'a> HostDelete<'a> {
16    pub fn new(name: &'a str) -> Self {
17        Self {
18            host: HostDeleteRequestData {
19                xmlns: XMLNS,
20                name: name.into(),
21            },
22        }
23    }
24}
25
26/// Type for data under the host &lt;delete&gt; tag
27#[derive(Serialize, Debug)]
28pub struct HostDeleteRequestData<'a> {
29    /// XML namespace for host commands
30    #[serde(rename = "xmlns:host")]
31    xmlns: &'a str,
32    /// The host to be deleted
33    #[serde(rename = "host:name")]
34    name: StringValue<'a>,
35}
36
37#[derive(Serialize, Debug)]
38/// Type for EPP XML &lt;delete&gt; command for hosts
39pub struct HostDelete<'a> {
40    /// The instance holding the data for the host to be deleted
41    #[serde(rename = "host:delete")]
42    host: HostDeleteRequestData<'a>,
43}
44
45#[cfg(test)]
46mod tests {
47    use super::HostDelete;
48    use crate::response::ResultCode;
49    use crate::tests::{assert_serialized, response_from_file, CLTRID, SUCCESS_MSG, SVTRID};
50
51    #[test]
52    fn command() {
53        let object = HostDelete::new("ns1.eppdev-1.com");
54        assert_serialized("request/host/delete.xml", &object);
55    }
56
57    #[test]
58    fn response() {
59        let object = response_from_file::<HostDelete>("response/host/delete.xml");
60        assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
61        assert_eq!(object.result.message, SUCCESS_MSG.into());
62        assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into());
63        assert_eq!(object.tr_ids.server_tr_id, SVTRID.into());
64    }
65}