Skip to content

Commit 15918ab

Browse files
l46kokcopybara-github
authored andcommitted
Add protolite tests for Android
PiperOrigin-RevId: 749966327
1 parent edc6e94 commit 15918ab

File tree

43 files changed

+1417
-210
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1417
-210
lines changed

.github/workflows/unwanted_deps.sh

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,23 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
# Script ran as part of Github CEL-Java CI to verify that the runtime jar does not contain generated cel protos from @cel_spec.
16+
# Script ran as part of Github CEL-Java CI to verify that the runtime jar does not contain unwanted dependencies.
1717

18-
runtime_deps="$(bazel query 'deps(//publish:cel_runtime)' --nohost_deps --noimplicit_deps --output graph | grep '@cel_spec')"
18+
UNWANTED_DEPS=(
19+
'@cel_spec' # Do not include generated CEL protos in the jar
20+
'protobuf_java_util' # Does not support protolite
21+
)
1922

20-
if [[ ! -z $runtime_deps ]]; then
21-
echo -e "Runtime contains unwanted @cel_spec dependency!\n"
22-
echo "cel_spec dependency graph:"
23-
echo -e "$runtime_deps"
24-
exit 1
25-
fi
23+
runtime_deps="$(bazel query 'deps(//publish:cel_runtime)' --nohost_deps --noimplicit_deps --output graph)"
24+
25+
for unwanted_dep in "${UNWANTED_DEPS[@]}"; do
26+
if echo "$runtime_deps" | grep "$unwanted_dep" > /dev/null; then
27+
echo -e "Runtime contains unwanted dependency: $unwanted_dep!\n"
28+
echo "cel_spec dependency graph (including '$unwanted_dep'):"
29+
echo "$(echo "$runtime_deps" | grep "$unwanted_dep")"
30+
exit 1
31+
fi
32+
done
2633

2734
exit 0
2835

bundle/src/test/java/dev/cel/bundle/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ java_library(
3030
"//common:proto_ast",
3131
"//common:source_location",
3232
"//common/ast",
33+
"//common/internal:proto_time_utils",
3334
"//common/resources/testdata/proto3:standalone_global_enum_java_proto",
3435
"//common/testing",
3536
"//common/types",
@@ -55,7 +56,6 @@ java_library(
5556
"@com_google_googleapis//google/type:type_java_proto",
5657
"@maven//:com_google_guava_guava",
5758
"@maven//:com_google_protobuf_protobuf_java",
58-
"@maven//:com_google_protobuf_protobuf_java_util",
5959
"@maven//:com_google_testparameterinjector_test_parameter_injector",
6060
"@maven//:com_google_truth_extensions_truth_proto_extension",
6161
"@maven//:junit_junit",

bundle/src/test/java/dev/cel/bundle/CelImplTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
import com.google.protobuf.Struct;
5252
import com.google.protobuf.TextFormat;
5353
import com.google.protobuf.Timestamp;
54-
import com.google.protobuf.util.Timestamps;
5554
import com.google.rpc.context.AttributeContext;
5655
import com.google.testing.junit.testparameterinjector.TestParameter;
5756
import com.google.testing.junit.testparameterinjector.TestParameterInjector;
@@ -71,6 +70,7 @@
7170
import dev.cel.common.CelVarDecl;
7271
import dev.cel.common.ast.CelExpr;
7372
import dev.cel.common.ast.CelExpr.CelList;
73+
import dev.cel.common.internal.ProtoTimeUtils;
7474
import dev.cel.common.testing.RepeatedTestProvider;
7575
import dev.cel.common.types.CelKind;
7676
import dev.cel.common.types.CelProtoMessageTypes;
@@ -409,6 +409,7 @@ public void program_setTypeFactoryOnAnyPackedMessage_messageConstructionSucceeds
409409
}
410410

411411
@Test
412+
@SuppressWarnings("unused") // testRunIndex name retained for test result readability
412413
public void program_concurrentMessageConstruction_succeeds(
413414
@TestParameter(valuesProvider = RepeatedTestProvider.class) int testRunIndex)
414415
throws Exception {
@@ -814,7 +815,7 @@ public void program_duplicateTypeDescriptor() throws Exception {
814815
.build();
815816
CelRuntime.Program program =
816817
cel.createProgram(cel.compile("protobuf.Timestamp{seconds: 12}").getAst());
817-
assertThat(program.eval()).isEqualTo(Timestamps.fromSeconds(12));
818+
assertThat(program.eval()).isEqualTo(ProtoTimeUtils.fromSecondsToTimestamp(12));
818819
}
819820

820821
@Test
@@ -827,7 +828,7 @@ public void program_hermeticDescriptors_wellKnownProtobuf() throws Exception {
827828
.build();
828829
CelRuntime.Program program =
829830
cel.createProgram(cel.compile("protobuf.Timestamp{seconds: 12}").getAst());
830-
assertThat(program.eval()).isEqualTo(Timestamps.fromSeconds(12));
831+
assertThat(program.eval()).isEqualTo(ProtoTimeUtils.fromSecondsToTimestamp(12));
831832
}
832833

833834
@Test
@@ -956,7 +957,7 @@ public void program_typeProvider() throws Exception {
956957
.build();
957958
CelRuntime.Program program =
958959
cel.createProgram(cel.compile("protobuf.Timestamp{seconds: 12}").getAst());
959-
assertThat(program.eval()).isEqualTo(Timestamps.fromSeconds(12));
960+
assertThat(program.eval()).isEqualTo(ProtoTimeUtils.fromSecondsToTimestamp(12));
960961
}
961962

962963
@Test

codelab/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ public void evaluate_jwtWithTimeVariable_producesJsonString() throws Exception {
667667
@SuppressWarnings("unchecked")
668668
Map<String, Object> evaluatedResult =
669669
(Map<String, Object>)
670-
exercise5.eval(ast, ImmutableMap.of("time", Timestamps.fromSeconds(1698361778)));
670+
exercise5.eval(ast, ImmutableMap.of("time", ProtoTimeUtils.fromSecondsToTimestamp(1698361778)));
671671
String jsonOutput = exercise5.toJson(evaluatedResult);
672672

673673
assertThat(jsonOutput)
@@ -776,7 +776,7 @@ public void evaluate_constructAttributeContext() {
776776
+ "time: now"
777777
+ "}";
778778
// Values for `now` and `jwt` variables to be passed into the runtime
779-
Timestamp now = Timestamps.now();
779+
Timestamp now = ProtoTimeUtils.now();
780780
ImmutableMap<String, Object> jwt =
781781
ImmutableMap.of(
782782
"sub", "serviceAccount:delegate@acme.co",

codelab/src/test/codelab/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ java_test(
7878
"//codelab",
7979
"//common:cel_ast",
8080
"@maven//:com_google_guava_guava",
81-
"@maven//:com_google_protobuf_protobuf_java_util",
81+
"@maven//:com_google_protobuf_protobuf_java",
8282
"@maven//:com_google_testparameterinjector_test_parameter_injector",
8383
"@maven//:junit_junit",
8484
],
@@ -93,10 +93,10 @@ java_test(
9393
"//:java_truth",
9494
"//codelab",
9595
"//common:cel_ast",
96+
"//common/internal:proto_time_utils",
9697
"@com_google_googleapis//google/rpc/context:attribute_context_java_proto",
9798
"@maven//:com_google_guava_guava",
9899
"@maven//:com_google_protobuf_protobuf_java",
99-
"@maven//:com_google_protobuf_protobuf_java_util",
100100
"@maven//:com_google_testparameterinjector_test_parameter_injector",
101101
"@maven//:junit_junit",
102102
],

codelab/src/test/codelab/Exercise5Test.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import static com.google.common.truth.Truth.assertThat;
1818

1919
import com.google.common.collect.ImmutableMap;
20-
import com.google.protobuf.util.Timestamps;
20+
import com.google.protobuf.Timestamp;
2121
import com.google.testing.junit.testparameterinjector.TestParameterInjector;
2222
import dev.cel.common.CelAbstractSyntaxTree;
2323
import java.util.Map;
@@ -48,7 +48,9 @@ public void evaluate_jwtWithTimeVariable_producesJsonString() throws Exception {
4848
@SuppressWarnings("unchecked")
4949
Map<String, Object> evaluatedResult =
5050
(Map<String, Object>)
51-
exercise5.eval(ast, ImmutableMap.of("time", Timestamps.fromSeconds(1698361778)));
51+
exercise5.eval(
52+
ast,
53+
ImmutableMap.of("time", Timestamp.newBuilder().setSeconds(1698361778).build()));
5254
String jsonOutput = exercise5.toJson(evaluatedResult);
5355

5456
assertThat(jsonOutput)

codelab/src/test/codelab/Exercise6Test.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
import com.google.protobuf.Struct;
2121
import com.google.protobuf.Timestamp;
2222
import com.google.protobuf.Value;
23-
import com.google.protobuf.util.Timestamps;
2423
import com.google.rpc.context.AttributeContext;
2524
import com.google.testing.junit.testparameterinjector.TestParameterInjector;
2625
import dev.cel.common.CelAbstractSyntaxTree;
26+
import dev.cel.common.internal.ProtoTimeUtils;
2727
import org.junit.Test;
2828
import org.junit.runner.RunWith;
2929

@@ -51,7 +51,7 @@ public void evaluate_constructAttributeContext() {
5151
+ "time: now"
5252
+ "}";
5353
// Values for `now` and `jwt` variables to be passed into the runtime
54-
Timestamp now = Timestamps.now();
54+
Timestamp now = ProtoTimeUtils.now();
5555
ImmutableMap<String, Object> jwt =
5656
ImmutableMap.of(
5757
"sub", "serviceAccount:delegate@acme.co",

codelab/src/test/codelab/solutions/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ java_test(
7373
"//codelab:solutions",
7474
"//common:cel_ast",
7575
"@maven//:com_google_guava_guava",
76-
"@maven//:com_google_protobuf_protobuf_java_util",
76+
"@maven//:com_google_protobuf_protobuf_java",
7777
"@maven//:com_google_testparameterinjector_test_parameter_injector",
7878
"@maven//:junit_junit",
7979
],
@@ -87,10 +87,10 @@ java_test(
8787
"//:java_truth",
8888
"//codelab:solutions",
8989
"//common:cel_ast",
90+
"//common/internal:proto_time_utils",
9091
"@com_google_googleapis//google/rpc/context:attribute_context_java_proto",
9192
"@maven//:com_google_guava_guava",
9293
"@maven//:com_google_protobuf_protobuf_java",
93-
"@maven//:com_google_protobuf_protobuf_java_util",
9494
"@maven//:com_google_testparameterinjector_test_parameter_injector",
9595
"@maven//:junit_junit",
9696
],

codelab/src/test/codelab/solutions/Exercise5Test.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import static com.google.common.truth.Truth.assertThat;
1818

1919
import com.google.common.collect.ImmutableMap;
20-
import com.google.protobuf.util.Timestamps;
20+
import com.google.protobuf.Timestamp;
2121
import com.google.testing.junit.testparameterinjector.TestParameterInjector;
2222
import dev.cel.common.CelAbstractSyntaxTree;
2323
import java.util.Map;
@@ -48,7 +48,9 @@ public void evaluate_jwtWithTimeVariable_producesJsonString() throws Exception {
4848
@SuppressWarnings("unchecked")
4949
Map<String, Object> evaluatedResult =
5050
(Map<String, Object>)
51-
exercise5.eval(ast, ImmutableMap.of("time", Timestamps.fromSeconds(1698361778)));
51+
exercise5.eval(
52+
ast,
53+
ImmutableMap.of("time", Timestamp.newBuilder().setSeconds(1698361778).build()));
5254
String jsonOutput = exercise5.toJson(evaluatedResult);
5355

5456
assertThat(jsonOutput)

codelab/src/test/codelab/solutions/Exercise6Test.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
import com.google.protobuf.Struct;
2121
import com.google.protobuf.Timestamp;
2222
import com.google.protobuf.Value;
23-
import com.google.protobuf.util.Timestamps;
2423
import com.google.rpc.context.AttributeContext;
2524
import com.google.testing.junit.testparameterinjector.TestParameterInjector;
2625
import dev.cel.common.CelAbstractSyntaxTree;
26+
import dev.cel.common.internal.ProtoTimeUtils;
2727
import org.junit.Test;
2828
import org.junit.runner.RunWith;
2929

@@ -51,7 +51,7 @@ public void evaluate_constructAttributeContext() {
5151
+ "time: now"
5252
+ "}";
5353
// Values for `now` and `jwt` variables to be passed into the runtime
54-
Timestamp now = Timestamps.now();
54+
Timestamp now = ProtoTimeUtils.now();
5555
ImmutableMap<String, Object> jwt =
5656
ImmutableMap.of(
5757
"sub", "serviceAccount:delegate@acme.co",

0 commit comments

Comments
 (0)