planreadtest

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package planreadtest holds stored plans in an in-memory API server, for tests of programs that read plans.

A plan here is published through the operator's own store, so it is chunked, bound and committed the way the controller does it. Cases lists the stored states a plan reader has to answer, each with the answer planread gives; a program that reads plans through its own API runs the same cases and has to give the same answers.

The objects carry the UIDs this package assigned and the bindings between them depend on those UIDs, so they belong in a client that keeps them, such as the one NewClient builds. A real API server assigns its own.

Index

Constants

View Source
const Namespace = "application"

Namespace is where every lab stores its schemas.

Variables

This section is empty.

Functions

func Document

func Document(t testing.TB, statements []string) []byte

Document renders a plan document the way an executor writes one, every statement classified safe.

func FutureDocument

func FutureDocument(t testing.TB) []byte

FutureDocument is a plan document from a build that is not this one.

func NewClient

func NewClient(t testing.TB, objects ...client.Object) client.Client

NewClient is an in-memory API server that holds the given objects with the UIDs they carry.

func Scheme

func Scheme(t testing.TB) *runtime.Scheme

Scheme knows the core kinds and the operator's.

func SpanningStatements

func SpanningStatements() []string

SpanningStatements are long enough to cross a chunk boundary, and made of what a boundary must not be allowed to cut: a quote, a backslash escape and a multi-byte character all sit inside the SQL.

Types

type Case

type Case struct {
	// Name is a short identifier, stable across releases of this package.
	Name string
	// Description says what the state is and why the answer is what it is.
	Description string
	// Schema and Selection are what the reader is asked for, in Namespace.
	Schema    string
	Selection planread.Selection
	// Objects are what the API server holds. Load them with NewClient.
	Objects []client.Object
	Want    Want
}

Case is one stored state and the answer a plan reader owes for it.

func Cases

func Cases(t testing.TB) []Case

Cases builds every case. Each starts from its own API server.

type Lab

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

Lab is a namespace on paper: one schema and the plans stored for it.

func NewLab

func NewLab(t testing.TB, name string) *Lab

NewLab stores one PostgreSQL schema with no plan yet.

func (*Lab) AddSchema

func (l *Lab) AddSchema(t testing.TB, name string) *Lab

AddSchema stores another schema beside this lab's, in the same API server.

func (*Lab) Client

func (l *Lab) Client() client.Client

Client is the lab's API server, for reads and for changes a test makes.

func (*Lab) DeleteChunk

func (l *Lab) DeleteChunk(t testing.TB, plan *operatorv1alpha1.PtahSchemaPlan)

DeleteChunk removes the first chunk of a plan.

func (*Lab) DeletePlan

func (l *Lab) DeletePlan(t testing.TB, plan *operatorv1alpha1.PtahSchemaPlan)

DeletePlan removes a stored plan. Its chunks stay, as they would until the garbage collector reaches them.

func (*Lab) EditChunk

EditChunk rewrites the first chunk of a plan in place. Chunks are immutable in a cluster; this is how a test makes one that no longer matches.

func (*Lab) EditManifest

func (l *Lab) EditManifest(t testing.TB, plan *operatorv1alpha1.PtahSchemaPlan, edit func(*operatorv1alpha1.PtahSchemaPlanSpec))

EditManifest rewrites a stored plan's spec in place.

func (*Lab) Objects

func (l *Lab) Objects(t testing.TB) []client.Object

Objects returns every schema, plan and chunk the lab's API server holds, ready for NewClient.

func (*Lab) Publish

func (l *Lab) Publish(t testing.TB, statements []string, marker string) (*operatorv1alpha1.PtahSchemaPlan, []byte)

Publish stores one plan of the given statements and returns it with its exact document. The marker tells two plans of the same lab apart.

func (*Lab) PublishDocument

func (l *Lab) PublishDocument(
	t testing.TB,
	document []byte,
	marker string,
	adjust ...func(*operatorv1alpha1.PtahSchemaPlanSpec),
) *operatorv1alpha1.PtahSchemaPlan

PublishDocument stores exact bytes as a plan, for cases about what the document says rather than the statements in it. Adjust edits the manifest before it is bound.

func (*Lab) Recreate

func (l *Lab) Recreate(t testing.TB, plan *operatorv1alpha1.PtahSchemaPlan)

Recreate deletes a plan and stores the same manifest under the same name as a new object, which is what a delete and a recreate leave behind.

func (*Lab) Schema

func (l *Lab) Schema() *operatorv1alpha1.PtahSchema

Schema is the lab's schema as last read or written.

func (*Lab) SetApplied

func (l *Lab) SetApplied(t testing.TB, plan *operatorv1alpha1.PtahSchemaPlan)

SetApplied records a confirmed apply of a stored plan, with the reference the operator writes.

func (*Lab) SetCurrent

func (l *Lab) SetCurrent(t testing.TB, plan *operatorv1alpha1.PtahSchemaPlan)

SetCurrent points the schema's status at a stored plan.

func (*Lab) Uncommit

func (l *Lab) Uncommit(t testing.TB, plan *operatorv1alpha1.PtahSchemaPlan)

Uncommit takes back the condition that says the chunks were all written, which is the state a publication interrupted halfway leaves behind.

type Want

type Want struct {
	Err error
	// PlanName, Document and Statements describe a plan that reads.
	PlanName   string
	Document   []byte
	Statements []string
}

Want is the answer. Err is nil for a plan that reads, and otherwise the planread error the reader's error must match with errors.Is, and no other.

Jump to

Keyboard shortcuts

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