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

Function TestValidatorValidate

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

Source from the content-addressed store, hash-verified

1392}
1393
1394func TestValidatorValidate(t *testing.T) {
1395 tests := []struct {
1396 name string
1397 v *Validator
1398 want error
1399 }{
1400 {
1401 name: "nil validator",
1402 v: nil,
1403 want: errors.New("invalid validator: nil"),
1404 },
1405 {
1406 name: "empty validator",
1407 v: NewValidator(""),
1408 want: errors.New("missing name"),
1409 },
1410 }
1411
1412 for _, tst := range tests {
1413 tc := tst
1414 t.Run(tc.name, func(t *testing.T) {
1415 err := tc.v.Validate()
1416 if err == nil && tc.want == nil {
1417 return
1418 }
1419 if err == nil && tc.want != nil {
1420 t.Fatalf("v.Validate() got valid, wanted error %v", tc.want)
1421 }
1422 if err != nil && tc.want == nil {
1423 t.Fatalf("v.Validate() got error %v, wanted nil error", err)
1424 }
1425 if !strings.Contains(err.Error(), tc.want.Error()) {
1426 t.Errorf("v.Validate() got error %v, wanted %v", err, tc.want)
1427 }
1428 })
1429 }
1430}
1431
1432func TestValidatorConfigValue(t *testing.T) {
1433 var v *Validator

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected