mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-08 04:32:37 +00:00
Fix error messages; add tests
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user