Documentation ¶
Overview ¶
Package kmp wraps github.com/google/go-cmp with custom Comparers for frequently used kubernetes resources that have unexported fields.
Index ¶
- func CompareSetFields(x, y interface{}, opts ...cmp.Option) ([]string, error)
- func SafeDiff(x, y interface{}, opts ...cmp.Option) (diff string, err error)
- func SafeEqual(x, y interface{}, opts ...cmp.Option) (equal bool, err error)
- func ShortDiff(prev, cur interface{}, opts ...cmp.Option) (string, error)
- type FieldListReporter
- type ShortDiffReporter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompareSetFields ¶
CompareSetFields returns a list of field names that differ between x and y. Uses SafeEqual for comparison.
func SafeDiff ¶
SafeDiff wraps cmp.Diff but recovers from panics and uses custom Comparers for: * k8s.io/apimachinery/pkg/api/resource.Quantity SafeDiff should be used instead of cmp.Diff in non-test code to protect the running process from crashing.
Types ¶
type FieldListReporter ¶
type FieldListReporter struct {
// contains filtered or unexported fields
}
FieldListReporter implements the cmp.Reporter interface. It keeps track of the field names that differ between two structs and reports them through the Fields() function.
func (*FieldListReporter) Fields ¶
func (r *FieldListReporter) Fields() []string
Fields returns the field names that differed between the two objects after calling cmp.Equal with the FieldListReporter. Field names are returned in alphabetical order.
func (*FieldListReporter) PopStep ¶
func (r *FieldListReporter) PopStep()
PopStep implements cmp.Reporter.
func (*FieldListReporter) PushStep ¶
func (r *FieldListReporter) PushStep(ps cmp.PathStep)
PushStep implements the cmp.Reporter.
func (*FieldListReporter) Report ¶
func (r *FieldListReporter) Report(rs cmp.Result)
Report implements the cmp.Reporter.
type ShortDiffReporter ¶
type ShortDiffReporter struct {
// contains filtered or unexported fields
}
ShortDiffReporter implements the cmp.Reporter interface. It reports on fields which have diffing values in a short zero-context, unified diff format.
func (*ShortDiffReporter) Diff ¶
func (r *ShortDiffReporter) Diff() (string, error)
Diff returns the generated short diff for this object. cmp.Equal should be called before this method.
func (*ShortDiffReporter) PopStep ¶
func (r *ShortDiffReporter) PopStep()
PopStep implements the cmp.Reporter.
func (*ShortDiffReporter) PushStep ¶
func (r *ShortDiffReporter) PushStep(ps cmp.PathStep)
PushStep implements the cmp.Reporter.
func (*ShortDiffReporter) Report ¶
func (r *ShortDiffReporter) Report(rs cmp.Result)
Report implements the cmp.Reporter.