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

Function TestValidateTimestampLiterals

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

Source from the content-addressed store, hash-verified

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

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