From c476b49dcfc420f1f2822f40ad82ef925f3f35cd Mon Sep 17 00:00:00 2001 From: Jordan Liggitt Date: Fri, 9 Oct 2020 17:50:52 -0400 Subject: [PATCH] Add GC unit tests Adds unit tests covering the problematic scenarios identified around conflicting data in child owner references Before After package level 51% 68% garbagecollector.go 60% 75% graph_builder.go 50% 81% graph.go 50% 68% Added/improved coverage of key functions that had lacking unit test coverage: * attemptToDeleteWorker * attemptToDeleteItem * processGraphChanges (added coverage of all added code) Kubernetes-commit: e491c3bc7056530d82590d95f0af0e8c4d8dded5 --- tools/record/fake.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tools/record/fake.go b/tools/record/fake.go index 2ff444ea..0b3f344a 100644 --- a/tools/record/fake.go +++ b/tools/record/fake.go @@ -27,17 +27,29 @@ import ( // thrown away in this case. type FakeRecorder struct { Events chan string + + IncludeObject bool +} + +func objectString(object runtime.Object, includeObject bool) string { + if !includeObject { + return "" + } + return fmt.Sprintf(" involvedObject{kind=%s,apiVersion=%s}", + object.GetObjectKind().GroupVersionKind().Kind, + object.GetObjectKind().GroupVersionKind().GroupVersion(), + ) } func (f *FakeRecorder) Event(object runtime.Object, eventtype, reason, message string) { if f.Events != nil { - f.Events <- fmt.Sprintf("%s %s %s", eventtype, reason, message) + f.Events <- fmt.Sprintf("%s %s %s%s", eventtype, reason, message, objectString(object, f.IncludeObject)) } } func (f *FakeRecorder) Eventf(object runtime.Object, eventtype, reason, messageFmt string, args ...interface{}) { if f.Events != nil { - f.Events <- fmt.Sprintf(eventtype+" "+reason+" "+messageFmt, args...) + f.Events <- fmt.Sprintf(eventtype+" "+reason+" "+messageFmt, args...) + objectString(object, f.IncludeObject) } }