Skip to content

Commit 584de17

Browse files
committed
Extend csv tests and register as an example
1 parent 295931a commit 584de17

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

x-pack/plugin/esql/qa/testFixtures/src/main/resources/ip.csv-spec

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,25 @@ eth0 |gamma |fe80::cae2:65ff:fece:feb9
181181
eth0 |epsilon |[fe80::cae2:65ff:fece:feb9, fe80::cae2:65ff:fece:fec0, fe80::cae2:65ff:fece:fec1]|fe80::cae2:65ff:fece:fec1|fe80::cae2:65ff:fece:fec1
182182
;
183183

184+
networkDirectionSimple
185+
186+
FROM hosts |
187+
WHERE mv_count(ip0) == 1 AND mv_count(ip1) == 1 |
188+
EVAL direction = network_direction(ip0, ip1, ["loopback"]) |
189+
KEEP ip0, ip1, direction
190+
;
191+
192+
193+
ip0:ip | ip1:ip | direction:keyword
194+
127.0.0.1 | 127.0.0.1 | internal
195+
::1 | ::1 | internal
196+
127.0.0.1 | ::1 | internal
197+
127.0.0.1 | 127.0.0.2 | internal
198+
127.0.0.1 | 128.0.0.1 | outbound
199+
fe80::cae2:65ff:fece:feb9 | fe81::cae2:65ff:fece:feb9 | external
200+
fe80::cae2:65ff:fece:feb9 | 127.0.0.3 | inbound
201+
;
202+
184203
cidrMatchSimple
185204

186205
from hosts | where cidr_match(ip1, "127.0.0.2/32") | keep card, host, ip0, ip1;

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/ip/NetworkDirection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class NetworkDirection extends EsqlScalarFunction {
5252
@FunctionInfo(
5353
returnType = "keyword",
5454
description = "Returns true if the direction of the source-to-destination-IPs is determined to be inbound, provided a list of internal networks.",
55-
examples = @Example(file = "ip", tag = "cdirMatchMultipleArgs") // TODO make an example
55+
examples = @Example(file = "ip", tag = "networkDirectionSimple")
5656
)
5757
public NetworkDirection(
5858
Source source,

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/ip/NetworkDirectionTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public static Iterable<Object[]> parameters() {
7575
List.of(
7676
new TestCaseSupplier.TypedData(EsqlDataTypeConverter.stringToIP("0.0.0.0"), DataType.IP, "source_ip"),
7777
new TestCaseSupplier.TypedData(EsqlDataTypeConverter.stringToIP("0.0.0.0"), DataType.IP, "destination_ip"),
78-
new TestCaseSupplier.TypedData(new BytesRef("unspecified"), stringType, "internal_networks") // TODO: unspecified causes errors
78+
new TestCaseSupplier.TypedData(new BytesRef("unspecified"), stringType, "internal_networks")
7979
),
8080
"NetworkDirectionEvaluator[sourceIp=Attribute[channel=0], destinationIp=Attribute[channel=1], networks=Attribute[channel=2]]",
8181
DataType.KEYWORD,

0 commit comments

Comments
 (0)