Skip to content

Commit 08647b2

Browse files
committed
Add remaining test types
1 parent 1fd1e51 commit 08647b2

File tree

3 files changed

+94
-1
lines changed

3 files changed

+94
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
1313
import org.elasticsearch.common.io.stream.StreamInput;
1414
import org.elasticsearch.common.io.stream.StreamOutput;
15-
import org.elasticsearch.common.network.InetAddresses;
1615
import org.elasticsearch.common.network.NetworkDirectionUtils;
1716
import org.elasticsearch.compute.ann.Evaluator;
1817
import org.elasticsearch.compute.ann.Fixed;
@@ -160,4 +159,16 @@ static BytesRef process(@Fixed(includeInToString=false, scope=THREAD_LOCAL) Byte
160159
public DataType dataType() {
161160
return DataType.KEYWORD;
162161
}
162+
163+
public Expression sourceIpField() {
164+
return sourceIpField;
165+
}
166+
167+
public Expression destinationIpField() {
168+
return destinationIpField;
169+
}
170+
171+
public Expression internalNetworks() {
172+
return internalNetworks;
173+
}
163174
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.esql.expression.function.scalar.ip;
9+
10+
import org.elasticsearch.xpack.esql.core.expression.Expression;
11+
import org.elasticsearch.xpack.esql.core.tree.Source;
12+
import org.elasticsearch.xpack.esql.core.type.DataType;
13+
import org.elasticsearch.xpack.esql.expression.function.ErrorsForCasesWithoutExamplesTestCase;
14+
import org.elasticsearch.xpack.esql.expression.function.TestCaseSupplier;
15+
import org.hamcrest.Matcher;
16+
17+
import java.util.List;
18+
import java.util.Set;
19+
20+
import static org.hamcrest.Matchers.equalTo;
21+
22+
public class NetworkDirectionErrorTests extends ErrorsForCasesWithoutExamplesTestCase {
23+
@Override
24+
protected List<TestCaseSupplier> cases() {
25+
return paramsToSuppliers(NetworkDirectionTests.parameters());
26+
}
27+
28+
@Override
29+
protected Expression build(Source source, List<Expression> args) {
30+
return new NetworkDirection(source, args.get(0), args.get(1), args.get(2));
31+
}
32+
33+
@Override
34+
protected Matcher<String> expectedTypeErrorMatcher(List<Set<DataType>> validPerPosition, List<DataType> signature) {
35+
return equalTo(typeErrorMessage(true, validPerPosition, signature, (v, p) -> switch (p) {
36+
case 0, 1 -> "ip";
37+
case 2 -> "keyword";
38+
default -> "";
39+
}));
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.esql.expression.function.scalar.ip;
9+
10+
import org.elasticsearch.xpack.esql.core.expression.Expression;
11+
import org.elasticsearch.xpack.esql.core.tree.Source;
12+
import org.elasticsearch.xpack.esql.expression.AbstractExpressionSerializationTests;
13+
14+
import java.io.IOException;
15+
16+
public class NetworkDirectionSerializationTests extends AbstractExpressionSerializationTests<NetworkDirection> {
17+
18+
@Override
19+
protected NetworkDirection createTestInstance() {
20+
Source source = randomSource();
21+
Expression sourceIpField = randomChild();
22+
Expression destinationIpField = randomChild();
23+
Expression internalNetworks = randomChild();
24+
return new NetworkDirection(source, sourceIpField, destinationIpField, internalNetworks);
25+
}
26+
27+
@Override
28+
protected NetworkDirection mutateInstance(NetworkDirection instance) throws IOException {
29+
Source source = instance.source();
30+
Expression sourceIpField = instance.sourceIpField();
31+
Expression destinationIpField = instance.destinationIpField();
32+
Expression internalNetworks = instance.internalNetworks();
33+
switch (between(0, 2)) {
34+
case 0 -> sourceIpField = randomValueOtherThan(sourceIpField, AbstractExpressionSerializationTests::randomChild);
35+
case 1 -> destinationIpField = randomValueOtherThan(destinationIpField, AbstractExpressionSerializationTests::randomChild);
36+
case 2 -> internalNetworks = randomValueOtherThan(internalNetworks, AbstractExpressionSerializationTests::randomChild);
37+
}
38+
39+
return new NetworkDirection(source, sourceIpField, destinationIpField, internalNetworks);
40+
}
41+
}

0 commit comments

Comments
 (0)