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

Function TestFeatureValidate

common/env/env_test.go:1446–1482  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1444}
1445
1446func TestFeatureValidate(t *testing.T) {
1447 tests := []struct {
1448 name string
1449 f *Feature
1450 want error
1451 }{
1452 {
1453 name: "nil feature",
1454 f: nil,
1455 want: errors.New("invalid feature: nil"),
1456 },
1457 {
1458 name: "empty feature",
1459 f: NewFeature("", true),
1460 want: errors.New("missing name"),
1461 },
1462 }
1463
1464 for _, tst := range tests {
1465 tc := tst
1466 t.Run(tc.name, func(t *testing.T) {
1467 err := tc.f.Validate()
1468 if err == nil && tc.want == nil {
1469 return
1470 }
1471 if err == nil && tc.want != nil {
1472 t.Fatalf("f.Validate() got valid, wanted error %v", tc.want)
1473 }
1474 if err != nil && tc.want == nil {
1475 t.Fatalf("f.Validate() got error %v, wanted nil error", err)
1476 }
1477 if !strings.Contains(err.Error(), tc.want.Error()) {
1478 t.Errorf("f.Validate() got error %v, wanted %v", err, tc.want)
1479 }
1480 })
1481 }
1482}
1483
1484func mustNewFunction(t *testing.T, name string, opts ...decls.FunctionOpt) *decls.FunctionDecl {
1485 t.Helper()

Callers

nothing calls this directly

Calls 5

NewFeatureFunction · 0.85
NewMethod · 0.80
ValidateMethod · 0.65
ContainsMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected