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

Function TestValidateDurationLiterals

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

Source from the content-addressed store, hash-verified

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