Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4f07134

Browse files
committed
Improve test coverage of network address functions
The following functions were not covered by any tests:- abbrev(inet)- set_masklen(cidr)- set_masklen(inet)- netmask(inet)- hostmask(inet)While on it, this improves the output of some of the existing queries inthe test inet to use better aliases.Author: Aleksander AlekseevReviewed-by: Jacob Champion, Keisuke Kuroda, Tom LaneDiscussion:https://postgr.es/m/CAJ7c6TOyZ9bGNrDK6Z3Q0gr9ow8ZpOm+=+01mpE0dsdH4C+u9A@mail.gmail.com
1 parent75eb976 commit4f07134

File tree

2 files changed

+135
-49
lines changed

2 files changed

+135
-49
lines changed

‎src/test/regress/expected/inet.out

Lines changed: 119 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -88,31 +88,32 @@ SELECT i AS inet, host(i), text(i), family(i) FROM INET_TBL;
8888
::4.3.2.1/24 | ::4.3.2.1 | ::4.3.2.1/24 | 6
8989
(17 rows)
9090

91-
SELECT c AS cidr, abbrev(c) FROM INET_TBL;
92-
cidr | abbrev
93-
--------------------+--------------------
94-
192.168.1.0/24 | 192.168.1/24
95-
192.168.1.0/26 | 192.168.1.0/26
96-
192.168.1.0/24 | 192.168.1/24
97-
192.168.1.0/24 | 192.168.1/24
98-
192.168.1.0/24 | 192.168.1/24
99-
192.168.1.0/24 | 192.168.1/24
100-
10.0.0.0/8 | 10/8
101-
10.0.0.0/32 | 10.0.0.0/32
102-
10.1.2.3/32 | 10.1.2.3/32
103-
10.1.2.0/24 | 10.1.2/24
104-
10.1.0.0/16 | 10.1/16
105-
10.0.0.0/8 | 10/8
106-
10.0.0.0/8 | 10/8
107-
10.0.0.0/8 | 10/8
108-
10:23::f1/128 | 10:23::f1/128
109-
10:23::8000/113 | 10:23::8000/113
110-
::ffff:1.2.3.4/128 | ::ffff:1.2.3.4/128
91+
SELECT c AS cidr, abbrev(c) AS "abbrev(cidr)",
92+
i AS inet, abbrev(i) AS "abbrev(inet)" FROM INET_TBL;
93+
cidr | abbrev(cidr) | inet | abbrev(inet)
94+
--------------------+--------------------+------------------+------------------
95+
192.168.1.0/24 | 192.168.1/24 | 192.168.1.226/24 | 192.168.1.226/24
96+
192.168.1.0/26 | 192.168.1.0/26 | 192.168.1.226 | 192.168.1.226
97+
192.168.1.0/24 | 192.168.1/24 | 192.168.1.0/24 | 192.168.1.0/24
98+
192.168.1.0/24 | 192.168.1/24 | 192.168.1.0/25 | 192.168.1.0/25
99+
192.168.1.0/24 | 192.168.1/24 | 192.168.1.255/24 | 192.168.1.255/24
100+
192.168.1.0/24 | 192.168.1/24 | 192.168.1.255/25 | 192.168.1.255/25
101+
10.0.0.0/8 | 10/8 | 10.1.2.3/8 | 10.1.2.3/8
102+
10.0.0.0/32 | 10.0.0.0/32 | 10.1.2.3/8 | 10.1.2.3/8
103+
10.1.2.3/32 | 10.1.2.3/32 | 10.1.2.3 | 10.1.2.3
104+
10.1.2.0/24 | 10.1.2/24 | 10.1.2.3/24 | 10.1.2.3/24
105+
10.1.0.0/16 | 10.1/16 | 10.1.2.3/16 | 10.1.2.3/16
106+
10.0.0.0/8 | 10/8 | 10.1.2.3/8 | 10.1.2.3/8
107+
10.0.0.0/8 | 10/8 | 11.1.2.3/8 | 11.1.2.3/8
108+
10.0.0.0/8 | 10/8 | 9.1.2.3/8 | 9.1.2.3/8
109+
10:23::f1/128 | 10:23::f1/128 | 10:23::f1/64 | 10:23::f1/64
110+
10:23::8000/113 | 10:23::8000/113 | 10:23::ffff | 10:23::ffff
111+
::ffff:1.2.3.4/128 | ::ffff:1.2.3.4/128 | ::4.3.2.1/24 | ::4.3.2.1/24
111112
(17 rows)
112113

113-
SELECT c AS cidr, broadcast(c),
114-
i AS inet, broadcast(i) FROM INET_TBL;
115-
cidr |broadcast| inet |broadcast
114+
SELECT c AS cidr, broadcast(c) AS "broadcast(cidr)",
115+
i AS inet, broadcast(i)AS "broadcast(inet)"FROM INET_TBL;
116+
cidr | broadcast(cidr)| inet | broadcast(inet)
116117
--------------------+------------------+------------------+---------------------------------------
117118
192.168.1.0/24 | 192.168.1.255/24 | 192.168.1.226/24 | 192.168.1.255/24
118119
192.168.1.0/26 | 192.168.1.63/26 | 192.168.1.226 | 192.168.1.226
@@ -190,6 +191,50 @@ SELECT c AS cidr, masklen(c) AS "masklen(cidr)",
190191
10.0.0.0/8 | 8 | 9.1.2.3/8 | 8
191192
(4 rows)
192193

194+
SELECT i AS inet, netmask(i) AS "netmask(inet)" FROM INET_TBL;
195+
inet | netmask(inet)
196+
------------------+-----------------------------------------
197+
192.168.1.226/24 | 255.255.255.0
198+
192.168.1.226 | 255.255.255.255
199+
192.168.1.0/24 | 255.255.255.0
200+
192.168.1.0/25 | 255.255.255.128
201+
192.168.1.255/24 | 255.255.255.0
202+
192.168.1.255/25 | 255.255.255.128
203+
10.1.2.3/8 | 255.0.0.0
204+
10.1.2.3/8 | 255.0.0.0
205+
10.1.2.3 | 255.255.255.255
206+
10.1.2.3/24 | 255.255.255.0
207+
10.1.2.3/16 | 255.255.0.0
208+
10.1.2.3/8 | 255.0.0.0
209+
11.1.2.3/8 | 255.0.0.0
210+
9.1.2.3/8 | 255.0.0.0
211+
10:23::f1/64 | ffff:ffff:ffff:ffff::
212+
10:23::ffff | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff
213+
::4.3.2.1/24 | ffff:ff00::
214+
(17 rows)
215+
216+
SELECT i AS inet, hostmask(i) AS "hostmask(inet)" FROM INET_TBL;
217+
inet | hostmask(inet)
218+
------------------+------------------------------------
219+
192.168.1.226/24 | 0.0.0.255
220+
192.168.1.226 | 0.0.0.0
221+
192.168.1.0/24 | 0.0.0.255
222+
192.168.1.0/25 | 0.0.0.127
223+
192.168.1.255/24 | 0.0.0.255
224+
192.168.1.255/25 | 0.0.0.127
225+
10.1.2.3/8 | 0.255.255.255
226+
10.1.2.3/8 | 0.255.255.255
227+
10.1.2.3 | 0.0.0.0
228+
10.1.2.3/24 | 0.0.0.255
229+
10.1.2.3/16 | 0.0.255.255
230+
10.1.2.3/8 | 0.255.255.255
231+
11.1.2.3/8 | 0.255.255.255
232+
9.1.2.3/8 | 0.255.255.255
233+
10:23::f1/64 | ::ffff:ffff:ffff:ffff
234+
10:23::ffff | ::
235+
::4.3.2.1/24 | 0:ff:ffff:ffff:ffff:ffff:ffff:ffff
236+
(17 rows)
237+
193238
SELECT c AS cidr, i AS inet FROM INET_TBL
194239
WHERE c = i;
195240
cidr | inet
@@ -238,29 +283,59 @@ SELECT max(c) AS max, min(c) AS min FROM INET_TBL;
238283
10:23::8000/113 | 10.0.0.0/8
239284
(1 row)
240285

241-
-- check the conversion to/from text and set_netmask
242-
SELECT set_masklen(inet(text(i)), 24) FROM INET_TBL;
243-
set_masklen
244-
------------------
245-
192.168.1.226/24
246-
192.168.1.226/24
247-
192.168.1.0/24
248-
192.168.1.0/24
249-
192.168.1.255/24
250-
192.168.1.255/24
251-
10.1.2.3/24
252-
10.1.2.3/24
253-
10.1.2.3/24
254-
10.1.2.3/24
255-
10.1.2.3/24
256-
10.1.2.3/24
257-
11.1.2.3/24
258-
9.1.2.3/24
259-
10:23::f1/24
260-
10:23::ffff/24
261-
::4.3.2.1/24
286+
-- check the conversion to/from text and setting netmask
287+
SELECT c AS cidr, set_masklen(cidr(text(c)), 24) AS "set_masklen(cidr)",
288+
i AS inet, set_masklen(inet(text(i)), 24) AS "set_masklen(inet)" FROM INET_TBL;
289+
cidr | set_masklen(cidr) | inet | set_masklen(inet)
290+
--------------------+-------------------+------------------+-------------------
291+
192.168.1.0/24 | 192.168.1.0/24 | 192.168.1.226/24 | 192.168.1.226/24
292+
192.168.1.0/26 | 192.168.1.0/24 | 192.168.1.226 | 192.168.1.226/24
293+
192.168.1.0/24 | 192.168.1.0/24 | 192.168.1.0/24 | 192.168.1.0/24
294+
192.168.1.0/24 | 192.168.1.0/24 | 192.168.1.0/25 | 192.168.1.0/24
295+
192.168.1.0/24 | 192.168.1.0/24 | 192.168.1.255/24 | 192.168.1.255/24
296+
192.168.1.0/24 | 192.168.1.0/24 | 192.168.1.255/25 | 192.168.1.255/24
297+
10.0.0.0/8 | 10.0.0.0/24 | 10.1.2.3/8 | 10.1.2.3/24
298+
10.0.0.0/32 | 10.0.0.0/24 | 10.1.2.3/8 | 10.1.2.3/24
299+
10.1.2.3/32 | 10.1.2.0/24 | 10.1.2.3 | 10.1.2.3/24
300+
10.1.2.0/24 | 10.1.2.0/24 | 10.1.2.3/24 | 10.1.2.3/24
301+
10.1.0.0/16 | 10.1.0.0/24 | 10.1.2.3/16 | 10.1.2.3/24
302+
10.0.0.0/8 | 10.0.0.0/24 | 10.1.2.3/8 | 10.1.2.3/24
303+
10.0.0.0/8 | 10.0.0.0/24 | 11.1.2.3/8 | 11.1.2.3/24
304+
10.0.0.0/8 | 10.0.0.0/24 | 9.1.2.3/8 | 9.1.2.3/24
305+
10:23::f1/128 | 10::/24 | 10:23::f1/64 | 10:23::f1/24
306+
10:23::8000/113 | 10::/24 | 10:23::ffff | 10:23::ffff/24
307+
::ffff:1.2.3.4/128 | ::/24 | ::4.3.2.1/24 | ::4.3.2.1/24
308+
(17 rows)
309+
310+
-- check that netmask is treated as maximum value when set to -1
311+
SELECT c AS cidr, set_masklen(cidr(text(c)), -1) AS "set_masklen(cidr)",
312+
i AS inet, set_masklen(inet(text(i)), -1) AS "set_masklen(inet)" FROM INET_TBL;
313+
cidr | set_masklen(cidr) | inet | set_masklen(inet)
314+
--------------------+--------------------+------------------+-------------------
315+
192.168.1.0/24 | 192.168.1.0/32 | 192.168.1.226/24 | 192.168.1.226
316+
192.168.1.0/26 | 192.168.1.0/32 | 192.168.1.226 | 192.168.1.226
317+
192.168.1.0/24 | 192.168.1.0/32 | 192.168.1.0/24 | 192.168.1.0
318+
192.168.1.0/24 | 192.168.1.0/32 | 192.168.1.0/25 | 192.168.1.0
319+
192.168.1.0/24 | 192.168.1.0/32 | 192.168.1.255/24 | 192.168.1.255
320+
192.168.1.0/24 | 192.168.1.0/32 | 192.168.1.255/25 | 192.168.1.255
321+
10.0.0.0/8 | 10.0.0.0/32 | 10.1.2.3/8 | 10.1.2.3
322+
10.0.0.0/32 | 10.0.0.0/32 | 10.1.2.3/8 | 10.1.2.3
323+
10.1.2.3/32 | 10.1.2.3/32 | 10.1.2.3 | 10.1.2.3
324+
10.1.2.0/24 | 10.1.2.0/32 | 10.1.2.3/24 | 10.1.2.3
325+
10.1.0.0/16 | 10.1.0.0/32 | 10.1.2.3/16 | 10.1.2.3
326+
10.0.0.0/8 | 10.0.0.0/32 | 10.1.2.3/8 | 10.1.2.3
327+
10.0.0.0/8 | 10.0.0.0/32 | 11.1.2.3/8 | 11.1.2.3
328+
10.0.0.0/8 | 10.0.0.0/32 | 9.1.2.3/8 | 9.1.2.3
329+
10:23::f1/128 | 10:23::f1/128 | 10:23::f1/64 | 10:23::f1
330+
10:23::8000/113 | 10:23::8000/128 | 10:23::ffff | 10:23::ffff
331+
::ffff:1.2.3.4/128 | ::ffff:1.2.3.4/128 | ::4.3.2.1/24 | ::4.3.2.1
262332
(17 rows)
263333

334+
-- check that invalid netmask is rejected
335+
SELECT set_masklen(inet(text(i)), 33) FROM INET_TBL;
336+
ERROR: invalid mask length: 33
337+
SELECT set_masklen(cidr(text(c)), 33) FROM INET_TBL;
338+
ERROR: invalid mask length: 33
264339
-- check that btree index works correctly
265340
CREATE INDEX inet_idx1 ON inet_tbl(i);
266341
SET enable_seqscan TO off;

‎src/test/regress/sql/inet.sql

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ SELECT c AS cidr, i AS inet FROM INET_TBL;
3434
-- now test some support functions
3535

3636
SELECT iASinet, host(i),text(i), family(i)FROM INET_TBL;
37-
SELECT cAScidr, abbrev(c)FROM INET_TBL;
38-
SELECT cAScidr, broadcast(c),
39-
iASinet, broadcast(i)FROM INET_TBL;
37+
SELECT cAScidr, abbrev(c)AS"abbrev(cidr)",
38+
iASinet, abbrev(i)AS"abbrev(inet)"FROM INET_TBL;
39+
SELECT cAScidr, broadcast(c)AS"broadcast(cidr)",
40+
iASinet, broadcast(i)AS"broadcast(inet)"FROM INET_TBL;
4041
SELECT cAScidr, network(c)AS"network(cidr)",
4142
iASinet, network(i)AS"network(inet)"FROM INET_TBL;
4243
SELECT cAScidr, masklen(c)AS"masklen(cidr)",
@@ -46,6 +47,9 @@ SELECT c AS cidr, masklen(c) AS "masklen(cidr)",
4647
iASinet, masklen(i)AS"masklen(inet)"FROM INET_TBL
4748
WHERE masklen(c)<=8;
4849

50+
SELECT iASinet, netmask(i)AS"netmask(inet)"FROM INET_TBL;
51+
SELECT iASinet, hostmask(i)AS"hostmask(inet)"FROM INET_TBL;
52+
4953
SELECT cAScidr, iASinetFROM INET_TBL
5054
WHERE c= i;
5155

@@ -60,8 +64,15 @@ SELECT i, c,
6064
SELECTmax(i)AS max,min(i)AS minFROM INET_TBL;
6165
SELECTmax(c)AS max,min(c)AS minFROM INET_TBL;
6266

63-
-- check the conversion to/from text and set_netmask
64-
SELECT set_masklen(inet(text(i)),24)FROM INET_TBL;
67+
-- check the conversion to/from text and setting netmask
68+
SELECT cAScidr, set_masklen(cidr(text(c)),24)AS"set_masklen(cidr)",
69+
iASinet, set_masklen(inet(text(i)),24)AS"set_masklen(inet)"FROM INET_TBL;
70+
-- check that netmask is treated as maximum value when set to -1
71+
SELECT cAScidr, set_masklen(cidr(text(c)),-1)AS"set_masklen(cidr)",
72+
iASinet, set_masklen(inet(text(i)),-1)AS"set_masklen(inet)"FROM INET_TBL;
73+
-- check that invalid netmask is rejected
74+
SELECT set_masklen(inet(text(i)),33)FROM INET_TBL;
75+
SELECT set_masklen(cidr(text(c)),33)FROM INET_TBL;
6576

6677
-- check that btree index works correctly
6778
CREATEINDEXinet_idx1ON inet_tbl(i);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp