Skip to content

Commit 1442116

Browse files
l46kokcopybara-github
authored andcommitted
Internal Changes
PiperOrigin-RevId: 890081732
1 parent 28d2b3c commit 1442116

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

policy/src/main/java/dev/cel/policy/CelPolicy.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.Arrays;
2828
import java.util.Collection;
2929
import java.util.Collections;
30+
import java.util.HashMap;
3031
import java.util.List;
3132
import java.util.Map;
3233
import java.util.Optional;
@@ -77,8 +78,7 @@ public abstract static class Builder {
7778

7879
public abstract Builder setPolicySource(CelPolicySource policySource);
7980

80-
// This should stay package-private to encourage add/set methods to be used instead.
81-
abstract ImmutableMap.Builder<String, Object> metadataBuilder();
81+
private final HashMap<String, Object> metadata = new HashMap<>();
8282

8383
public abstract Builder setMetadata(ImmutableMap<String, Object> value);
8484

@@ -90,6 +90,10 @@ public List<Import> imports() {
9090
return Collections.unmodifiableList(importList);
9191
}
9292

93+
public Map<String, Object> metadata() {
94+
return Collections.unmodifiableMap(metadata);
95+
}
96+
9397
@CanIgnoreReturnValue
9498
public Builder addImport(Import value) {
9599
importList.add(value);
@@ -104,20 +108,21 @@ public Builder addImports(Collection<Import> values) {
104108

105109
@CanIgnoreReturnValue
106110
public Builder putMetadata(String key, Object value) {
107-
metadataBuilder().put(key, value);
111+
metadata.put(key, value);
108112
return this;
109113
}
110114

111115
@CanIgnoreReturnValue
112116
public Builder putMetadata(Map<String, Object> map) {
113-
metadataBuilder().putAll(map);
117+
metadata.putAll(map);
114118
return this;
115119
}
116120

117121
abstract CelPolicy autoBuild();
118122

119123
public CelPolicy build() {
120124
setImports(ImmutableList.copyOf(importList));
125+
setMetadata(ImmutableMap.copyOf(metadata));
121126
return autoBuild();
122127
}
123128
}

testing/src/main/java/dev/cel/testing/testrunner/CelTestSuite.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public abstract static class Builder {
9393
public abstract Builder toBuilder();
9494

9595
public static Builder newBuilder() {
96-
return new AutoValue_CelTestSuite_CelTestSection.Builder();
96+
return new AutoValue_CelTestSuite_CelTestSection.Builder().setDescription("");
9797
}
9898

9999
/** Class representing a CEL test case within a test section. */
@@ -237,7 +237,8 @@ public abstract static class Builder {
237237

238238
public static Builder newBuilder() {
239239
return new AutoValue_CelTestSuite_CelTestSection_CelTestCase.Builder()
240-
.setInput(Input.ofNoInput()); // Default input to no input.
240+
.setInput(Input.ofNoInput()) // Default input to no input.
241+
.setDescription("");
241242
}
242243
}
243244
}

testing/src/main/java/dev/cel/testing/testrunner/TestRunnerLibrary.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ public static void runTest(
106106
}
107107
}
108108

109+
/** Runs the test with the provided AST. */
110+
public static void runTest(
111+
CelAbstractSyntaxTree ast, CelTestCase testCase, CelTestContext celTestContext)
112+
throws Exception {
113+
evaluate(ast, testCase, celTestContext, /* celCoverageIndex= */ null);
114+
}
115+
109116
@VisibleForTesting
110117
static void evaluateTestCase(CelTestCase testCase, CelTestContext celTestContext)
111118
throws Exception {

0 commit comments

Comments
 (0)