mirror of
https://github.com/postgres/postgres.git
synced 2025-11-03 09:13:20 +03:00
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 in the test inet to use better aliases. Author: Aleksander Alekseev Reviewed-by: Jacob Champion, Keisuke Kuroda, Tom Lane Discussion: https://postgr.es/m/CAJ7c6TOyZ9bGNrDK6Z3Q0gr9ow8ZpOm+=+01mpE0dsdH4C+u9A@mail.gmail.com
This commit is contained in:
@@ -34,9 +34,10 @@ SELECT c AS cidr, i AS inet FROM INET_TBL;
|
||||
-- now test some support functions
|
||||
|
||||
SELECT i AS inet, host(i), text(i), family(i) FROM INET_TBL;
|
||||
SELECT c AS cidr, abbrev(c) FROM INET_TBL;
|
||||
SELECT c AS cidr, broadcast(c),
|
||||
i AS inet, broadcast(i) FROM INET_TBL;
|
||||
SELECT c AS cidr, abbrev(c) AS "abbrev(cidr)",
|
||||
i AS inet, abbrev(i) AS "abbrev(inet)" FROM INET_TBL;
|
||||
SELECT c AS cidr, broadcast(c) AS "broadcast(cidr)",
|
||||
i AS inet, broadcast(i) AS "broadcast(inet)" FROM INET_TBL;
|
||||
SELECT c AS cidr, network(c) AS "network(cidr)",
|
||||
i AS inet, network(i) AS "network(inet)" FROM INET_TBL;
|
||||
SELECT c AS cidr, masklen(c) AS "masklen(cidr)",
|
||||
@@ -46,6 +47,9 @@ SELECT c AS cidr, masklen(c) AS "masklen(cidr)",
|
||||
i AS inet, masklen(i) AS "masklen(inet)" FROM INET_TBL
|
||||
WHERE masklen(c) <= 8;
|
||||
|
||||
SELECT i AS inet, netmask(i) AS "netmask(inet)" FROM INET_TBL;
|
||||
SELECT i AS inet, hostmask(i) AS "hostmask(inet)" FROM INET_TBL;
|
||||
|
||||
SELECT c AS cidr, i AS inet FROM INET_TBL
|
||||
WHERE c = i;
|
||||
|
||||
@@ -60,8 +64,15 @@ SELECT i, c,
|
||||
SELECT max(i) AS max, min(i) AS min FROM INET_TBL;
|
||||
SELECT max(c) AS max, min(c) AS min FROM INET_TBL;
|
||||
|
||||
-- check the conversion to/from text and set_netmask
|
||||
SELECT set_masklen(inet(text(i)), 24) FROM INET_TBL;
|
||||
-- check the conversion to/from text and setting netmask
|
||||
SELECT c AS cidr, set_masklen(cidr(text(c)), 24) AS "set_masklen(cidr)",
|
||||
i AS inet, set_masklen(inet(text(i)), 24) AS "set_masklen(inet)" FROM INET_TBL;
|
||||
-- check that netmask is treated as maximum value when set to -1
|
||||
SELECT c AS cidr, set_masklen(cidr(text(c)), -1) AS "set_masklen(cidr)",
|
||||
i AS inet, set_masklen(inet(text(i)), -1) AS "set_masklen(inet)" FROM INET_TBL;
|
||||
-- check that invalid netmask is rejected
|
||||
SELECT set_masklen(inet(text(i)), 33) FROM INET_TBL;
|
||||
SELECT set_masklen(cidr(text(c)), 33) FROM INET_TBL;
|
||||
|
||||
-- check that btree index works correctly
|
||||
CREATE INDEX inet_idx1 ON inet_tbl(i);
|
||||
|
||||
Reference in New Issue
Block a user