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.Load gives, and DisplayCases the same states with the answer planread.LoadForDisplay gives; a program that reads plans through its own API runs the cases of the read it uses 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
- func Document(t testing.TB, statements []string) []byte
- func DocumentWithUnreadFields(t testing.TB, statements []string) []byte
- func FutureDocument(t testing.TB) []byte
- func NewClient(t testing.TB, objects ...client.Object) client.Client
- func Scheme(t testing.TB) *runtime.Scheme
- func SpanningStatements() []string
- func UnreadFieldNames() []string
- type Case
- type Lab
- func (l *Lab) AddSchema(t testing.TB, name string) *Lab
- func (l *Lab) Client() client.Client
- func (l *Lab) DeleteChunk(t testing.TB, plan *operatorv1alpha1.PtahSchemaPlan)
- func (l *Lab) DeletePlan(t testing.TB, plan *operatorv1alpha1.PtahSchemaPlan)
- func (l *Lab) EditChunk(t testing.TB, plan *operatorv1alpha1.PtahSchemaPlan, ...)
- func (l *Lab) EditManifest(t testing.TB, plan *operatorv1alpha1.PtahSchemaPlan, ...)
- func (l *Lab) Objects(t testing.TB) []client.Object
- func (l *Lab) Publish(t testing.TB, statements []string, marker string) (*operatorv1alpha1.PtahSchemaPlan, []byte)
- func (l *Lab) PublishDocument(t testing.TB, document []byte, marker string, ...) *operatorv1alpha1.PtahSchemaPlan
- func (l *Lab) Recreate(t testing.TB, plan *operatorv1alpha1.PtahSchemaPlan)
- func (l *Lab) Schema() *operatorv1alpha1.PtahSchema
- func (l *Lab) SetApplied(t testing.TB, plan *operatorv1alpha1.PtahSchemaPlan)
- func (l *Lab) SetCurrent(t testing.TB, plan *operatorv1alpha1.PtahSchemaPlan)
- func (l *Lab) Uncommit(t testing.TB, plan *operatorv1alpha1.PtahSchemaPlan)
- type Want
Constants ¶
const Namespace = "application"
Namespace is where every lab stores its schemas.
const UnreadValue = "value-of-a-field-this-build-does-not-read"
UnreadValue is what every added field of DocumentWithUnreadFields holds. A reader that shows it has shown a value it did not read.
Variables ¶
This section is empty.
Functions ¶
func Document ¶
Document renders a plan document the way an executor writes one, every statement classified safe.
func DocumentWithUnreadFields ¶ added in v0.2.10
DocumentWithUnreadFields is Document as a newer Ptah could write it: a field added to the plan and to each statement, at the same format version. They are the two fields the strict decoder keeps out of an Apply.
func FutureDocument ¶
FutureDocument is a plan document from a build that is not this one.
func NewClient ¶
NewClient is an in-memory API server that holds the given objects with the UIDs they carry.
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.
func UnreadFieldNames ¶ added in v0.2.10
func UnreadFieldNames() []string
UnreadFieldNames are the names a display read gives the fields DocumentWithUnreadFields adds.
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 ¶
Cases builds every case with the answer planread.Load gives. Each starts from its own API server.
func DisplayCases ¶ added in v0.2.10
DisplayCases builds the same cases with the answer planread.LoadForDisplay gives, which differs on the one stored state that has unread fields.
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 (*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 ¶
func (l *Lab) EditChunk(t testing.TB, plan *operatorv1alpha1.PtahSchemaPlan, edit func(*operatorv1alpha1.PtahSchemaPlanChunk))
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 ¶
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
// UnreadFields are the names a display read gives.
UnreadFields []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.