Skip to content

Commit b48cd77

Browse files
committed
sqlexec: cover the HandleSQLPattern regex path over HTTP
Add an HTTP test that registers a regex matcher and echoes back a captured submatch, exercising Server.HandleSQLPattern and Request.Match end-to-end. This was the only SQL-exec path without coverage; it also gives HandleSQLPattern a caller (the deadcode check flagged the Server-level wrapper as unreachable). Co-authored-by: Isaac
1 parent 76663a4 commit b48cd77

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

libs/sqlexec/sqlexec_http_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package sqlexec_test
22

33
import (
4+
"regexp"
45
"testing"
56
"time"
67

@@ -48,6 +49,19 @@ func TestHTTPExecuteSuccess(t *testing.T) {
4849
assert.Equal(t, [][]string{{"1", "2"}}, r.Rows)
4950
}
5051

52+
func TestHTTPExecutePattern(t *testing.T) {
53+
server := newServer(t)
54+
// A regex matcher echoes back a captured submatch, exercising the
55+
// HandleSQLPattern path and Request.Match over the full HTTP round-trip.
56+
server.HandleSQLPattern(regexp.MustCompile(`^SELECT (\d+)$`), func(r testsql.Request) testsql.Result {
57+
return testsql.Result{Columns: []string{"n"}, Rows: [][]string{{r.Match[1]}}}
58+
})
59+
60+
got, err := httpClient(t, server).ExecuteScalar(t.Context(), "SELECT 42")
61+
require.NoError(t, err)
62+
assert.Equal(t, "42", got)
63+
}
64+
5165
func TestHTTPExecutePolls(t *testing.T) {
5266
server := newServer(t)
5367
server.HandleSQL("SELECT 1", func(testsql.Request) testsql.Result {

0 commit comments

Comments
 (0)