Files
PandeyandGitHub 7ab8f8e001 feat: rename module to SigNoz and support clickhouse-go v2.44.0 (#4)
## Why

`clickhouse-go/v2` **v2.44.0** added a new method `HasData() bool` to
the `driver.Rows` interface. SigNoz needs to upgrade to v2.44.0 (it
fixes a connection-pool slot leak — `acquire conn timeout` — introduced
in v2.43.0 via PRs #1759/#1795), but this mock's `*Rows` did not
implement `HasData()`, so it no longer satisfies `driver.Rows` and
breaks the build.

This ports the mock into a SigNoz-owned module and adds the missing
method.

## What

- Rename module path `github.com/srikanthccv/ClickHouse-go-mock` →
`github.com/SigNoz/clickhouse-go-mock` (incl. example imports).
- Bump `github.com/ClickHouse/clickhouse-go/v2` `v2.43.0` → `v2.44.0`.
- Implement `Rows.HasData()` to satisfy the v2.44.0 `driver.Rows`
interface (mirrors `Next()` semantics).
- Fix `non-constant format string in call to fmt.Errorf` vet errors
flagged by the current Go toolchain.

## Verification

- `go build ./...` ✅
- `go vet ./...` ✅
- `go test ./...` ✅
2026-05-29 23:51:54 +05:30

72 lines
1.9 KiB
Go

package main
import (
"context"
"log"
cmock "github.com/SigNoz/clickhouse-go-mock"
)
func main() {
mock, err := cmock.NewClickHouseNative(nil)
if err != nil {
log.Fatalf("an error '%s' was not expected when opening a stub database connection", err)
}
cols := make([]cmock.ColumnType, 0)
cols = append(cols, cmock.ColumnType{Type: "Int32", Name: "id"})
cols = append(cols, cmock.ColumnType{Type: "String", Name: "title"})
cols = append(cols, cmock.ColumnType{Type: "String", Name: "content"})
values := make([][]any, 1)
values[0] = make([]any, 3)
values[0][0] = int32(42069)
values[0][1] = "Inside the Making of CoComelon, the Children's Entertainment Juggernaut"
values[0][2] = "..."
rows := cmock.NewRows(cols, values)
mock.
ExpectQuery("SELECT id, title, content FROM articles WHERE id = ?").
WithArgs(1).
WillReturnRows(rows)
returnRows, err := mock.Query(context.Background(), "SELECT id, title, content FROM articles WHERE id = ?", 1)
if err != nil {
log.Fatalf("an error '%s' was not expected when querying a statement", err)
}
cnt := 0
for returnRows.Next() {
var id int32
var title string
var content string
err = returnRows.Scan(&id, &title, &content)
if err != nil {
log.Fatalf("an error '%s' was not expected when scanning a row", err)
}
if id != 42069 {
log.Fatalf("expected id to be 42069, but got %d", id)
}
if title != "Inside the Making of CoComelon, the Children's Entertainment Juggernaut" {
log.Fatalf("expected title to be `Inside the Making of CoComelon, the Children's Entertainment Juggernaut`, but got `%s`", title)
}
if content != "..." {
log.Fatalf("expected content to be content, but got %s", content)
}
cnt++
if cnt > 2 {
log.Fatalf("expected only 1 row, but got more")
break
}
}
if err := mock.ExpectationsWereMet(); err != nil {
log.Fatalf("there were unfulfilled expectations: %s", err)
}
}