Skip to content

Commit fcbf501

Browse files
l46kokcopybara-github
authored andcommitted
Remove duplicate test policies and use the ones from cel-policy as SoT
PiperOrigin-RevId: 918667081
1 parent 919ae0b commit fcbf501

47 files changed

Lines changed: 94 additions & 1600 deletions

Some content is hidden

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

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ java_library(
99
srcs = glob(["*.java"]),
1010
resources = [
1111
"//testing:policy_test_resources",
12+
"@cel_policy//conformance:testdata",
1213
],
1314
deps = [
1415
"//:java_truth",

policy/src/test/java/dev/cel/policy/PolicyTestHelper.java

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ enum TestYamlPolicy {
7474
"required_labels",
7575
true,
7676
"cel.@block([spec.labels.filter(@it:0:0, !(@it:0:0 in resource.labels)), spec.labels,"
77-
+ " resource.labels, @index2.filter(@it:0:0, @it:0:0 in @index1 && @index1[@it:0:0] !="
78-
+ " @index2[@it:0:0])], (@index0.size() > 0) ? optional.of(\"missing one or more"
79-
+ " required labels: [\"\" + @index0.join(\",\") + \"\"]\") : ((@index3.size() > 0) ?"
80-
+ " optional.of(\"invalid values provided on one or more labels: [\"\" +"
81-
+ " @index3.join(\",\") + \"\"]\") : optional.none()))"),
77+
+ " resource.labels.transformList(@it:0:1, @it2:0:1, @it:0:1 in @index1 && @it2:0:1 !="
78+
+ " @index1[@it:0:1], @it:0:1)], (@index0.size() > 0) ? optional.of(\"missing one or"
79+
+ " more required labels: [\"\" + @index0.join(\"\", \"\") + \"\"]\") :"
80+
+ " ((@index2.size() > 0) ? optional.of(\"invalid values provided on one or more"
81+
+ " labels: [\"\" + @index2.join(\"\", \"\") + \"\"]\") : optional.none()))"),
8282
RESTRICTED_DESTINATIONS(
8383
"restricted_destinations",
8484
false,
@@ -102,9 +102,10 @@ enum TestYamlPolicy {
102102
"cel.@block([spec.single_int32], (@index0 > 10) ? optional.of(\"invalid spec, got"
103103
+ " single_int32=\" + string(@index0) + \", wanted <= 10\") : ((spec.standalone_enum =="
104104
+ " cel.expr.conformance.proto3.TestAllTypes.NestedEnum.BAR ||"
105-
+ " dev.cel.testing.testdata.proto3.StandaloneGlobalEnum.SGAR =="
106-
+ " dev.cel.testing.testdata.proto3.StandaloneGlobalEnum.SGOO) ? optional.of(\"invalid"
107-
+ " spec, neither nested nor imported enums may refer to BAR\") : optional.none()))"),
105+
+ " cel.expr.conformance.proto3.TestAllTypes.NestedEnum.BAZ in"
106+
+ " spec.repeated_nested_enum || cel.expr.conformance.proto3.GlobalEnum.GAR =="
107+
+ " cel.expr.conformance.proto3.GlobalEnum.GOO) ? optional.of(\"invalid spec, neither"
108+
+ " nested nor repeated enums may refer to BAR or BAZ\") : optional.none()))"),
108109
LIMITS(
109110
"limits",
110111
true,
@@ -136,16 +137,20 @@ String getUnparsed() {
136137
}
137138

138139
String readPolicyYamlContent() throws IOException {
139-
return readFromYaml(String.format("policy/%s/policy.yaml", name));
140+
return readFromYaml(
141+
String.format("third_party/cel/policy/conformance/testdata/%s/policy.yaml", name));
140142
}
141143

142144
String readConfigYamlContent() throws IOException {
143-
return readFromYaml(String.format("policy/%s/config.yaml", name));
145+
return readFromYaml(
146+
String.format("third_party/cel/policy/conformance/testdata/%s/config.yaml", name));
144147
}
145148

146149
PolicyTestSuite readTestYamlContent() throws IOException {
147150
Yaml yaml = new Yaml(new Constructor(PolicyTestSuite.class, new LoaderOptions()));
148-
String testContent = readFile(String.format("policy/%s/tests.yaml", name));
151+
String testContent =
152+
readFile(
153+
String.format("third_party/cel/policy/conformance/testdata/%s/tests.yaml", name));
149154

150155
return yaml.load(testContent);
151156
}
@@ -163,9 +168,18 @@ static String readFromYaml(String yamlPath) throws IOException {
163168
*/
164169
@VisibleForTesting
165170
public static final class PolicyTestSuite {
171+
private String name;
166172
private String description;
167173
private List<PolicyTestSection> section;
168174

175+
public void setName(String name) {
176+
this.name = name;
177+
}
178+
179+
public String getName() {
180+
return name;
181+
}
182+
169183
public void setDescription(String description) {
170184
this.description = description;
171185
}

repositories.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ def bazel_common_dependency():
3434
)
3535

3636
def cel_policy_dependency():
37-
cel_policy_tag = "569292f1c4eaa41894c1e37ee94eb146e284bcfa"
38-
cel_policy_sha = "5a68318d906f6ce18492ad6f82b5f8bb083fd9d694cf567d399216c11da03157"
37+
cel_policy_tag = "e4c38defbbf34dfff2dc448dc58e93a9733ae8b1"
38+
cel_policy_sha = "46378e0d17a16465899f9fefc94c3d44e1f40aedd8a31c9c0b2b6198048eabd6"
3939
http_archive(
4040
name = "cel_policy",
4141
sha256 = cel_policy_sha,

testing/src/test/java/dev/cel/testing/testrunner/BUILD.bazel

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,13 @@ java_test(
157157

158158
cel_java_test(
159159
name = "test_runner_sample_yaml",
160-
cel_expr = "nested_rule/policy.yaml",
160+
cel_expr = "@cel_policy//conformance:testdata/nested_rule/policy.yaml",
161161
proto_deps = [
162162
"@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_proto",
163163
"@cel_spec//proto/cel/expr/conformance/proto3:test_all_types_proto",
164164
],
165-
test_data_path = "//testing/src/test/resources/policy",
166165
test_src = ":user_test",
167-
test_suite = "nested_rule/testrunner_tests.yaml",
166+
test_suite = "@cel_policy//conformance:testdata/nested_rule/tests.yaml",
168167
deps = [
169168
"@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_java_proto",
170169
"@cel_spec//proto/cel/expr/conformance/proto3:test_all_types_java_proto",
@@ -173,7 +172,7 @@ cel_java_test(
173172

174173
cel_java_test(
175174
name = "unknown_set_yaml",
176-
cel_expr = "nested_rule/policy.yaml",
175+
cel_expr = "@cel_policy//conformance:testdata/nested_rule/policy.yaml",
177176
proto_deps = [
178177
"@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_proto",
179178
"@cel_spec//proto/cel/expr/conformance/proto3:test_all_types_proto",
@@ -211,15 +210,14 @@ cel_java_test(
211210

212211
cel_java_test(
213212
name = "context_pb_user_test_runner_sample",
214-
cel_expr = "context_pb/policy.yaml",
215-
config = "context_pb/config.yaml",
213+
cel_expr = "@cel_policy//conformance:testdata/context_pb/policy.yaml",
214+
config = "@cel_policy//conformance:testdata/context_pb/config.yaml",
216215
proto_deps = [
217216
"@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_proto",
218217
"@cel_spec//proto/cel/expr/conformance/proto3:test_all_types_proto",
219218
],
220-
test_data_path = "//testing/src/test/resources/policy",
221219
test_src = ":context_pb_user_test",
222-
test_suite = "context_pb/tests.yaml",
220+
test_suite = "@cel_policy//conformance:testdata/context_pb/tests.yaml",
223221
deps = [
224222
"@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_java_proto",
225223
"@cel_spec//proto/cel/expr/conformance/proto3:test_all_types_java_proto",
@@ -228,15 +226,14 @@ cel_java_test(
228226

229227
cel_java_test(
230228
name = "additional_config_test_runner_sample",
231-
cel_expr = "nested_rule/policy.yaml",
232-
config = "nested_rule/config.yaml",
229+
cel_expr = "@cel_policy//conformance:testdata/nested_rule/policy.yaml",
230+
config = "@cel_policy//conformance:testdata/nested_rule/config.yaml",
233231
proto_deps = [
234232
"@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_proto",
235233
"@cel_spec//proto/cel/expr/conformance/proto3:test_all_types_proto",
236234
],
237-
test_data_path = "//testing/src/test/resources/policy",
238235
test_src = ":env_config_user_test",
239-
test_suite = "nested_rule/testrunner_tests.textproto",
236+
test_suite = "@cel_policy//conformance:testdata/nested_rule/tests.textproto",
240237
deps = [
241238
"@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_java_proto",
242239
"@cel_spec//proto/cel/expr/conformance/proto3:test_all_types_java_proto",
@@ -245,14 +242,13 @@ cel_java_test(
245242

246243
cel_java_test(
247244
name = "test_runner_sample",
248-
cel_expr = "nested_rule/policy.yaml",
245+
cel_expr = "@cel_policy//conformance:testdata/nested_rule/policy.yaml",
249246
proto_deps = [
250247
"@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_proto",
251248
"@cel_spec//proto/cel/expr/conformance/proto3:test_all_types_proto",
252249
],
253-
test_data_path = "//testing/src/test/resources/policy",
254250
test_src = ":user_test",
255-
test_suite = "nested_rule/testrunner_tests.textproto",
251+
test_suite = "@cel_policy//conformance:testdata/nested_rule/tests.textproto",
256252
deps = [
257253
"@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_java_proto",
258254
"@cel_spec//proto/cel/expr/conformance/proto3:test_all_types_java_proto",
@@ -286,8 +282,8 @@ cel_java_test(
286282

287283
cel_java_test(
288284
name = "context_message_user_test_runner_textproto_sample",
289-
cel_expr = "context_pb/policy.yaml",
290-
config = "context_pb/config.yaml",
285+
cel_expr = "@cel_policy//conformance:testdata/context_pb/policy.yaml",
286+
config = "@cel_policy//conformance:testdata/context_pb/config.yaml",
291287
proto_deps = [
292288
"@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_proto",
293289
"@cel_spec//proto/cel/expr/conformance/proto3:test_all_types_proto",
@@ -303,15 +299,14 @@ cel_java_test(
303299

304300
cel_java_test(
305301
name = "context_pb_user_test_runner_textproto_sample",
306-
cel_expr = "context_pb/policy.yaml",
307-
config = "context_pb/config.yaml",
302+
cel_expr = "@cel_policy//conformance:testdata/context_pb/policy.yaml",
303+
config = "@cel_policy//conformance:testdata/context_pb/config.yaml",
308304
proto_deps = [
309305
"@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_proto",
310306
"@cel_spec//proto/cel/expr/conformance/proto3:test_all_types_proto",
311307
],
312-
test_data_path = "//testing/src/test/resources/policy",
313308
test_src = ":context_pb_user_test",
314-
test_suite = "context_pb/tests.textproto",
309+
test_suite = "@cel_policy//conformance:testdata/context_pb/tests.textproto",
315310
deps = [
316311
"@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_java_proto",
317312
"@cel_spec//proto/cel/expr/conformance/proto3:test_all_types_java_proto",

testing/src/test/resources/policy/context_pb/config.yaml

Lines changed: 0 additions & 19 deletions
This file was deleted.

testing/src/test/resources/policy/context_pb/policy.yaml

Lines changed: 0 additions & 25 deletions
This file was deleted.

testing/src/test/resources/policy/context_pb/tests.textproto

Lines changed: 0 additions & 19 deletions
This file was deleted.

testing/src/test/resources/policy/context_pb/tests.yaml

Lines changed: 0 additions & 35 deletions
This file was deleted.

testing/src/test/resources/policy/k8s/config.yaml

Lines changed: 0 additions & 33 deletions
This file was deleted.

testing/src/test/resources/policy/k8s/policy.yaml

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)