Files
zeekay bdc69767ca debrand: rename the connection mock files and rewrite README for this fork
clickconnmock.go becomes conn.go, matching every other file in the package.

The README still described the upstream module throughout — its install path,
import block and constructor. It now documents this fork's actual API
(NewDatastoreNative, ExpectQueryRow/WillReturnRow), and the example was compiled
and run as a test rather than written by hand.

Provenance is recorded honestly: this fork was cut from upstream's v0.13.0, the
latest upstream RELEASE TAG. The v0.14.x tags this repo carries correspond to no
upstream release — 'git ls-remote --tags' upstream returns v0.1.0 through
v0.13.0 and no v0.14 at all. Existing tags are left in place so nothing pinning
them breaks; the README now states the real base.

Earlier provenance comments pointed at github.com/ClickHouse/datastore-go, which
returns 404. They now reference the real counterpart files in
github.com/hanzo-ds/go, with the upstream commit SHAs dropped since those
commits do not exist in this fork.

Zero vendor references remain.
2026-07-26 11:52:21 -07:00

1.4 KiB

mock

A mock library implementing github.com/hanzo-ds/go/lib/driver, for testing code that talks to Datastore without a server.

Install

go get github.com/hanzo-ds/mock

Usage

package main

import (
	"context"
	"testing"

	datastore "github.com/hanzo-ds/go"
	mock "github.com/hanzo-ds/mock"
)

type Video struct {
	Title string
}

func fetchVideos(conn datastore.Conn) (*Video, error) {
	var v Video
	if err := conn.QueryRow(context.Background(), "SELECT title FROM videos LIMIT 1").Scan(&v.Title); err != nil {
		return nil, err
	}
	return &v, nil
}

func TestFetchVideos(t *testing.T) {
	conn, err := mock.NewDatastoreNative(nil)
	if err != nil {
		t.Fatal(err)
	}

	row := mock.NewRow(
		[]mock.ColumnType{{Name: "title", Type: "String"}},
		[]any{"a title"},
	)
	conn.ExpectQueryRow("SELECT title FROM videos LIMIT 1").WillReturnRow(row)

	if _, err := fetchVideos(conn); err != nil {
		t.Fatal(err)
	}
	if err := conn.ExpectationsWereMet(); err != nil {
		t.Fatal(err)
	}
}

See the package documentation at pkg.go.dev.

Provenance

A de-branded fork of the upstream mock library, cut from its v0.13.0 release — the latest upstream release tag. It is built on github.com/hanzo-ds/go and sqlmock.