Debian Codegraph @

src/response/values/event_action_value.rs

raw
1 //! Event Actions
2
3 use super::EnumDisplay;
4 use strum::{EnumIter, EnumString};
5
6 /// Event Actions registered in the IANA RDAP registry.
7 #[derive(PartialEq, Eq, Debug, EnumString, EnumDisplay, EnumIter)]
8 pub enum EventActionValue {
9 #[strum(serialize = "registration")]
10 Registration,
11 #[strum(serialize = "reregistration")]
12 Reregistration,
13 #[strum(serialize = "last changed")]
14 LastChanged,
15 #[strum(serialize = "expiration")]
16 Expiration,
17 #[strum(serialize = "deletion")]
18 Deletion,
19 #[strum(serialize = "reinstantiation")]
20 Reinstantiation,
21 #[strum(serialize = "transfer")]
22 Transfer,
23 #[strum(serialize = "locked")]
24 Locked,
25 #[strum(serialize = "unlocked")]
26 Unlocked,
27 #[strum(serialize = "last update of RDAP database")]
28 LastUpdateOfRDAPDatabase,
29 #[strum(serialize = "registrar expiration")]
30 RegistrarExpiration,
31 #[strum(serialize = "enum validation expiration")]
32 EnumValidationExpiration,
33 }
34
35 #[cfg(all(test, feature = "iana_registry_tests"))]
36 mod tests {
37 use super::*;
38 use strum::IntoEnumIterator;
39
40 const IANA_REGISTRY_URL: &str =
41 "https://www.iana.org/assignments/rdap-json-values/rdap-json-values.xml";
42
43 #[test]
44 fn iana_event_action_values_match_enum() {
45 let client = reqwest::blocking::Client::builder()
46 .user_agent("icann-rdap-iana-test")
47 .build()
48 .expect("failed to build reqwest client");
49 let resp = client
50 .get(IANA_REGISTRY_URL)
51 .header("Accept", "application/xml")
52 .send()
53 .expect("failed to fetch IANA RDAP JSON values registry");
54 let body = resp.text().expect("failed to read IANA registry body");
55
56 let mut iana_values: std::collections::HashSet<String> = std::collections::HashSet::new();
57 let records: Vec<&str> = body.split("<record").skip(1).collect();
58 for record in records {
59 let type_start = match record.find("<type>") {
60 Some(pos) => pos + 6,
61 None => continue,
62 };
63 let type_end = match record[type_start..].find("</type>") {
64 Some(len) => len,
65 None => continue,
66 };
67 let type_val = record[type_start..type_start + type_end].trim().to_string();
68 if type_val != "event action" {
69 continue;
70 }
71 let value_start = match record.find("<value>") {
72 Some(pos) => pos + 7,
73 None => continue,
74 };
75 let value_end = match record[value_start..].find("</value>") {
76 Some(len) => len,
77 None => continue,
78 };
79 let value = record[value_start..value_start + value_end]
80 .trim()
81 .to_string();
82 iana_values.insert(value);
83 }
84
85 let mut enum_values: std::collections::HashSet<String> = std::collections::HashSet::new();
86 for variant in EventActionValue::iter() {
87 enum_values.insert(variant.to_string());
88 }
89
90 let mut missing = Vec::new();
91 for value in &iana_values {
92 if !enum_values.contains(value) {
93 missing.push(value.clone());
94 }
95 }
96
97 let mut extra = Vec::new();
98 for value in &enum_values {
99 if !iana_values.contains(value) {
100 extra.push(value.clone());
101 }
102 }
103
104 missing.sort();
105 extra.sort();
106
107 if !missing.is_empty() || !extra.is_empty() {
108 let mut msg = String::from("EventActionValue enum does not match IANA registry:\n");
109 if !missing.is_empty() {
110 msg.push_str("Missing from enum:\n");
111 for v in &missing {
112 msg.push_str(&format!(" - {v}\n"));
113 }
114 }
115 if !extra.is_empty() {
116 msg.push_str("Not in IANA registry:\n");
117 for v in &extra {
118 msg.push_str(&format!(" - {v}\n"));
119 }
120 }
121 panic!("{msg}");
122 }
123 }
124 }