https://github.com/srikanthccv/clickhouse-go-mock
a mock library implementing support for clickhouse-go/v2/lib/driver
https://github.com/srikanthccv/clickhouse-go-mock
clickhouse driver golang mock testing
Last synced: 4 months ago
JSON representation
a mock library implementing support for clickhouse-go/v2/lib/driver
- Host: GitHub
- URL: https://github.com/srikanthccv/clickhouse-go-mock
- Owner: srikanthccv
- License: apache-2.0
- Created: 2022-11-05T14:26:25.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-06-21T03:49:58.000Z (about 1 year ago)
- Last Synced: 2025-07-09T01:04:24.454Z (12 months ago)
- Topics: clickhouse, driver, golang, mock, testing
- Language: Go
- Homepage:
- Size: 124 KB
- Stars: 0
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ClickHouse-go-mock
A mock library implementing support for [clickhouse-go/v2/lib/driver](https://pkg.go.dev/github.com/ClickHouse/clickhouse-go/v2/lib/driver)
## Install
```go
go get github.com/srikanthccv/ClickHouse-go-mock
```
## Quick Start
```go
package main
import (
"context"
"log"
"github.com/ClickHouse/clickhouse-go/v2"
cmock "github.com/srikanthccv/ClickHouse-go-mock"
)
type Video struct {
Name string `db:"name"`
Title string `db:"title"`
Content string `db:"content"`
}
func fetchVideos(conn clickhouse.Conn) (*Video, error) {
var video Video
if _, err := conn.Query(context.TODO(), "SELECT name, title, content FROM videos WHERE name LIKE ?", "%Cocomelon%"); err != nil {
return nil, err
}
return &video, nil
}
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)
}
mock.ExpectQuery("SELECT name, title, content FROM videos WHERE name LIKE ?").WithArgs("%Cocomelon%")
_, err = fetchVideos(mock)
if err != nil {
log.Fatalf("an error '%s' was not expected when querying a statement", err)
}
if err := mock.ExpectationsWereMet(); err != nil {
log.Fatalf("there were unfulfilled expectations: %s", err)
}
}
```
## Documentation
Please see the package documentation at [godoc.org](https://pkg.go.dev/github.com/srikanthccv/ClickHouse-go-mock).
And tests are the best documentation, see [clickconnmock_test.go](clickconnmock_test.go).
## License
The Apache License, Version 2.0 - see [LICENSE](LICENSE) for more details.
## Credits
This library is built on top of [clickhouse-go](https://github.com/ClickHouse/clickhouse-go) and [sqlmock](https://github.com/DATA-DOG/go-sqlmock)