...

Package fixture

import "sigs.k8s.io/structured-merge-diff/v4/internal/fixture"
Overview
Index

Overview ▾

Variables

DeducedParser is a parser that is deduced no matter what the version specified.

var DeducedParser = SameVersionParser{
    T: typed.DeducedParseableType,
}

func FixTabsOrDie

func FixTabsOrDie(in typed.YAMLObject) typed.YAMLObject

FixTabsOrDie counts the number of tab characters preceding the first line in the given yaml object. It removes that many tabs from every line. It panics (it's a test funtion) if some line has fewer tabs than the first line.

The purpose of this is to make it easier to read tests.

type Apply

Apply is a type of operation. It is a non-forced apply run by a manager with a given object. Since non-forced apply operation can conflict, the user can specify the expected conflicts. If conflicts don't match, an error will occur.

type Apply struct {
    Manager    string
    APIVersion fieldpath.APIVersion
    Object     typed.YAMLObject
    Conflicts  merge.Conflicts
}

type ApplyObject

type ApplyObject struct {
    Manager    string
    APIVersion fieldpath.APIVersion
    Object     *typed.TypedValue
    Conflicts  merge.Conflicts
}

type ChangeParser

ChangeParser is a type of operation. It simulates making changes a schema without versioning the schema. This can be used to test the behavior of making backward compatible schema changes, e.g. setting "elementRelationship: atomic" on an existing struct. It also may be used to ensure that backward incompatible changes are detected appropriately.

type ChangeParser struct {
    Parser *typed.Parser
}

type ExtractApply

ExtractApply is a type of operation. It simulates extracting an object the state based on the manager you have applied with, merging the apply object with that extracted object and reapplying that.

type ExtractApply struct {
    Manager    string
    APIVersion fieldpath.APIVersion
    Object     typed.YAMLObject
}

type ExtractApplyObject

type ExtractApplyObject struct {
    Manager    string
    APIVersion fieldpath.APIVersion
    Object     *typed.TypedValue
}

type ForceApply

ForceApply is a type of operation. It is a forced-apply run by a manager with a given object. Any error will be returned.

type ForceApply struct {
    Manager    string
    APIVersion fieldpath.APIVersion
    Object     typed.YAMLObject
}

type ForceApplyObject

ForceApplyObject is a type of operation. It is a forced-apply run by a manager with a given object. Any error will be returned.

type ForceApplyObject struct {
    Manager    string
    APIVersion fieldpath.APIVersion
    Object     *typed.TypedValue
}

type Operation

Operation is a step that will run when building a table-driven test.

type Operation interface {
    // contains filtered or unexported methods
}

type Parser

For the sake of tests, a parser is something that can retrieve a ParseableType.

type Parser interface {
    Type(string) typed.ParseableType
}

type SameVersionParser

SameVersionParser can be used if all the versions are actually using the same type.

type SameVersionParser struct {
    T typed.ParseableType
}

func (SameVersionParser) Type

func (p SameVersionParser) Type(_ string) typed.ParseableType

type State

State of the current test in terms of live object. One can check at any time that Live and Managers match the expectations.

The parser will look for the type by using the APIVersion of the object it's trying to parse. If trying to parse a "v1" object, a corresponding "v1" type should exist in the schema. If all the versions should map to the same type, or to a DeducedParseableType, one can use the SameVersionParser or the DeducedParser types defined in this package.

type State struct {
    Live     *typed.TypedValue
    Parser   Parser
    Managers fieldpath.ManagedFields
    Updater  *merge.Updater
}

func (*State) Apply

func (s *State) Apply(obj typed.YAMLObject, version fieldpath.APIVersion, manager string, force bool) error

Apply the passed in object to the current state

func (*State) ApplyObject

func (s *State) ApplyObject(tv *typed.TypedValue, version fieldpath.APIVersion, manager string, force bool) error

func (*State) CompareLive

func (s *State) CompareLive(obj typed.YAMLObject, version fieldpath.APIVersion) (string, error)

CompareLive takes a YAML string and returns the comparison with the current live object or an error.

func (*State) Update

func (s *State) Update(obj typed.YAMLObject, version fieldpath.APIVersion, manager string) error

Update the current state with the passed in object

func (*State) UpdateObject

func (s *State) UpdateObject(tv *typed.TypedValue, version fieldpath.APIVersion, manager string) error

type TestCase

TestCase is the list of operations that need to be run, as well as the object/managedfields as they are supposed to look like after all the operations have been successfully performed. If Object/Managed is not specified, then the comparison is not performed (any object or managed field will pass). Any error (conflicts aside) happen while running the operation, that error will be returned right away.

type TestCase struct {
    // Ops is the list of operations to run sequentially
    Ops []Operation
    // Object, if not empty, is the object as it's expected to
    // be after all the operations are run.
    Object typed.YAMLObject
    // APIVersion should be set if the object is non-empty and
    // describes the version of the object to compare to.
    APIVersion fieldpath.APIVersion
    // Managed, if not nil, is the ManagedFields as expected
    // after all operations are run.
    Managed fieldpath.ManagedFields
    // ReportInputOnNoop if we don't want to compare the output and
    // always return it.
    ReturnInputOnNoop bool
    // IgnoredFields containing the set to ignore for every version
    IgnoredFields map[fieldpath.APIVersion]*fieldpath.Set
}

func (TestCase) Bench

func (tc TestCase) Bench(parser Parser) error

Bench runs the test-case using the given parser and a dummy converter, but doesn't check exit conditions--see the comment for BenchWithConverter.

func (TestCase) BenchWithConverter

func (tc TestCase) BenchWithConverter(parser Parser, converter merge.Converter) error

BenchWithConverter runs the test-case using the given parser and converter, but doesn't do any comparison operations aftewards; you should probably run TestWithConverter once and reset the benchmark, to make sure the test case actually passes..

func (TestCase) PreprocessOperations

func (tc TestCase) PreprocessOperations(parser Parser) error

Preprocess all the operations by parsing the yaml before-hand.

func (TestCase) Test

func (tc TestCase) Test(parser Parser) error

Test runs the test-case using the given parser and a dummy converter.

func (TestCase) TestWithConverter

func (tc TestCase) TestWithConverter(parser Parser, converter merge.Converter) error

TestWithConverter runs the test-case using the given parser and converter.

type Update

Update is a type of operation. It is a controller type of update. Errors are passed along.

type Update struct {
    Manager    string
    APIVersion fieldpath.APIVersion
    Object     typed.YAMLObject
}

type UpdateObject

UpdateObject is a type of operation. It is a controller type of update. Errors are passed along.

type UpdateObject struct {
    Manager    string
    APIVersion fieldpath.APIVersion
    Object     *typed.TypedValue
}