testcontainer

package
v0.0.0-...-b7c5dae Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package testcontainer starts the servers oceanbase's oracle tests run against: one testcontainer of each per test binary, started by the first test that asks and removed by Terminate, which the package's TestMain calls.

MySQL80 answers for the grammar OceanBase inherited from MySQL. A test gets a database of its own on it, reached through an account that holds privileges only on the databases this package creates, so a statement a corpus runs (SET GLOBAL, SHUTDOWN, ALTER USER root) cannot change the server under the tests that follow. Those statements answer 1227 or 1044, which a verdict that looks for 1064 still reads as parsed. OceanBase answers for OceanBase itself, as root.

Index

Constants

View Source
const OceanBaseImage = "oceanbase/oceanbase-ce:4.3.5.6-106000012026040916"

OceanBaseImage is the build the recorded OceanBase verdicts were read on. The 4.3.5-lts tag moves with each patch release, so this names the patch.

View Source
const OceanBaseVersion = "5.7.25-OceanBase_CE-v4.3.5.6"

OceanBaseVersion is what SELECT VERSION() answers on OceanBaseImage.

Variables

View Source
var MySQL80 = &Server{Image: "mysql:8.0", Args: []string{"--skip-log-bin"}}

MySQL80 is mysql:8.0. The binary log stays off so the restricted account can create routines (1419 otherwise).

View Source
var OceanBase = &oceanBase{}

OceanBase is the package's OceanBase CE in MySQL mode. Tests log in as root in the test tenant, so they may create accounts, use fixed database names and change server-wide settings.

Functions

func OceanBaseTransient

func OceanBaseTransient(err error) bool

OceanBaseTransient reports an error OceanBase answers while it is between leaders or starved for CPU, which the same statement clears once the server settles. On a busy box (load average 380 on 20 cores, 2026-11-05) the root service is revoked and taken back within a minute, and a log stream changes leader.

A verdict must never read one of these as an answer: engineAccepts-style helpers take any code but 1064 to mean the statement parsed.

func OpenOceanBase

func OpenOceanBase(dsn string) (*sql.DB, error)

OpenOceanBase opens dsn through a connector that runs each statement again while OceanBase answers a transient error, for up to three minutes, so no test has to wrap its own statements. A statement still failing after that returns the last error as a plain error.

Types

type Database

type Database struct {
	// DB is a pool of connections that start in the database, on the restricted
	// account, pinned to one connection so that USE and session state hold across
	// statements.
	DB   *sql.DB
	Name string
}

Database is a test's own database on a Server.

func (*Database) Close

func (d *Database) Close(ctx context.Context)

Close drops the database and closes the pool.

func (*Database) Reset

func (d *Database) Reset(ctx context.Context) error

Reset empties the database and selects it, as a server of its own would be for the next test.

type Server

type Server struct {
	// Image is the pinned image.
	Image string
	// Args are the server's arguments.
	Args []string
	// contains filtered or unexported fields
}

Server is one MySQL server a test binary starts on first use.

func (*Server) Database

func (s *Server) Database(ctx context.Context, label string) (*Database, error)

Database creates a database named for label and returns it.

func (*Server) Terminate

func (s *Server) Terminate()

Terminate removes the server, if this process started one.

Jump to

Keyboard shortcuts

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