// metadataEqual checks that the metadata of two images is directly equivalent. func metadataEqual(a, b *docker.Config) bool { // compare output metadata a.Image, b.Image = "", "" e1, e2 := envMap(a.Env), envMap(b.Env) if !conversion.EqualitiesOrDie().DeepEqual(e1, e2) { return false } a.Env, b.Env = nil, nil if !conversion.EqualitiesOrDie().DeepEqual(a, b) { return false } return true }
// Semantic can do semantic deep equality checks for api objects. // Example: api.Semantic.DeepEqual(aPod, aPodWithNonNilButEmptyMaps) == true var Semantic = conversion.EqualitiesOrDie( func(a, b resource.Quantity) bool { // Ignore formatting, only care that numeric value stayed the same. // TODO: if we decide it's important, after we drop v1beta1/2, we // could start comparing format. // // Uninitialized quantities are equivalent to 0 quantities. if a.Amount == nil && b.MilliValue() == 0 { return true } if b.Amount == nil && a.MilliValue() == 0 { return true } if a.Amount == nil || b.Amount == nil { return false } return a.Amount.Cmp(b.Amount) == 0 }, func(a, b unversioned.Time) bool { return a.UTC() == b.UTC() }, func(a, b labels.Selector) bool { return a.String() == b.String() }, func(a, b fields.Selector) bool { return a.String() == b.String() }, ) var standardResources = sets.NewString(
} return diff.StringDiff(string(ab), string(bb)) // An alternate diff attempt, in case json isn't showing you // the difference. (reflect.DeepEqual makes a distinction between // nil and empty slices, for example.) //return diff.StringDiff( // fmt.Sprintf("%#v", a), // fmt.Sprintf("%#v", b), //) } var semantic = conversion.EqualitiesOrDie( func(a, b MyWeirdCustomEmbeddedVersionKindField) bool { a.APIVersion, a.ObjectKind = "", "" b.APIVersion, b.ObjectKind = "", "" return a == b }, ) func runTest(t *testing.T, source interface{}) { name := reflect.TypeOf(source).Elem().Name() TestObjectFuzzer.Fuzz(source) _, codec := GetTestScheme() data, err := runtime.Encode(codec, source.(runtime.Object)) if err != nil { t.Errorf("%v: %v (%#v)", name, err, source) return } obj2, err := runtime.Decode(codec, data)
"Conversion error: %s. (in: %v(%+v) out: %v)", c.Message, reflect.TypeOf(c.In), c.In, reflect.TypeOf(c.Out), ) } // Semantic can do semantic deep equality checks for api objects. // Example: api.Semantic.DeepEqual(aPod, aPodWithNonNilButEmptyMaps) == true var Semantic = conversion.EqualitiesOrDie( func(a, b resource.Quantity) bool { // Ignore formatting, only care that numeric value stayed the same. // TODO: if we decide it's important, it should be safe to start comparing the format. // // Uninitialized quantities are equivalent to 0 quantities. return a.Cmp(b) == 0 }, func(a, b unversioned.Time) bool { return a.UTC() == b.UTC() }, func(a, b labels.Selector) bool { return a.String() == b.String() }, func(a, b fields.Selector) bool { return a.String() == b.String() }, ) var standardResourceQuotaScopes = sets.NewString( string(ResourceQuotaScopeTerminating), string(ResourceQuotaScopeNotTerminating), string(ResourceQuotaScopeBestEffort), string(ResourceQuotaScopeNotBestEffort), )