MCPcopy Create free account
hub / github.com/cel-expr/cel-go / TestFileExpressionCustomPolicyParser

Function TestFileExpressionCustomPolicyParser

tools/compiler/compiler_test.go:372–395  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

370}
371
372func TestFileExpressionCustomPolicyParser(t *testing.T) {
373 t.Run("test file expression custom policy parser", func(t *testing.T) {
374 envOpt := EnvironmentFile("../../policy/testdata/k8s/config.yaml")
375 parserOpt := policy.ParserOption(func(p *policy.Parser) (*policy.Parser, error) {
376 p.TagVisitor = policy.K8sTestTagHandler()
377 return p, nil
378 })
379 compilerOpts := []any{envOpt, parserOpt}
380 compiler, err := NewCompiler(compilerOpts...)
381 if err != nil {
382 t.Fatalf("NewCompiler() failed: %v", err)
383 }
384 policyFile := &FileExpression{
385 Path: "../../policy/testdata/k8s/policy.yaml",
386 }
387 k8sAst, _, err := policyFile.CreateAST(compiler)
388 if err != nil {
389 t.Fatalf("CreateAST() failed: %v", err)
390 }
391 if k8sAst == nil {
392 t.Fatalf("CreateAST() returned nil ast")
393 }
394 })
395}
396
397func TestRawExpressionCreateAst(t *testing.T) {
398 t.Run("test raw expression create ast", func(t *testing.T) {

Callers

nothing calls this directly

Calls 5

CreateASTMethod · 0.95
ParserOptionFuncType · 0.92
K8sTestTagHandlerFunction · 0.92
EnvironmentFileFunction · 0.85
NewCompilerFunction · 0.85

Tested by

no test coverage detected