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

Function TestValidateDurationLiterals

cel/validator_test.go:29–84  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

27)
28
29func TestValidateDurationLiterals(t *testing.T) {
30 env, err := NewEnv(
31 Variable("x", types.StringType),
32 ASTValidators(ValidateDurationLiterals()))
33 if err != nil {
34 t.Fatalf("NewEnv(ValidateDurationLiterals()) failed: %v", err)
35 }
36
37 tests := []struct {
38 expr string
39 iss string
40 }{
41 {
42 expr: `duration('1')`,
43 iss: `ERROR: <input>:1:10: invalid duration argument
44 | duration('1')
45 | .........^`,
46 },
47 {
48 expr: `duration('1d')`,
49 iss: `ERROR: <input>:1:10: invalid duration argument
50 | duration('1d')
51 | .........^`,
52 },
53 {
54 expr: "duration('1us')\n < duration('1nns')",
55 iss: `ERROR: <input>:2:13: invalid duration argument
56 | < duration('1nns')
57 | ............^`,
58 },
59 {
60 expr: `duration('2h3m4s5us')`,
61 },
62 {
63 expr: `duration(x)`,
64 },
65 }
66 for _, tst := range tests {
67 tc := tst
68 t.Run(tc.expr, func(t *testing.T) {
69 _, iss := env.Compile(tc.expr)
70 if tc.iss != "" {
71 if iss.Err() == nil {
72 t.Fatalf("e.Compile(%v) returned ast, expected error: %v", tc.expr, tc.iss)
73 }
74 if !test.Compare(iss.Err().Error(), tc.iss) {
75 t.Fatalf("e.Compile(%v) returned %v, expected error: %v", tc.expr, iss.Err(), tc.iss)
76 }
77 return
78 }
79 if iss.Err() != nil {
80 t.Fatalf("e.Compile(%v) failed: %v", tc.expr, iss.Err())
81 }
82 })
83 }
84}
85
86func TestValidateTimestampLiterals(t *testing.T) {

Callers

nothing calls this directly

Calls 8

CompileMethod · 0.95
CompareFunction · 0.92
ASTValidatorsFunction · 0.85
ValidateDurationLiteralsFunction · 0.85
ErrMethod · 0.80
NewEnvFunction · 0.70
VariableFunction · 0.70
ErrorMethod · 0.45

Tested by

no test coverage detected