| 1 | // Copyright 2025 Google LLC |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | // Package test provides a YAML-serializable test suite for CEL tests. |
| 16 | package testscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test`/ |
| 17 | |
| 18 | // Suite is a collection of tests designed to evaluate the correctness of |
| 19 | // a CEL policy or a CEL expression |
| 20 | type Suitescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test`/Suite# struct { |
| 21 | Namescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test`/Suite#Name. string `yaml:"name"` |
| 22 | Descriptionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test`/Suite#Description. string `yaml:"description"` |
| 23 | Sectionsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test`/Suite#Sections. []*Sectionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test`/Section# `yaml:"section"` |
| 24 | } |
| 25 | |
| 26 | // Section is a collection of related test cases. |
| 27 | type Sectionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test`/Section# struct { |
| 28 | Namescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test`/Section#Name. string `yaml:"name"` |
| 29 | Testsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test`/Section#Tests. []*Casescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test`/Case# `yaml:"tests"` |
| 30 | } |
| 31 | |
| 32 | // Case is a test case to validate a CEL policy or expression. The test case |
| 33 | // encompasses evaluation of the compiled expression using the provided input |
| 34 | // bindings and asserting the result against the expected result. |
| 35 | type Casescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test`/Case# struct { |
| 36 | Namescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test`/Case#Name. string `yaml:"name"` |
| 37 | Descriptionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test`/Case#Description. string `yaml:"description"` |
| 38 | Inputscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test`/Case#Input. map[string]*InputValuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test`/InputValue# `yaml:"input,omitempty"` |
| 39 | *InputContextscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test`/Case#InputContext. `yaml:",inline,omitempty"` |
| 40 | Outputscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test`/Case#Output. *Outputscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test`/Output# `yaml:"output"` |
| 41 | } |
| 42 | |
| 43 | // InputContext represents an optional context expression. |
| 44 | type InputContextscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test`/InputContext# struct { |
| 45 | ContextExprscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test`/InputContext#ContextExpr. string `yaml:"context_expr"` |
| 46 | } |
| 47 | |
| 48 | // InputValue represents an input value for a binding which can be either a simple literal value or |
| 49 | // an expression. |
| 50 | type InputValuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test`/InputValue# struct { |
| 51 | Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test`/InputValue#Value. any `yaml:"value"` |
| 52 | Exprscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test`/InputValue#Expr. string `yaml:"expr"` |
| 53 | } |
| 54 | |
| 55 | // Output represents the expected result of a test case. |
| 56 | type Outputscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test`/Output# struct { |
| 57 | Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test`/Output#Value. any `yaml:"value"` |
| 58 | Exprscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test`/Output#Expr. string `yaml:"expr"` |
| 59 | ErrorSetscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test`/Output#ErrorSet. []string `yaml:"error_set"` |
| 60 | UnknownSetscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/test`/Output#UnknownSet. []int64 `yaml:"unknown_set"` |
| 61 | } |