Move ObjectDiff into util

This commit is contained in:
Clayton Coleman
2014-10-09 17:23:43 -04:00
parent 996c0e44d6
commit 935e97d59d
5 changed files with 71 additions and 52 deletions

View File

@@ -17,12 +17,10 @@ limitations under the License.
package runtime
import (
"encoding/json"
"fmt"
"reflect"
"github.com/GoogleCloudPlatform/kubernetes/pkg/conversion"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"gopkg.in/v1/yaml"
)
@@ -368,32 +366,6 @@ func (s *Scheme) CopyOrDie(obj Object) Object {
return newObj
}
// ObjectDiff writes the two objects out as JSON and prints out the identical part of
// the objects followed by the remaining part of 'a' and finally the remaining part of 'b'.
// For debugging tests.
func ObjectDiff(a, b Object) string {
ab, err := json.Marshal(a)
if err != nil {
panic(fmt.Sprintf("a: %v", err))
}
bb, err := json.Marshal(b)
if err != nil {
panic(fmt.Sprintf("b: %v", err))
}
return util.StringDiff(string(ab), string(bb))
}
// ObjectGoPrintDiff is like ObjectDiff, but uses go's %#v formatter to print the
// objects, in case json isn't showing you the difference. (reflect.DeepEqual makes
// a distinction between nil and empty slices, for example, even though nothing else
// really does.)
func ObjectGoPrintDiff(a, b Object) string {
return util.StringDiff(
fmt.Sprintf("%#v", a),
fmt.Sprintf("%#v", b),
)
}
// metaInsertion implements conversion.MetaInsertionFactory, which lets the conversion
// package figure out how to encode our object's types and versions. These fields are
// located in our TypeMeta.