(t *testing.T)
| 24 | ) |
| 25 | |
| 26 | func TestCoverageStats(t *testing.T) { |
| 27 | testCases := []struct { |
| 28 | name string |
| 29 | configPath string |
| 30 | testSuitePath string |
| 31 | celExpr string |
| 32 | compilerOpts []any |
| 33 | totalASTNodes int64 |
| 34 | coveredBranchNodesComplete []int64 |
| 35 | coveredBranchNodesPartial []int64 |
| 36 | uncoveredNodes []int64 |
| 37 | }{ |
| 38 | { |
| 39 | name: "restricted destinations policy coverage", |
| 40 | configPath: "../../policy/testdata/restricted_destinations/config.yaml", |
| 41 | testSuitePath: "../../policy/testdata/restricted_destinations/tests.yaml", |
| 42 | celExpr: "../../policy/testdata/restricted_destinations/policy.yaml", |
| 43 | compilerOpts: []any{locationCodeEnvOption()}, |
| 44 | totalASTNodes: 44, |
| 45 | coveredBranchNodesComplete: []int64{1, 7, 11, 12, 19, 23, 28, 29, 30, 31, 32, 33, 34, 36, 37, 38, 39, 40, 42}, |
| 46 | coveredBranchNodesPartial: []int64{3, 13, 41}, |
| 47 | uncoveredNodes: []int64{}, |
| 48 | }, |
| 49 | { |
| 50 | name: "k8s policy coverage", |
| 51 | configPath: "../../policy/testdata/k8s/config.yaml", |
| 52 | testSuitePath: "../../policy/testdata/k8s/tests.yaml", |
| 53 | celExpr: "../../policy/testdata/k8s/policy.yaml", |
| 54 | compilerOpts: []any{k8sParserOpts()}, |
| 55 | totalASTNodes: 38, |
| 56 | coveredBranchNodesComplete: []int64{}, |
| 57 | coveredBranchNodesPartial: []int64{8, 16, 17, 18, 19, 21, 22, 23, 24, 25, 26, 31}, |
| 58 | uncoveredNodes: []int64{5, 6, 7, 11, 12, 38}, |
| 59 | }, |
| 60 | { |
| 61 | name: "policy with custom policy metadata coverage", |
| 62 | testSuitePath: "../../tools/celtest/testdata/custom_policy_tests.yaml", |
| 63 | celExpr: "../../tools/celtest/testdata/custom_policy.celpolicy", |
| 64 | compilerOpts: []any{customPolicyParserOption(), compiler.PolicyMetadataEnvOption(ParsePolicyVariables)}, |
| 65 | totalASTNodes: 10, |
| 66 | coveredBranchNodesComplete: []int64{1, 2, 3, 6}, |
| 67 | coveredBranchNodesPartial: []int64{}, |
| 68 | uncoveredNodes: []int64{}, |
| 69 | }, |
| 70 | { |
| 71 | name: "raw expression file with unknowns test coverage", |
| 72 | configPath: "../../tools/celtest/testdata/config.yaml", |
| 73 | testSuitePath: "../../tools/celtest/testdata/raw_expr_tests.yaml", |
| 74 | celExpr: "../../tools/celtest/testdata/raw_expr.cel", |
| 75 | compilerOpts: []any{fnEnvOption()}, |
| 76 | totalASTNodes: 8, |
| 77 | coveredBranchNodesComplete: []int64{1, 6, 8}, |
| 78 | coveredBranchNodesPartial: []int64{}, |
| 79 | uncoveredNodes: []int64{}, |
| 80 | }, |
| 81 | } |
| 82 | for _, tc := range testCases { |
| 83 | t.Run(tc.name, func(t *testing.T) { |
nothing calls this directly
no test coverage detected