MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / TestTokenizeContext_ErrorHandling

Function TestTokenizeContext_ErrorHandling

pkg/sql/tokenizer/context_test.go:189–228  ·  view source on GitHub ↗

TestTokenizeContext_ErrorHandling verifies proper error handling

(t *testing.T)

Source from the content-addressed store, hash-verified

187
188// TestTokenizeContext_ErrorHandling verifies proper error handling
189func TestTokenizeContext_ErrorHandling(t *testing.T) {
190 tests := []struct {
191 name string
192 input string
193 shouldError bool
194 }{
195 {
196 name: "unterminated string",
197 input: "SELECT 'unterminated",
198 shouldError: true,
199 },
200 {
201 name: "invalid character",
202 input: "SELECT \x00 FROM users",
203 shouldError: true,
204 },
205 }
206
207 for _, tt := range tests {
208 t.Run(tt.name, func(t *testing.T) {
209 ctx := context.Background()
210 tkz := GetTokenizer()
211 defer PutTokenizer(tkz)
212
213 tokens, err := tkz.TokenizeContext(ctx, []byte(tt.input))
214
215 if tt.shouldError && err == nil {
216 t.Error("Expected error but got none")
217 }
218
219 if err != nil && err == context.Canceled {
220 t.Error("Should not return context.Canceled for SQL errors")
221 }
222
223 if tt.shouldError && tokens != nil {
224 t.Error("Expected nil tokens on error")
225 }
226 })
227 }
228}
229
230// TestTokenizeContext_CancellationResponseTime verifies fast cancellation (< 100ms requirement)
231func TestTokenizeContext_CancellationResponseTime(t *testing.T) {

Callers

nothing calls this directly

Calls 5

GetTokenizerFunction · 0.85
PutTokenizerFunction · 0.85
RunMethod · 0.80
TokenizeContextMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected