Add test cases for isIPAddressInRange

This commit is contained in:
vdimir 2021-03-29 13:24:52 +03:00
parent ae4b8e3181
commit b4c2980bf5
No known key found for this signature in database
GPG Key ID: F57B3E10A21DBB31
2 changed files with 30 additions and 0 deletions

View File

@ -28,6 +28,15 @@
::192.168.100.1 ::192.168.100.0/120 1
::192.168.103.255 ::192.168.100.0/118 1
::192.168.103.255 ::192.168.100.0/120 0
# Check with dense table
1
1
1
1
1
1
1
1
# Mismatching IP versions is not an error.
0
0

View File

@ -21,6 +21,27 @@ SELECT '# Invocation with non-constants';
WITH arrayJoin(['192.168.100.1', '192.168.103.255']) as addr, arrayJoin(['192.168.100.0/22', '192.168.100.0/24']) as prefix SELECT addr, prefix, isIPAddressInRange(addr, prefix);
WITH arrayJoin(['::192.168.100.1', '::192.168.103.255']) as addr, arrayJoin(['::192.168.100.0/118', '::192.168.100.0/120']) as prefix SELECT addr, prefix, isIPAddressInRange(addr, prefix);
SELECT '# Check with dense table';
DROP TABLE IF EXISTS test_data;
CREATE TABLE test_data (cidr String) ENGINE = Memory;
INSERT INTO test_data
SELECT
IPv4NumToString(IPv4CIDRToRange(IPv4StringToNum('255.255.255.255'), toUInt8(number)).1) || '/' || toString(number) AS cidr
FROM system.numbers LIMIT 33;
SELECT sum(isIPAddressInRange('0.0.0.0', cidr)) == 1 FROM test_data;
SELECT sum(isIPAddressInRange('127.0.0.0', cidr)) == 1 FROM test_data;
SELECT sum(isIPAddressInRange('128.0.0.0', cidr)) == 2 FROM test_data;
SELECT sum(isIPAddressInRange('255.0.0.0', cidr)) == 9 FROM test_data;
SELECT sum(isIPAddressInRange('255.0.0.1', cidr)) == 9 FROM test_data;
SELECT sum(isIPAddressInRange('255.0.0.255', cidr)) == 9 FROM test_data;
SELECT sum(isIPAddressInRange('255.255.255.255', cidr)) == 33 FROM test_data;
SELECT sum(isIPAddressInRange('255.255.255.254', cidr)) == 32 FROM test_data;
DROP TABLE IF EXISTS test_data;
SELECT '# Mismatching IP versions is not an error.';
SELECT isIPAddressInRange('127.0.0.1', 'ffff::/16');