Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Log method on Scheme for better debugging #1591

Merged
merged 1 commit into from
Oct 6, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions pkg/api/serialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,20 @@ func runTest(t *testing.T, codec runtime.Codec, source runtime.Object) {
}
}

// For debugging problems
func TestSpecificKind(t *testing.T) {
api.Scheme.Log(t)
kind := "PodList"
item, err := api.Scheme.New("", kind)
if err != nil {
t.Errorf("Couldn't make a %v? %v", kind, err)
return
}
runTest(t, v1beta1.Codec, item)
runTest(t, v1beta2.Codec, item)
api.Scheme.Log(nil)
}

func TestTypes(t *testing.T) {
for kind := range api.Scheme.KnownTypes("") {
// Try a few times, since runTest uses random values.
Expand Down
5 changes: 5 additions & 0 deletions pkg/conversion/scheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ func NewScheme() *Scheme {
return s
}

// Log sets a logger on the scheme. For test purposes only
func (s *Scheme) Log(l DebugLogger) {
s.converter.Debug = l
}

// nameFunc returns the name of the type that we wish to use for encoding. Defaults to
// the go name of the type if the type is not registered.
func (s *Scheme) nameFunc(t reflect.Type) string {
Expand Down
5 changes: 5 additions & 0 deletions pkg/runtime/scheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@ func (s *Scheme) New(versionName, typeName string) (Object, error) {
return obj.(Object), nil
}

// Log sets a logger on the scheme. For test purposes only
func (s *Scheme) Log(l conversion.DebugLogger) {
s.raw.Log(l)
}

// AddConversionFuncs adds a function to the list of conversion functions. The given
// function should know how to convert between two API objects. We deduce how to call
// it from the types of its two parameters; see the comment for Converter.Register.
Expand Down