dbimptest

package
v0.26.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 32 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package dbimptest holds the test helpers that every driver in github.com/xo/dbimp shares. It replays and records the responses of a real server, checks that a test leaves no goroutine behind, runs the contract of docs/DRIVER.md against a driver, and compares the type table and the interface table of a driver with its document, or writes them.

Only a test imports this package. It imports testing and net/http/httptest, which a driver must not pull into the build of a consumer, so it is not in the root package (D37 in docs/decisions/).

Index

Constants

View Source
const (
	// KindCRUD is a statement of CRUD, such as update.
	KindCRUD = "crud"
	// KindSchema is an operation on a schema, such as a foreign key.
	KindSchema = "schema"
	// KindFeature is a feature of the database that is its own.
	KindFeature = "feature"
	// KindType is a native type.
	KindType = "type"
)

The kinds of an entry of the survey.

View Source
const (
	// SourceModel is an AI model.
	SourceModel = "model"
	// SourceDriver is another driver, in Go or in another language.
	SourceDriver = "driver"
)

The kinds of a source of the survey.

View Source
const (
	// NotMeasured is the verdict of an entry that no server settled yet.
	NotMeasured = "not measured"
	// Yes is the verdict of an entry that the server supports.
	Yes = "yes"
	// No is the verdict of an entry that the server refused.
	No = "no"
)

The verdicts of an entry of the survey.

View Source
const (
	// Administrator is the principal that administers the server.
	Administrator = "administrator"
	// Ordinary is the ordinary user that the Init step of dbrun creates.
	Ordinary = "ordinary"
)

The principals of step 6 of docs/DRIVER.md.

View Source
const (
	TypesBegin      = "<!-- dbimp:types -->"
	TypesEnd        = "<!-- /dbimp:types -->"
	InterfacesBegin = "<!-- dbimp:interfaces -->"
	InterfacesEnd   = "<!-- /dbimp:interfaces -->"
)

The markers around a generated table in docs/<PRODUCT>.md.

View Source
const (
	KindsBegin  = "<!-- dbimp:kinds -->"
	KindsEnd    = "<!-- /dbimp:kinds -->"
	MatrixBegin = "<!-- dbimp:matrix -->"
	MatrixEnd   = "<!-- /dbimp:matrix -->"
)

The markers around the list of kinds, and around the generated table of every driver, in docs/TYPES.md (step 8a).

View Source
const (
	// FrameText is a text frame.
	FrameText = "text"
	// FrameBinary is a binary frame.
	FrameBinary = "binary"
	// FrameClose is a close frame, which only a reply can be.
	FrameClose = "close"
)

The types of a WebSocketFrame.

View Source
const EnvUpdate = "DBIMP_UPDATE"

EnvUpdate is the environment variable that makes TypeTable and InterfaceTable write their table into the document, rather than compare it.

View Source
const FeaturesName = "features.json"

FeaturesName is the name of the survey of step 5a of docs/DRIVER.md in testdata/<driver>/.

View Source
const HeapLimit = 16 << 20

HeapLimit is the growth of the live heap that a driver can cause while it reads a result of 64 MiB, as D25 requires.

View Source
const ManifestName = "manifest.json"

ManifestName is the name of the manifest in testdata/<driver>/.

View Source
const RequestsName = "requests.json"

RequestsName is the name of the script in testdata/<driver>/ that the command dbimptest/cmd/record reads. It lists the requests of step 6.

View Source
const TransportWebSocket = "websocket"

TransportWebSocket is the value of the member transport of a file that holds a WebSocketExchange.

Variables

This section is empty.

Functions

func CheckGoroutines

func CheckGoroutines(t *testing.T)

CheckGoroutines fails the test if a goroutine that started during the test is still running when the test ends, as step 12 of docs/DRIVER.md requires. Call it first in the test, so that it runs after every other cleanup, such as the one that closes the database. It counts every goroutine of the process, so the test that calls it must not run in parallel with another test.

func DefaultMatch

func DefaultMatch(r *http.Request, body []byte, ex *Exchange) bool

DefaultMatch matches the method, the path and the query exactly. It matches two JSON bodies if their canonical forms are equal, and any other two bodies if their bytes are equal.

func DefaultWebSocketMatch added in v0.20.0

func DefaultWebSocketMatch(t WebSocketTurn) bool

DefaultWebSocketMatch matches the key of the frame that arrived with the key of the request of the exchange. The key is the string member command of a JSON object. A frame with no such member takes the key of the frame before it, with the prefix "after:", as the message with the credentials of a login has none. A frame that is not a JSON object has its bytes as its key.

func InterfaceTable

func InterfaceTable(t *testing.T, doc string, reasons map[string]string, connector driver.Connector, values ...any)

InterfaceTable compares the interface table of step 10 of docs/DRIVER.md with the table between InterfacesBegin and InterfacesEnd in the document at doc, and writes it there when EnvUpdate is set. values are the types of the driver, such as its driver, its connector, a connection and its rows. An interface is implemented if one of values implements it. reasons holds, for each interface, why the driver implements it or does not, and the test fails if one is missing. The connector is the only value that must implement io.Closer.

func RedactMembers added in v0.20.0

func RedactMembers(text string, names []string) string

RedactMembers returns text with the value of each member that is named in names written as REDACTED, at any depth. It returns text as it is if text is not JSON.

func Replay

func Replay(t *testing.T, dir string, match Match) *httptest.Server

Replay starts a fake server that answers each request with the response of the first exchange in dir that match accepts. If match is nil, it uses DefaultMatch. A request that no exchange matches fails the test. Replay reads every file in dir except the manifest, the script of requests and the survey, and closes the server when the test ends.

func ReplayRelease

func ReplayRelease(t *testing.T, dir, release string, match Match) *httptest.Server

ReplayRelease is Replay for the exchanges of one release only, whose files start with the name of the release, as dbrun names it. A test uses it when releases answer the same request in different ways.

func ReplayWebSocket added in v0.20.0

func ReplayWebSocket(t *testing.T, dir string, match WebSocketMatch) *httptest.Server

ReplayWebSocket starts a TLS server that accepts a WebSocket on any path. For each request frame that arrives, it sends the reply of the first exchange in dir that match accepts, in the order of the file names. If match is nil, it uses DefaultWebSocketMatch. A request that no exchange matches fails the test and closes the connection. An exchange with no reply sends nothing, and a reply that is a close frame closes the connection. The server answers a ping and the close of the client. ReplayWebSocket reads every file in dir that holds a WebSocketExchange. It closes the server and its connections when the test ends. A client trusts srv.Certificate().

func RoundTrip

func RoundTrip(tb testing.TB, db *sql.DB, c RoundTripCase)

RoundTrip runs the round trip of c against db. For each value, and once with the value as a bound argument and once as a literal, it inserts a row, selects it by its key and compares the value, updates it to the next value, selects and compares again, deletes it, and selects to see that it is gone. It reads each value into a *any, so the comparison covers the Go type that database/sql returns, and it never selects a literal in place of a stored value.

func RunContract

func RunContract(t *testing.T, c Contract)

RunContract tests the driver against c. Each subtest checks that it leaves no goroutine behind, so the test that calls RunContract must not run in parallel with another test.

func ThriftReply added in v0.26.0

func ThriftReply(name string, result func(*dbimp.ThriftEncoder)) []byte

ThriftReply returns the message that answers the call name, with a result struct that result writes.

func TypeTable

func TypeTable(t *testing.T, doc string, rows []TypeRow)

TypeTable compares rows, as the type table, with the table between TypesBegin and TypesEnd in the document at doc, and fails the test if the document holds another table. If EnvUpdate is set, it writes the table into the document.

func WithLabel

func WithLabel(ctx context.Context, item int, principal string) context.Context

WithLabel returns a context that labels the request made with it. A Recorder uses that label rather than the one that Label set, so that a request that runs while others are sent keeps its own item.

func WriteBlock added in v0.7.0

func WriteBlock(t *testing.T, doc, begin, end, want string)

WriteBlock compares the text between begin and end in the document at doc with want, or writes want there if EnvUpdate is set, as TypeTable does for its table. The table of docs/TYPES.md is one such block.

func WriteManifest

func WriteManifest(path string, m *Manifest) error

WriteManifest writes m to the file at path.

Types

type ColumnsCase

type ColumnsCase struct {
	Body string
	Want []string
}

ColumnsCase is a result and the names of its columns, in order.

type Contract

type Contract struct {
	// Open returns a database for the fake server at url, which is an
	// http:// URL. The driver builds its own DSN from url.
	Open func(t *testing.T, url string) *sql.DB
	// Query is any statement. A fake server ignores it, and answers each case
	// with the body of that case.
	Query string
	// Columns is a result with at least two columns.
	Columns ColumnsCase
	// Null is a result whose first row holds a NULL.
	Null NullCase
	// ErrorAfterRows is a result that holds some rows and then an error.
	ErrorAfterRows ErrorCase
	// Stream is the form of a result with many rows.
	Stream StreamCase
	// Transactions is true if the driver supports transactions. If it is
	// false, BeginTx must return dbimp.ErrNotSupported (D20).
	Transactions bool
	// ContentType is the content type of the bodies of the cases, such as
	// "application/cbor". It is "application/json" when it is empty.
	ContentType string
	// WebSocket, if it is not nil, makes RunContract test a driver whose product
	// takes its requests as frames of a WebSocket, such as Exasol (D200). The
	// cases above send an HTTP request and read an HTTP body, so a WebSocket
	// driver cannot run them, and RunContract then ignores every other field and
	// runs the cases of WebSocketContract.
	WebSocket *WebSocketContract
	// Thrift, if it is not nil, makes RunContract test a driver whose product takes
	// its calls as Thrift messages over HTTP, such as Hive and Impala (D232). A
	// result there arrives in pages, one call for each page, so RunContract then
	// ignores every other field and runs the cases of ThriftContract.
	Thrift *ThriftContract
}

Contract is the part of the contract of D8 and D18 to D21 that every driver keeps in the same way. RunContract tests it against fake servers, which answer with bodies in the form of the product. The driver supplies the bodies, because each product has its own form.

type Entry

type Entry struct {
	// Item is the number of the item in step 6 of docs/DRIVER.md.
	Item int `json:"item"`
	// Principal is Administrator or Ordinary.
	Principal string `json:"principal"`
	// Release is the release of the server, as dbrun names it.
	Release string `json:"release"`
	// Date is the date of the recording, as YYYY-MM-DD.
	Date string `json:"date"`
	// File is the name of the exchange in testdata/<driver>/, or "" if Absent
	// is set.
	File string `json:"file,omitzero"`
	// Absent is the reason why the item does not apply to the product, such as
	// "no transactions", or "" if File is set.
	Absent string `json:"absent,omitzero"`
}

Entry is one recorded exchange, or one item of step 6 that does not apply to the product.

type ErrorCase

type ErrorCase struct {
	Body string
	Rows int
}

ErrorCase is a result that holds Rows rows and then an error.

type Exchange

type Exchange struct {
	Request  Request  `json:"request"`
	Response Response `json:"response"`
}

Exchange is one request to a real server and its response, as a file under testdata/<driver>/ holds it.

func ReadExchange

func ReadExchange(path string) (*Exchange, error)

ReadExchange reads the exchange in the file at path.

type Feature

type Feature struct {
	// Kind is KindCRUD, KindSchema, KindFeature or KindType.
	Kind string `json:"kind"`
	// Name names it, such as "update", "foreign key" or "number". A type is
	// named as the type table names it.
	Name string `json:"name"`
	// Sources names each source that named it.
	Sources []string `json:"sources"`
	// Verdict is NotMeasured, Yes or No.
	Verdict string `json:"verdict"`
	// Evidence is the recorded file under testdata/<driver>/ that shows what
	// the server answered: for the verdict No, that it lacks the entry.
	Evidence string `json:"evidence,omitzero"`
	// Test is the test that exercises it, as a function and a subtest, such
	// as "TestIntegrationCRUD/update". For the verdict No, the test sends
	// the operation and expects the refusal of the server, or shows that the
	// server ignores it.
	Test string `json:"test,omitzero"`
}

Feature is one operation, feature or type of the survey.

type Features

type Features struct {
	// Driver is the name of the driver.
	Driver string `json:"driver"`
	// Consulted lists each model and each driver that the survey asked.
	Consulted []Source `json:"consulted"`
	// Entries has one entry for each operation, feature and type.
	Entries []Feature `json:"entries"`
}

Features is the survey of step 5a of docs/DRIVER.md: each operation, feature and type of one database, where each came from, what the server said about it, and the test that exercises it.

func ReadFeatures

func ReadFeatures(path string) (*Features, error)

ReadFeatures reads the survey in the file at path.

type HeapGauge added in v0.17.0

type HeapGauge struct {
	// contains filtered or unexported fields
}

HeapGauge measures how much the live heap of the process grows while a driver reads a large result. It reads HeapAlloc after a full collection, so that garbage that the collector has not yet freed, the free slots inside a span, and the memory that earlier tests left live do not count. A driver that holds the whole result still shows the whole result.

A test that uses a HeapGauge must not run in parallel with another test.

func NewHeapGauge added in v0.17.0

func NewHeapGauge() *HeapGauge

NewHeapGauge returns a HeapGauge whose base is the live heap now. Call it after the test has opened its database and before it reads the first row.

func (*HeapGauge) Check added in v0.17.0

func (g *HeapGauge) Check(t *testing.T)

Check fails the test if the largest growth is over HeapLimit.

func (*HeapGauge) Peak added in v0.17.0

func (g *HeapGauge) Peak() uint64

Peak returns the largest growth in bytes that Sample recorded.

func (*HeapGauge) Sample added in v0.17.0

func (g *HeapGauge) Sample()

Sample collects garbage and records the growth of the live heap since the base, if it is the largest growth so far.

type Manifest

type Manifest struct {
	// Driver is the name of the driver.
	Driver string `json:"driver"`
	// NoOrdinaryUser is the reason why the product has no ordinary user, or
	// "" if it has one.
	NoOrdinaryUser string `json:"noOrdinaryUser,omitzero"`
	// Entries has one entry for each recorded exchange.
	Entries []Entry `json:"entries"`
}

Manifest lists the recorded exchanges of one driver, as step 6 of docs/DRIVER.md requires.

func ReadManifest

func ReadManifest(path string) (*Manifest, error)

ReadManifest reads the manifest in the file at path.

type Match

type Match func(r *http.Request, body []byte, ex *Exchange) bool

Match reports whether a request that a fake server received, with its body, is the request of ex.

type NullCase

type NullCase struct {
	Body   string
	Column int
}

NullCase is a result whose first row holds a NULL in column Column.

type Recorder

type Recorder struct {
	// contains filtered or unexported fields
}

Recorder is an http.RoundTripper that writes each exchange with a real server into a directory, as step 6 of docs/DRIVER.md requires. It removes the value of each header that holds a credential. It reads each response whole, so it is for a recording and never for a driver.

func NewRecorder

func NewRecorder(dir, release string, next http.RoundTripper) *Recorder

NewRecorder returns a Recorder that sends each request with next and writes each exchange into dir. release is the release of the server, as dbrun names it, and the name of each file starts with it.

func (*Recorder) Label

func (r *Recorder) Label(item int, principal string)

Label sets the item of step 6 and the principal of the exchanges that follow, when a request carries no label of its own.

func (*Recorder) RedactMembers added in v0.20.0

func (r *Recorder) RedactMembers(names ...string)

RedactMembers adds names to the members that the Recorder writes as REDACTED in the frames of a WebSocket, at any depth, such as the password of a login.

func (*Recorder) RoundTrip

func (r *Recorder) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip sends req, and writes the exchange.

func (*Recorder) Secret added in v0.10.0

func (r *Recorder) Secret(s string)

Secret adds s to the texts that the Recorder writes as REDACTED in the body of each request, for a server that takes a password in the body, such as the info of openConnection of Avatica.

func (*Recorder) WriteManifest

func (r *Recorder) WriteManifest(driver string) error

WriteManifest adds the entries of the recording to the manifest of driver in the directory, and writes the manifest.

func (*Recorder) WriteWebSocket added in v0.20.0

func (r *Recorder) WriteWebSocket(ctx context.Context, session string, req, reply WebSocketFrame) error

WriteWebSocket writes one exchange of a WebSocket into the directory of the Recorder. The frame reply can be the zero frame for a request that the server did not answer. It redacts the passwords that Secret names and the members that RedactMembers names, and it labels the exchange as RoundTrip does. The frames that it gets hold the message as sent, so a frame of text or of JSON is redacted and a binary frame is not.

type Request

type Request struct {
	Method string      `json:"method"`
	Path   string      `json:"path"`
	Query  string      `json:"query,omitzero"`
	Header http.Header `json:"header,omitzero"`
	Body   string      `json:"body,omitzero"`
	Binary []byte      `json:"binary,omitzero"`
}

Request is the recorded part of a request. A body that is text is in Body, and a binary body, such as one in CBOR, is in Binary, which the file holds as base64.

func (Request) Content added in v0.2.0

func (r Request) Content() []byte

Content returns the bytes of the body.

type Response

type Response struct {
	Status    int         `json:"status"`
	Header    http.Header `json:"header,omitzero"`
	Body      string      `json:"body"`
	Binary    []byte      `json:"binary,omitzero"`
	Truncated bool        `json:"truncated,omitzero"`
}

Response is the recorded part of a response. A body that is text is in Body, and a binary body is in Binary, as for a Request. Truncated is true when the server closed the connection before the end of the body, as InfluxDB 3 does for an error after some rows. Body then holds what arrived.

func (Response) Content added in v0.2.0

func (r Response) Content() []byte

Content returns the bytes of the body.

type RoundTripCase

type RoundTripCase struct {
	// Type names the type, as the type table names it.
	Type string
	// Setup holds the statements that create the table, which RoundTrip
	// runs once, before any value.
	Setup []string
	// Teardown holds the statements that drop what Setup made. RoundTrip
	// runs them in a cleanup, so they run even when the test fails.
	Teardown []string
	// Insert inserts one row. Its arguments are the key and the value.
	Insert string
	// Literal returns a statement that inserts one row, with the key and the
	// value written as literals. It returns an error that wraps
	// dbimp.ErrNotSupported for a value that the database cannot write as a
	// literal, and RoundTrip logs that and goes on.
	Literal func(key string, v any) (string, error)
	// Select selects the value of the row with a key, which is its one
	// argument. It returns one column.
	Select string
	// Update sets the value of the row with a key. Its arguments are the
	// value and the key.
	Update string
	// Delete deletes the row with a key, which is its one argument. If it is
	// empty, RoundTrip logs that the database cannot delete one row, and
	// skips the delete and the check that the row is gone, as for InfluxDB 3
	// Core.
	Delete string
	// Column is the column of the value in the row that Select returns, for a
	// database that returns other columns with it, such as the name and the
	// time of an InfluxQL series. It is 0 by default.
	Column int
	// SkipUpdate returns why the update from one value to the next cannot
	// run, or "" when it can. RoundTrip logs the reason, and skips the update
	// and the read after it. It is for a database that cannot hold the
	// update, such as InfluxDB, which keeps the old value of a field that an
	// update leaves out as NULL. If it is nil, every update runs.
	SkipUpdate func(from, to Value) string
	// Values are the values to store. RoundTrip updates each value to the
	// next one, and the last one to the first, so it needs at least two.
	Values []Value
	// Wait is how long RoundTrip reads again until a read sees the write
	// before it, for a database that updates an index after a write. Zero
	// reads once.
	Wait time.Duration
	// Equal compares a value read back with the value wanted. If it is nil,
	// RoundTrip uses reflect.DeepEqual, which also compares the Go types.
	Equal func(got, want any) bool
	// Named passes each argument by name, for a database that binds named
	// parameters only: the key as sql.Named("key", k), and the value as
	// sql.Named("value", v). The statements then name the key and the value,
	// such as $key and $value.
	Named bool
	// KeyArg turns the key into the argument that the statements take, such
	// as a record id. If it is nil, the argument is the key as a string.
	// Literal gets the key as a string, and writes it in the same form.
	KeyArg func(key string) any
}

RoundTripCase is the round trip of one type, as step 14a of docs/DRIVER.md requires. The driver supplies the statements, because each database writes them in its own way. RoundTrip runs every step itself.

type ScriptedWebSocket added in v0.20.0

type ScriptedWebSocket struct {
	// contains filtered or unexported fields
}

ScriptedWebSocket is a TLS server that answers the request frames of each connection with a script. Unlike ReplayWebSocket, it keeps no recorded exchange and matches nothing: step i answers the i-th request frame of a connection, whatever it holds. A test uses it for a case that no recording holds, such as a reply that waits for a cancel.

func ServeWebSocketScript added in v0.20.0

func ServeWebSocketScript(tb testing.TB, script []WebSocketStep) *ScriptedWebSocket

ServeWebSocketScript starts a server that answers each connection with script. A request frame after the last step fails the test and closes the connection. The server closes with the test.

func (*ScriptedWebSocket) Addr added in v0.20.0

func (s *ScriptedWebSocket) Addr() string

Addr returns the host and the port of the server.

func (*ScriptedWebSocket) Certificate added in v0.20.0

func (s *ScriptedWebSocket) Certificate() *x509.Certificate

Certificate returns the certificate of the server, which nothing trusts but a client that is given it.

func (*ScriptedWebSocket) Frames added in v0.20.0

func (s *ScriptedWebSocket) Frames() []WebSocketFrame

Frames returns the data frames that the server read, in order, from every connection.

func (*ScriptedWebSocket) Held added in v0.20.0

func (s *ScriptedWebSocket) Held() <-chan struct{}

Held returns a channel that closes when the server starts to wait at a step with Hold, a moment after it read the request.

type Source

type Source struct {
	// Source names the model, or the import path of the driver.
	Source string `json:"source"`
	// Kind is SourceModel or SourceDriver.
	Kind string `json:"kind"`
	// Date is the date of the question, as YYYY-MM-DD.
	Date string `json:"date"`
}

Source is one model or one driver that the survey asked.

type StreamCase

type StreamCase struct {
	Head string
	Row  string
	Sep  string
	Tail string
}

StreamCase is the form of a result with many rows of one column: Head, then Row repeated with Sep between each two, then Tail.

type ThriftColumns added in v0.26.0

type ThriftColumns struct {
	Steps []ThriftStep
	Want  []string
}

ThriftColumns is a result and the names of its columns, in order.

type ThriftContract added in v0.26.0

type ThriftContract struct {
	// Open returns a database for the fake server at url, which is an http:// URL.
	// The driver builds its own DSN from url.
	Open func(t *testing.T, url string) *sql.DB
	// Query is any statement. The fake server ignores it.
	Query string
	// Common holds the steps that answer a call each time it comes, in any order,
	// such as OpenSession and CloseOperation. A step of a case answers first.
	Common []ThriftStep
	// Columns is a result with at least two columns.
	Columns ThriftColumns
	// Null is a result whose first row holds a NULL. The test runs the steps three
	// times in a row, one for each query that it makes.
	Null ThriftNull
	// ErrorAfterRows is a result that holds some rows, and then an error when the
	// driver reads the next page.
	ErrorAfterRows ThriftErrorCase
	// Close is a result of which the first page holds some rows, and no step for a
	// call that reads another page. A driver that reads more after Close fails the
	// test.
	Close []ThriftStep
	// Cancel is a result of which the first page holds one row, then a step with
	// Hold for the call that reads the next page. The test cancels the context
	// while the server holds that call.
	Cancel []ThriftStep
	// Drop is the name of the call that the statement sends first after the
	// session opens, such as ExecuteStatement. The server closes the connection
	// when it reads it.
	Drop string
	// Transactions is true if the driver supports transactions. If it is false,
	// BeginTx must return dbimp.ErrNotSupported (D20).
	Transactions bool
}

ThriftContract is the part of the contract of D8 and D18 to D21 for a driver whose product takes its calls as Thrift messages over HTTP, such as Hive and Impala (D232). Each call is one HTTP request, and a result arrives in pages, so the cases of the other contracts do not fit. The driver supplies the steps of a script for each case, because each product has its own calls. A step answers the next call of its name, and a call that no step answers fails the test.

type ThriftErrorCase added in v0.26.0

type ThriftErrorCase struct {
	Steps []ThriftStep
	Rows  int
}

ThriftErrorCase is a result that holds Rows rows and then an error.

type ThriftNull added in v0.26.0

type ThriftNull struct {
	Steps  []ThriftStep
	Column int
}

ThriftNull is a result whose first row holds a NULL in column Column.

type ThriftStep added in v0.26.0

type ThriftStep struct {
	// Call is the name of the call that the step answers, such as
	// "FetchResults".
	Call string
	// Reply is the whole message that the server writes.
	Reply []byte
	// Hold makes the server wait for the client to leave, and write nothing.
	Hold bool
}

ThriftStep is one answer of a fake server of Thrift.

type TypeRow

type TypeRow struct {
	// Wire is the name of the type on the wire, such as "number".
	Wire string
	// Kind is the kind of the type, one of the kinds of docs/TYPES.md, such
	// as "integer" (step 8a of docs/DRIVER.md). Kinds sets it.
	Kind string
	// Go is the Go type of a value, such as "int64".
	Go string
	// ScanType is the type that ColumnTypeScanType returns.
	ScanType string
	// DatabaseType is the name that ColumnTypeDatabaseTypeName returns, in
	// upper case.
	DatabaseType string
	// Nullable is true if a column of the type can be NULL.
	Nullable bool
}

TypeRow is one row of the type table of step 10 of docs/DRIVER.md.

func Kinds added in v0.7.0

func Kinds(t *testing.T, rows []TypeRow, kinds map[string]string) []TypeRow

Kinds returns rows with the kind of each row set from kinds, by the name of its wire type (step 8a). It fails the test for a row that kinds does not name, and for a name of kinds that no row has.

type Value

type Value struct {
	// Name names the value, such as "max" or "unicode".
	Name string
	// In is the value to write.
	In any
	// Want is the value that a read returns into a *any. If it is nil and In
	// is not, RoundTrip wants In.
	Want any
}

Value is one value of a round trip.

type WebSocketColumns added in v0.20.0

type WebSocketColumns struct {
	Steps []WebSocketStep
	Want  []string
}

WebSocketColumns is a result and the names of its columns, in order.

type WebSocketContract added in v0.20.0

type WebSocketContract struct {
	// Open returns a database for the server at addr, which is host:port of a
	// TLS server with a certificate that nothing trusts. The driver builds its
	// own DSN from addr, and turns the check of the certificate off.
	Open func(t *testing.T, addr string) *sql.DB
	// Query is any statement. The fake server ignores it, and answers each case
	// with the steps of that case.
	Query string
	// Login holds the steps of a login, which every case starts with.
	Login []WebSocketStep
	// Columns is a result with at least two columns.
	Columns WebSocketColumns
	// Null is a result whose first row holds a NULL.
	Null WebSocketNull
	// ErrorAfterRows is a result that holds some rows, and then an error when
	// the driver reads more.
	ErrorAfterRows WebSocketErrorCase
	// Close is a result of many rows, of which the first message holds some,
	// then the step that answers the request that frees the result. A driver
	// that reads more rows after Close fails the test.
	Close []WebSocketStep
	// Cancel is a result of many rows, of which the first message holds some,
	// then a step with Hold whose Reply is the answer of the server to a query
	// that the client aborted, then the step for the request that frees the
	// result. The test cancels the context while the server holds the request
	// that reads more rows.
	Cancel []WebSocketStep
	// Transactions is true if the driver supports transactions. If it is false,
	// BeginTx must return dbimp.ErrNotSupported (D20).
	Transactions bool
}

WebSocketContract is the part of the contract of D8 and D18 to D21 for a driver whose product takes its requests as frames of a WebSocket. The driver supplies the steps of a script for each case, because each product has its own frames. A step answers the request frame of the same position, so the script lists the frames that a correct driver sends, in order, and a frame that the script does not hold fails the test.

type WebSocketErrorCase added in v0.20.0

type WebSocketErrorCase struct {
	Steps []WebSocketStep
	Rows  int
}

WebSocketErrorCase is a result that holds Rows rows and then an error.

type WebSocketExchange added in v0.20.0

type WebSocketExchange struct {
	// Transport is TransportWebSocket.
	Transport string `json:"transport"`
	// Session names the session that the exchange belongs to.
	Session string `json:"session,omitzero"`
	// Request is the frame that the client sent.
	Request WebSocketFrame `json:"request"`
	// Reply is the frame that the server sent, or the zero frame if it sent
	// none.
	Reply WebSocketFrame `json:"reply,omitzero"`
}

WebSocketExchange is one request frame to a real server and the reply frame, as a file under testdata/<driver>/ holds it.

func ReadWebSocketExchange added in v0.20.0

func ReadWebSocketExchange(path string) (*WebSocketExchange, error)

ReadWebSocketExchange reads the exchange in the file at path.

type WebSocketFrame added in v0.20.0

type WebSocketFrame struct {
	Type   string         `json:"type,omitzero"`
	JSON   jsontext.Value `json:"json,omitzero"`
	Text   string         `json:"text,omitzero"`
	Binary []byte         `json:"binary,omitzero"`
	// Zlib is true for a binary frame whose bytes are the zlib form of the
	// text of the frame. The file holds the text, and the replay compresses it.
	Zlib bool `json:"zlib,omitzero"`
	// Code is the status code of a close frame.
	Code uint16 `json:"code,omitzero"`
}

WebSocketFrame is one message of a WebSocket, as a file holds it. A text frame that is JSON and short is in JSON, and any other text frame is in Text. A binary frame is in Binary, which the file holds as base64, unless Zlib is set. A close frame holds its code in Code and its reason in Text.

func NewFrame added in v0.20.0

func NewFrame(binaryMsg bool, msg []byte, inflate bool) WebSocketFrame

NewFrame returns the frame for a message that crossed the connection. If inflate is true and a binary message is zlib data of valid UTF-8, the frame holds the text and sets Zlib.

func (WebSocketFrame) Content added in v0.20.0

func (f WebSocketFrame) Content() []byte

Content returns the bytes of the message, as the text of a text frame, the bytes of a binary frame before compression, or the reason of a close frame.

func (WebSocketFrame) Wire added in v0.20.0

func (f WebSocketFrame) Wire() ([]byte, error)

Wire returns the bytes that cross the connection for the message: the zlib form of the content if Zlib is set, and the content otherwise.

type WebSocketMatch added in v0.20.0

type WebSocketMatch func(t WebSocketTurn) bool

WebSocketMatch reports whether the exchange of the turn answers the frame.

func WebSocketMatchOn added in v0.20.0

func WebSocketMatchOn(names ...string) WebSocketMatch

WebSocketMatchOn returns a WebSocketMatch that applies DefaultWebSocketMatch and also requires each of the named members of the two requests to be equal, such as sqlText. A member that both lack is equal.

type WebSocketNull added in v0.20.0

type WebSocketNull struct {
	Steps  []WebSocketStep
	Column int
}

WebSocketNull is a result whose first row holds a NULL in column Column. The test runs the steps three times in a row, one for each query that it makes.

type WebSocketStep added in v0.20.0

type WebSocketStep struct {
	// Reply is the frame that the server sends for the request.
	Reply WebSocketFrame
	// Hold makes the server wait for one more frame before it sends Reply, such
	// as the message that cancels a query. The server counts the extra frame,
	// and it closes Held when it starts to wait.
	Hold bool
	// Drop makes the server read the request, send nothing, and close the
	// connection.
	Drop bool
	// Mute makes the server read the request, send nothing, and keep the
	// connection open until the client closes it, as a server that hangs does.
	Mute bool
}

WebSocketStep is one step of the script of ServeWebSocketScript: what the server does when it reads one request frame.

type WebSocketTurn added in v0.20.0

type WebSocketTurn struct {
	// Got is the request frame that the fake server received.
	Got WebSocketFrame
	// Prev is the request frame that came before Got on the same connection,
	// or the zero frame.
	Prev WebSocketFrame
	// Exchange is the exchange that is tried.
	Exchange *WebSocketExchange
	// Before is the exchange before Exchange in its session, or nil.
	Before *WebSocketExchange
}

WebSocketTurn is what a WebSocketMatch compares.

Directories

Path Synopsis
cmd
record command
Command record sends the requests of step 6 of docs/DRIVER.md to a real server, as the administrator and as the ordinary user, and writes each exchange and the manifest into testdata/<driver>/.
Command record sends the requests of step 6 of docs/DRIVER.md to a real server, as the administrator and as the ordinary user, and writes each exchange and the manifest into testdata/<driver>/.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL