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

Function TestValidateTimestampLiterals

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

Source from the content-addressed store, hash-verified

86}
87
88func TestValidateTimestampLiterals(t *testing.T) {
89 env, err := NewEnv(
90 Variable("x", types.StringType),
91 ASTValidators(ValidateTimestampLiterals()))
92 if err != nil {
93 t.Fatalf("NewEnv(ValidateTimestampLiterals()) failed: %v", err)
94 }
95
96 tests := []struct {
97 expr string
98 iss string
99 }{
100 {
101 expr: `timestamp('1000-00-00T00:00:00Z')`,
102 iss: `ERROR: <input>:1:11: invalid timestamp argument
103 | timestamp('1000-00-00T00:00:00Z')
104 | ..........^`,
105 },
106 {
107 expr: `timestamp('1000-01-01T00:00:00ZZ')`,
108 iss: `ERROR: <input>:1:11: invalid timestamp argument
109 | timestamp('1000-01-01T00:00:00ZZ')
110 | ..........^`,
111 },
112 {
113 expr: `timestamp('1000-01-01T00:00:00Z')`,
114 },
115 {
116 expr: `timestamp(-6213559680)`, // min unix epoch time.
117 },
118 {
119 expr: `timestamp(-62135596801)`,
120 iss: `ERROR: <input>:1:11: invalid timestamp argument
121 | timestamp(-62135596801)
122 | ..........^`,
123 },
124 {
125 expr: `timestamp(x)`,
126 },
127 }
128 for _, tst := range tests {
129 tc := tst
130 t.Run(tc.expr, func(t *testing.T) {
131 _, iss := env.Compile(tc.expr)
132 if tc.iss != "" {
133 if iss.Err() == nil {
134 t.Fatalf("e.Compile(%v) returned ast, expected error: %v", tc.expr, tc.iss)
135 }
136 if !test.Compare(iss.Err().Error(), tc.iss) {
137 t.Fatalf("e.Compile(%v) returned %v, expected error: %v", tc.expr, iss.Err(), tc.iss)
138 }
139 return
140 }
141 if iss.Err() != nil {
142 t.Fatalf("e.Compile(%v) failed: %v", tc.expr, iss.Err())
143 }
144 })
145 }

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected