From 3bada55aab374d14436636b9f2aafc1108f5c81a Mon Sep 17 00:00:00 2001 From: Matt Moore Date: Fri, 21 Feb 2020 10:02:07 -0800 Subject: [PATCH] Drops the Serving-specific stats reporter logic from knative/pkg (#1114) --- reconciler/testing/stats.go | 40 ------------------------------------- reconciler/testing/table.go | 17 ++++------------ webhook/testing/factory.go | 5 ++--- 3 files changed, 6 insertions(+), 56 deletions(-) delete mode 100644 reconciler/testing/stats.go diff --git a/reconciler/testing/stats.go b/reconciler/testing/stats.go deleted file mode 100644 index 1d389a15d..000000000 --- a/reconciler/testing/stats.go +++ /dev/null @@ -1,40 +0,0 @@ -/* -Copyright 2019 The Knative Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package testing - -import ( - "fmt" - "time" -) - -// FakeStatsReporter is a fake implementation of StatsReporter -type FakeStatsReporter struct { - servicesReady map[string]int -} - -func (r *FakeStatsReporter) ReportServiceReady(namespace, service string, d time.Duration) error { - key := fmt.Sprintf("%s/%s", namespace, service) - if r.servicesReady == nil { - r.servicesReady = make(map[string]int) - } - r.servicesReady[key]++ - return nil -} - -func (r *FakeStatsReporter) GetServiceReadyStats() map[string]int { - return r.servicesReady -} diff --git a/reconciler/testing/table.go b/reconciler/testing/table.go index 61438fa64..38a891f26 100644 --- a/reconciler/testing/table.go +++ b/reconciler/testing/table.go @@ -79,9 +79,6 @@ type TableRow struct { // WantEvents holds the ordered list of events we expect during reconciliation. WantEvents []string - // WantServiceReadyStats holds the ServiceReady stats we expect during reconciliation. - WantServiceReadyStats map[string]int - // WithReactors is a set of functions that are installed as Reactors for the execution // of this row of the table-driven-test. WithReactors []clientgotesting.ReactionFunc @@ -123,15 +120,14 @@ func objKey(o runtime.Object) string { return path.Join(typeOf, on.GetNamespace(), on.GetName()) } -// Factory returns a Reconciler.Interface to perform reconciliation in table test, -// ActionRecorderList/EventList to capture k8s actions/events produced during reconciliation -// and FakeStatsReporter to capture stats. -type Factory func(*testing.T, *TableRow) (controller.Reconciler, ActionRecorderList, EventList, *FakeStatsReporter) +// Factory returns a Reconciler.Interface to perform reconciliation in table test, and +// ActionRecorderList/EventList to capture k8s actions/events produced during reconciliation. +type Factory func(*testing.T, *TableRow) (controller.Reconciler, ActionRecorderList, EventList) // Test executes the single table test. func (r *TableRow) Test(t *testing.T, factory Factory) { t.Helper() - c, recorderList, eventList, statsReporter := factory(t, r) + c, recorderList, eventList := factory(t, r) // Set the Reconciler for PostConditions to access it post-Reconcile() r.Reconciler = c @@ -355,11 +351,6 @@ func (r *TableRow) Test(t *testing.T, factory Factory) { } } - gotStats := statsReporter.GetServiceReadyStats() - if diff := cmp.Diff(r.WantServiceReadyStats, gotStats); diff != "" { - t.Errorf("Unexpected service ready stats (-want, +got): %s", diff) - } - for _, verify := range r.PostConditions { verify(t, r) } diff --git a/webhook/testing/factory.go b/webhook/testing/factory.go index 800a8cec0..26d35db35 100644 --- a/webhook/testing/factory.go +++ b/webhook/testing/factory.go @@ -51,7 +51,7 @@ type Ctor func(context.Context, *Listers, configmap.Watcher) controller.Reconcil // MakeFactory creates a reconciler factory with fake clients and controller created by `ctor`. func MakeFactory(ctor Ctor) rtesting.Factory { return func(t *testing.T, r *rtesting.TableRow) ( - controller.Reconciler, rtesting.ActionRecorderList, rtesting.EventList, *rtesting.FakeStatsReporter) { + controller.Reconciler, rtesting.ActionRecorderList, rtesting.EventList) { ls := NewListers(r.Objects) ctx := r.Ctx @@ -76,7 +76,6 @@ func MakeFactory(ctor Ctor) rtesting.Factory { eventRecorder := record.NewFakeRecorder(maxEventBufferSize) ctx = controller.WithEventRecorder(ctx, eventRecorder) - statsReporter := &rtesting.FakeStatsReporter{} // This is needed for the tests that use generated names and // the object cannot be created beforehand. @@ -109,7 +108,7 @@ func MakeFactory(ctor Ctor) rtesting.Factory { actionRecorderList := rtesting.ActionRecorderList{dynamicClient, kubeClient, apixClient} eventList := rtesting.EventList{Recorder: eventRecorder} - return c, actionRecorderList, eventList, statsReporter + return c, actionRecorderList, eventList } }