Make semantic deep equal public feature

* Use semantic deep equal when validating
* More test cases for deep equal
This commit is contained in:
Daniel Smith
2015-01-05 13:38:39 -08:00
parent 7f49ba0dcf
commit 0d628b3bff
4 changed files with 45 additions and 16 deletions

View File

@@ -18,6 +18,28 @@ package api
import (
"strings"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
"github.com/GoogleCloudPlatform/kubernetes/pkg/conversion"
)
// 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 equivilent to 0 quantities.
if a.Amount == nil && b.MilliValue() == 0 {
return true
}
if b.Amount == nil && a.MilliValue() == 0 {
return true
}
return a.Amount.Cmp(b.Amount) == 0
},
)
// TODO: Address these per #1502