Fix error messages; add tests

This commit is contained in:
Daniel Smith
2015-01-08 17:34:53 -08:00
parent 7bf9723d0a
commit bd7b457d9c
4 changed files with 130 additions and 10 deletions

View File

@@ -17,12 +17,29 @@ limitations under the License.
package api
import (
"reflect"
"strings"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
"github.com/GoogleCloudPlatform/kubernetes/pkg/conversion"
"github.com/davecgh/go-spew/spew"
)
// Conversion error conveniently packages up errors in conversions.
type ConversionError struct {
In, Out interface{}
Message string
}
// Return a helpful string about the error
func (c *ConversionError) Error() string {
return spew.Sprintf(
"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(
@@ -38,8 +55,12 @@ var Semantic = conversion.EqualitiesOrDie(
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
},
pullPoliciesEqual,
)
// TODO: Address these per #1502