mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
Add test cases for isIPAddressInRange
This commit is contained in:
parent
ae4b8e3181
commit
b4c2980bf5
@ -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
|
||||
|
@ -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');
|
||||
|
Loading…
Reference in New Issue
Block a user