@@ -71,9 +71,6 @@ pub fn arpa_qname_to_ip(qname: &str) -> Option<IpAddr> {
7171
7272#[ cfg( test) ]
7373mod tests {
74- use carbide_test_support:: Outcome :: * ;
75- use carbide_test_support:: { Case , check_cases_async} ;
76- use sqlx:: Row ;
7774
7875 #[ test]
7976 fn test_normalize_domain_name ( ) {
@@ -121,163 +118,6 @@ mod tests {
121118 ) ;
122119 }
123120
124- #[ crate :: sqlx_test]
125- async fn test_dns_hostname_from_ipv6_expands_to_rust_format ( pool : sqlx:: PgPool ) {
126- check_cases_async (
127- [
128- Case {
129- scenario : "ipv4 dotted-quad becomes dashed octets" ,
130- input : "192.168.1.2" ,
131- expect : Yields ( "192-168-1-2" . to_string ( ) ) ,
132- } ,
133- Case {
134- scenario : "unspecified address expands every hextet" ,
135- input : "::" ,
136- expect : Yields ( "0000-0000-0000-0000-0000-0000-0000-0000" . to_string ( ) ) ,
137- } ,
138- Case {
139- scenario : "loopback keeps the low hextet" ,
140- input : "::1" ,
141- expect : Yields ( "0000-0000-0000-0000-0000-0000-0000-0001" . to_string ( ) ) ,
142- } ,
143- Case {
144- scenario : "documentation prefix expands in full" ,
145- input : "2001:db8::2" ,
146- expect : Yields ( "2001-0db8-0000-0000-0000-0000-0000-0002" . to_string ( ) ) ,
147- } ,
148- Case {
149- scenario : "ipv4-mapped folds into the trailing hextets" ,
150- input : "::ffff:192.0.2.128" ,
151- expect : Yields ( "0000-0000-0000-0000-0000-ffff-c000-0280" . to_string ( ) ) ,
152- } ,
153- ] ,
154- |address| {
155- // Clone the (Arc-backed) pool per case so the future owns it and
156- // the closure stays `Fn` — see check_cases_async's signature.
157- let pool = pool. clone ( ) ;
158- async move {
159- sqlx:: query_scalar :: < _ , String > ( "SELECT nico_inet_to_dns_hostname($1::inet)" )
160- . bind ( address)
161- . fetch_one ( & pool)
162- . await
163- . map_err ( drop)
164- }
165- } ,
166- )
167- . await ;
168- }
169-
170- #[ crate :: sqlx_test]
171- async fn test_dns_records_instance_ipv6_qname_expands_hostname ( pool : sqlx:: PgPool ) {
172- sqlx:: query (
173- "INSERT INTO domains (id, name)
174- VALUES ('10000000-0000-0000-0000-000000000001', 'dwrt1.com')" ,
175- )
176- . execute ( & pool)
177- . await
178- . unwrap ( ) ;
179-
180- sqlx:: query (
181- "INSERT INTO network_segments (id, name, version)
182- VALUES ('20000000-0000-0000-0000-000000000001', 'tenant-segment', 'test')" ,
183- )
184- . execute ( & pool)
185- . await
186- . unwrap ( ) ;
187-
188- sqlx:: query (
189- "INSERT INTO machines (id, dpf)
190- VALUES ('host-1', '{\" enabled\" : true, \" used_for_ingestion\" : false}'::jsonb)" ,
191- )
192- . execute ( & pool)
193- . await
194- . unwrap ( ) ;
195-
196- sqlx:: query (
197- "INSERT INTO machine_interfaces (
198- id,
199- machine_id,
200- segment_id,
201- mac_address,
202- domain_id,
203- primary_interface,
204- hostname,
205- association_type
206- )
207- VALUES (
208- '30000000-0000-0000-0000-000000000001',
209- 'host-1',
210- '20000000-0000-0000-0000-000000000001',
211- '02:00:00:00:00:01',
212- '10000000-0000-0000-0000-000000000001',
213- true,
214- 'host-1',
215- 'Machine'
216- )" ,
217- )
218- . execute ( & pool)
219- . await
220- . unwrap ( ) ;
221-
222- let network_config = serde_json:: json!( {
223- "interfaces" : [
224- {
225- "function_id" : { "type" : "physical" } ,
226- "ip_addrs" : {
227- "unspecified" : "::" ,
228- "loopback" : "::1" ,
229- "tenant" : "2001:db8::2"
230- }
231- }
232- ]
233- } ) ;
234-
235- sqlx:: query ( "INSERT INTO instances (machine_id, network_config) VALUES ($1, $2::jsonb)" )
236- . bind ( "host-1" )
237- . bind ( network_config)
238- . execute ( & pool)
239- . await
240- . unwrap ( ) ;
241-
242- let rows = sqlx:: query (
243- "SELECT DISTINCT q_name, host(resource_record) AS resource_record
244- FROM dns_records_instance" ,
245- )
246- . fetch_all ( & pool)
247- . await
248- . unwrap ( ) ;
249-
250- let records = rows
251- . iter ( )
252- . map ( |row| {
253- (
254- row. try_get :: < String , _ > ( "resource_record" ) . unwrap ( ) ,
255- row. try_get :: < String , _ > ( "q_name" ) . unwrap ( ) ,
256- )
257- } )
258- . collect :: < Vec < _ > > ( ) ;
259-
260- let expected_records = vec ! [
261- (
262- "::" . to_string( ) ,
263- "0000-0000-0000-0000-0000-0000-0000-0000.dwrt1.com." . to_string( ) ,
264- ) ,
265- (
266- "::1" . to_string( ) ,
267- "0000-0000-0000-0000-0000-0000-0000-0001.dwrt1.com." . to_string( ) ,
268- ) ,
269- (
270- "2001:db8::2" . to_string( ) ,
271- "2001-0db8-0000-0000-0000-0000-0000-0002.dwrt1.com." . to_string( ) ,
272- ) ,
273- ] ;
274-
275- assert_eq ! ( records. len( ) , expected_records. len( ) ) ;
276- for expected_record in expected_records {
277- assert ! ( records. contains( & expected_record) ) ;
278- }
279- }
280-
281121 #[ crate :: sqlx_test]
282122 async fn find_ptr_record_resolves_address_to_hostname ( pool : sqlx:: PgPool ) {
283123 sqlx:: query (
0 commit comments