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

Function TestValidateTimestampLiterals

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

Source from the content-addressed store, hash-verified

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

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