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

Function TestFeatureValidate

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

Source from the content-addressed store, hash-verified

1551}
1552
1553func TestFeatureValidate(t *testing.T) {
1554 tests := []struct {
1555 name string
1556 f *Feature
1557 want error
1558 }{
1559 {
1560 name: "nil feature",
1561 f: nil,
1562 want: errors.New("invalid feature: nil"),
1563 },
1564 {
1565 name: "empty feature",
1566 f: NewFeature("", true),
1567 want: errors.New("missing name"),
1568 },
1569 }
1570
1571 for _, tst := range tests {
1572 tc := tst
1573 t.Run(tc.name, func(t *testing.T) {
1574 err := tc.f.Validate()
1575 if err == nil && tc.want == nil {
1576 return
1577 }
1578 if err == nil && tc.want != nil {
1579 t.Fatalf("f.Validate() got valid, wanted error %v", tc.want)
1580 }
1581 if err != nil && tc.want == nil {
1582 t.Fatalf("f.Validate() got error %v, wanted nil error", err)
1583 }
1584 if !strings.Contains(err.Error(), tc.want.Error()) {
1585 t.Errorf("f.Validate() got error %v, wanted %v", err, tc.want)
1586 }
1587 })
1588 }
1589}
1590
1591func mustNewFunction(t *testing.T, name string, opts ...decls.FunctionOpt) *decls.FunctionDecl {
1592 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