Skip to content

Commit 78a49d3

Browse files
committed
tests: add new example and test for extract_port
1 parent 578e653 commit 78a49d3

File tree

9 files changed

+165
-0
lines changed

9 files changed

+165
-0
lines changed

test/data/examples.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
example.com
22
example.com.ac
3+
example.com.ac:80
34
example.com.co
45
a.example.com
56
example.com/a
67
example.com.ac/a
78
https://example.com
89
https://a.example.com
10+
https://a.example.com:443
911
http://example.com.ac/path/?a=1&b=2&

test/sql/extract_domain.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,14 @@ SELECT extract_domain(uri) from uri_list;
187187
----
188188
example.com
189189
example.com.ac
190+
example.com.ac
190191
example.com.co
191192
example.com
192193
example.com
193194
example.com.ac
194195
example.com
195196
example.com
197+
example.com
196198
example.com.ac
197199

198200
# Test IP addresses

test/sql/extract_host.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,12 @@ SELECT extract_host(uri) from uri_list;
7777
----
7878
example.com
7979
example.com.ac
80+
example.com.ac
8081
example.com.co
8182
a.example.com
8283
example.com
8384
example.com.ac
8485
example.com
8586
a.example.com
87+
a.example.com
8688
example.com.ac

test/sql/extract_path.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,10 @@ SELECT extract_path(uri) from uri_list;
8484
/
8585
/
8686
/
87+
/
8788
/a
8889
/a
8990
/
9091
/
92+
/
9193
/path/

test/sql/extract_port.test

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
# name: test/sql/extract_port.test
2+
# description: test netquack extension extract_port function
3+
# group: [netquack]
4+
5+
require netquack
6+
7+
statement ok
8+
CREATE TABLE uri_list AS SELECT * FROM read_csv('test/data/examples.csv', header=false, columns={'uri': 'VARCHAR'});
9+
10+
# Basic HTTP/HTTPS cases
11+
query I
12+
SELECT extract_port('http://example.com:80/path');
13+
----
14+
80
15+
16+
query I
17+
SELECT extract_port('https://example.com:443/path');
18+
----
19+
443
20+
21+
# No port specified (should return NULL or default)
22+
query I
23+
SELECT extract_port('http://example.com/path');
24+
----
25+
(empty)
26+
27+
query I
28+
SELECT extract_port('https://example.com/');
29+
----
30+
(empty)
31+
32+
# Non-standard ports
33+
query I
34+
SELECT extract_port('http://example.com:8080/path');
35+
----
36+
8080
37+
38+
query I
39+
SELECT extract_port('https://example.com:8443/');
40+
----
41+
8443
42+
43+
# Different protocols
44+
query I
45+
SELECT extract_port('ftp://example.com:21');
46+
----
47+
21
48+
49+
query I
50+
SELECT extract_port('sftp://example.com:22/path');
51+
----
52+
22
53+
54+
query I
55+
SELECT extract_port('rsync://example.com:873');
56+
----
57+
873
58+
59+
# With authentication
60+
query I
61+
SELECT extract_port('https://user:[email protected]:443/path');
62+
----
63+
443
64+
65+
query I
66+
SELECT extract_port('ftp://user:[email protected]:2121/files');
67+
----
68+
2121
69+
70+
# IPv4 addresses
71+
query I
72+
SELECT extract_port('http://192.168.1.1:8080/path');
73+
----
74+
8080
75+
76+
# IPv6 addresses
77+
query I
78+
SELECT extract_port('http://[2001:db8::1]:8080/path');
79+
----
80+
8080
81+
82+
query I
83+
SELECT extract_port('http://[::1]:80/');
84+
----
85+
80
86+
87+
# No scheme cases
88+
query I
89+
SELECT extract_port('example.com:8080/path');
90+
----
91+
8080
92+
93+
query I
94+
SELECT extract_port('localhost:5432');
95+
----
96+
5432
97+
98+
query I
99+
SELECT extract_port('192.168.1.1:3389');
100+
----
101+
3389
102+
103+
query I
104+
SELECT extract_port('[::1]:6379');
105+
----
106+
6379
107+
108+
# Query parameters and fragments
109+
query I
110+
SELECT extract_port('http://example.com:8080?param=value');
111+
----
112+
8080
113+
114+
query I
115+
SELECT extract_port('https://example.com:8443#section');
116+
----
117+
8443
118+
119+
query I
120+
SELECT extract_port('ws://example.com:8080/path?query=1#frag');
121+
----
122+
8080
123+
124+
# Edge cases
125+
query I
126+
SELECT extract_port('http://example.com:/path');
127+
----
128+
(empty)
129+
130+
query I
131+
SELECT extract_port('http://example.com:notaport/path');
132+
----
133+
(empty)
134+
135+
# Test with data from CSV
136+
query I
137+
SELECT extract_port(uri) from uri_list;
138+
----
139+
(empty)
140+
(empty)
141+
80
142+
(empty)
143+
(empty)
144+
(empty)
145+
(empty)
146+
(empty)
147+
(empty)
148+
443
149+
(empty)

test/sql/extract_query.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,6 @@ SELECT extract_query_string(uri) from uri_list;
4343
(empty)
4444
(empty)
4545
(empty)
46+
(empty)
47+
(empty)
4648
a=1&b=2&

test/sql/extract_schema.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ SELECT extract_schema(uri) from uri_list;
213213
(empty)
214214
(empty)
215215
(empty)
216+
(empty)
217+
https
216218
https
217219
https
218220
http

test/sql/extract_subdomain.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,11 @@ SELECT extract_subdomain(uri) from uri_list;
143143
(empty)
144144
(empty)
145145
(empty)
146+
(empty)
146147
a
147148
(empty)
148149
(empty)
149150
(empty)
150151
a
152+
a
151153
(empty)

test/sql/extract_tld.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,12 @@ SELECT extract_tld(uri) from uri_list;
188188
----
189189
com
190190
com.ac
191+
com.ac
191192
com.co
192193
com
193194
com
194195
com.ac
195196
com
196197
com
198+
com
197199
com.ac

0 commit comments

Comments
 (0)