Skip to content

Oss failure late function binding experimentations. #743

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ java_library(
srcs = ["TestRunnerLibrary.java"],
tags = [
],
runtime_deps = ["@maven//:com_google_protobuf_protobuf_java"],
deps = [
":cel_test_context",
":cel_test_suite",
Expand Down
33 changes: 17 additions & 16 deletions testing/src/main/java/dev/cel/testing/testrunner/TestExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,32 @@

package dev.cel.testing.testrunner;

import static com.google.common.collect.MoreCollectors.onlyElement;
import static dev.cel.testing.utils.ClassLoaderUtils.loadClassesWithMethodAnnotation;
import static dev.cel.testing.utils.ClassLoaderUtils.loadSubclasses;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.time.ZoneId.systemDefault;

import com.google.common.collect.ImmutableList;
import com.google.common.io.Files;
import dev.cel.testing.testrunner.Annotations.TestSuiteSupplier;
import dev.cel.testing.testrunner.CelTestSuite.CelTestSection;
import dev.cel.testing.testrunner.CelTestSuite.CelTestSection.CelTestCase;
import io.github.classgraph.ClassInfoList;
import org.junit.runner.*;
import org.junit.runner.manipulation.Filter;
import org.junit.runners.model.TestClass;
import org.junit.runners.parameterized.BlockJUnit4ClassRunnerWithParametersFactory;
import org.junit.runners.parameterized.ParametersRunnerFactory;
import org.junit.runners.parameterized.TestWithParameters;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneOffset;
import java.util.Arrays;
import org.junit.runner.Description;
import org.junit.runner.JUnitCore;
import org.junit.runner.Request;
import org.junit.runner.Result;
import org.junit.runner.Runner;
import org.junit.runner.manipulation.Filter;
import org.junit.runners.model.TestClass;
import org.junit.runners.parameterized.BlockJUnit4ClassRunnerWithParametersFactory;
import org.junit.runners.parameterized.ParametersRunnerFactory;
import org.junit.runners.parameterized.TestWithParameters;

import static com.google.common.collect.MoreCollectors.onlyElement;
import static dev.cel.testing.utils.ClassLoaderUtils.loadClassesWithMethodAnnotation;
import static dev.cel.testing.utils.ClassLoaderUtils.loadSubclasses;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.time.ZoneId.systemDefault;

/** Test executor for running tests using custom runner. */
public final class TestExecutor {
Expand Down Expand Up @@ -229,6 +226,10 @@ public String describe() {
allTestsPassed = false;
testResult.setStatus(JUnitXmlReporter.TestResult.FAILURE);
testResult.setThrowable(result.getFailures().get(0).getException());
System.out.println("Size: " + result.getFailures().size());
System.out.println("ExecutorError: " + result.getFailures().get(0).getException());
System.out.println("ExecutorErrorStackTrace: " + result.getFailures().get(0).getTrace());
System.out.println("ExecutorErrorCause: " + result.getFailures().get(0).getException().getCause());
testReporter.onTestFailure(testResult);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,27 @@ public static void runTest(CelTestCase testCase, CelTestContext celTestContext)
static void evaluateTestCase(
CelTestCase testCase, CelTestContext celTestContext, CelExprFileSource celExprFileSource)
throws Exception {
System.out.println(
"evaluateTestCase: "
+ testCase.name()
+ " "
+ testCase.input().kind()
+ " "
+ testCase.input().bindings() + celExprFileSource.value());
celTestContext = extendCelTestContext(celTestContext, celExprFileSource);
System.out.println("Reached beyond extend cel");
CelAbstractSyntaxTree ast;
switch (celExprFileSource.type()) {
case POLICY:
System.out.println(celExprFileSource.value());
String content = readFile(celExprFileSource.value());
System.out.println(content);
ast =
compilePolicy(
celTestContext.cel(),
celTestContext.celPolicyParser().get(),
readFile(celExprFileSource.value()));
content);

break;
case TEXTPROTO:
case BINARYPB:
Expand All @@ -109,6 +121,7 @@ static void evaluateTestCase(
throw new IllegalArgumentException(
"Unsupported expression type: " + celExprFileSource.type());
}

evaluate(ast, testCase, celTestContext);
}

Expand All @@ -133,15 +146,28 @@ private static CelAbstractSyntaxTree readAstFromCheckedExpression(

private static CelTestContext extendCelTestContext(
CelTestContext celTestContext, CelExprFileSource celExprFileSource) throws Exception {
System.out.println("Reached insdie extencontext");
CelOptions celOptions = celTestContext.celOptions();
Cel celTest = celTestContext.cel();
try {
celTest = extendCel(celTestContext.cel(), celOptions);

} catch (Exception e) {
System.out.println("Printing error " + e);
}
System.out.println("Reached after extend cel");
CelTestContext.Builder celTestContextBuilder =
celTestContext.toBuilder().setCel(extendCel(celTestContext.cel(), celOptions));
celTestContext.toBuilder().setCel(celTest);

System.out.println("Extended cel.");
if (celExprFileSource.type().equals(ExpressionFileType.POLICY)) {
System.out.println("Inside policy check inside extend.");
celTestContextBuilder.setCelPolicyParser(
celTestContext
.celPolicyParser()
.orElse(CelPolicyParserFactory.newYamlParserBuilder().build()));
celTestContext
.celPolicyParser()
.orElse(CelPolicyParserFactory.newYamlParserBuilder().build()));
}
System.out.println("Reached end of extendCelTestContxt.");

return celTestContextBuilder.build();
}
Expand All @@ -155,6 +181,7 @@ private static Cel extendCel(Cel cel, CelOptions celOptions) throws Exception {
// regarding proto messages that need to be added to the cel object.
String fileDescriptorSetPath = System.getProperty("file_descriptor_set_path");
if (fileDescriptorSetPath != null) {
System.out.println("Fds");
extendedCel =
cel.toCelBuilder()
.addMessageTypes(
Expand All @@ -167,17 +194,33 @@ private static Cel extendCel(Cel cel, CelOptions celOptions) throws Exception {

// Extend the cel object with the config file if provided.
String configPath = System.getProperty("config_path");
System.out.println(configPath);
if (configPath != null) {
String configContent = readFile(configPath);
System.out.println(configContent);
environment = CelEnvironmentYamlParser.newInstance().parse(configContent);
}

System.out.println("Reached end of extend CEl" + " " + environment.toString());

// Policy compiler requires optional support. Add the optional library by default to the
// environment.
return environment.toBuilder()
.addExtensions(ExtensionConfig.of("optional"))
.build()
.extend(extendedCel, celOptions);
try {
System.out.println("line 208");
Cel newEnv = environment.toBuilder()
.addExtensions(ExtensionConfig.of("optional"))
.build()
.extend(extendedCel, celOptions);
System.out.println("Printing cel env " + newEnv);
return newEnv;
} catch (Exception e) {
System.out.println("line 216");
System.out.println("e " + e);
}
System.out.println("line 219");
return cel;
// System.out.println("Printing cel env " + newEnv);
// return newEnv;
}

/**
Expand Down Expand Up @@ -227,6 +270,7 @@ static ExpressionFileType fromFile(String filePath) {
}

private static String readFile(String path) throws IOException {
System.out.println("Reached here eval");
return asCharSource(new File(path), UTF_8).read();
}

Expand All @@ -240,6 +284,7 @@ private static CelAbstractSyntaxTree compilePolicy(
private static void evaluate(
CelAbstractSyntaxTree ast, CelTestCase testCase, CelTestContext celTestContext)
throws Exception {

Cel cel = celTestContext.cel();
Program program = cel.createProgram(ast);
ExprValue exprValue = null;
Expand Down
Loading