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

Function TestValidateDurationLiterals

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

Source from the content-addressed store, hash-verified

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