diff --git a/internal/framework/events/first_eventbatch_preparer.go b/internal/framework/events/first_eventbatch_preparer.go index b8bd48c470..155f120b32 100644 --- a/internal/framework/events/first_eventbatch_preparer.go +++ b/internal/framework/events/first_eventbatch_preparer.go @@ -9,6 +9,8 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" + + "github.com/nginx/nginx-gateway-fabric/internal/framework/kubernetes" ) //counterfeiter:generate . FirstEventBatchPreparer @@ -20,22 +22,13 @@ type FirstEventBatchPreparer interface { Prepare(ctx context.Context) (EventBatch, error) } -//counterfeiter:generate . Reader - -// Reader allows getting and listing resources from a cache. -// This interface is introduced for testing to mock the methods from -// sigs.k8s.io/controller-runtime/pkg/client.Reader. -type Reader interface { - client.Reader -} - // EachListItemFunc lists each item of a client.ObjectList. // It is from k8s.io/apimachinery/pkg/api/meta. type EachListItemFunc func(obj runtime.Object, fn func(runtime.Object) error) error // FirstEventBatchPreparerImpl is an implementation of FirstEventBatchPreparer. type FirstEventBatchPreparerImpl struct { - reader Reader + reader kubernetes.Reader eachListItem EachListItemFunc objects []client.Object objectLists []client.ObjectList @@ -48,7 +41,7 @@ type FirstEventBatchPreparerImpl struct { // For each list from objectLists, FirstEventBatchPreparerImpl will list the resources of the corresponding type from // the reader. func NewFirstEventBatchPreparerImpl( - reader Reader, + reader kubernetes.Reader, objects []client.Object, objectLists []client.ObjectList, ) *FirstEventBatchPreparerImpl { diff --git a/internal/framework/events/first_eventbatch_preparer_test.go b/internal/framework/events/first_eventbatch_preparer_test.go index 175818f62f..8828974cfd 100644 --- a/internal/framework/events/first_eventbatch_preparer_test.go +++ b/internal/framework/events/first_eventbatch_preparer_test.go @@ -17,19 +17,19 @@ import ( v1 "sigs.k8s.io/gateway-api/apis/v1" "github.com/nginx/nginx-gateway-fabric/internal/framework/events" - "github.com/nginx/nginx-gateway-fabric/internal/framework/events/eventsfakes" + "github.com/nginx/nginx-gateway-fabric/internal/framework/kubernetes/kubernetesfakes" ) var _ = Describe("FirstEventBatchPreparer", func() { var ( - fakeReader *eventsfakes.FakeReader + fakeReader *kubernetesfakes.FakeReader preparer *events.FirstEventBatchPreparerImpl ) const gcName = "my-class" BeforeEach(func() { - fakeReader = &eventsfakes.FakeReader{} + fakeReader = &kubernetesfakes.FakeReader{} preparer = events.NewFirstEventBatchPreparerImpl( fakeReader, []client.Object{&v1.GatewayClass{ObjectMeta: metav1.ObjectMeta{Name: gcName}}}, diff --git a/internal/framework/kubernetes/client.go b/internal/framework/kubernetes/client.go new file mode 100644 index 0000000000..e10df946aa --- /dev/null +++ b/internal/framework/kubernetes/client.go @@ -0,0 +1,14 @@ +package kubernetes + +import "sigs.k8s.io/controller-runtime/pkg/client" + +//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate + +//counterfeiter:generate . Reader + +// Reader allows getting and listing resources from a cache. +// This interface is introduced for testing to mock the methods from +// sigs.k8s.io/controller-runtime/pkg/client.Reader. +type Reader interface { + client.Reader +} diff --git a/internal/framework/events/eventsfakes/fake_reader.go b/internal/framework/kubernetes/kubernetesfakes/fake_reader.go similarity index 97% rename from internal/framework/events/eventsfakes/fake_reader.go rename to internal/framework/kubernetes/kubernetesfakes/fake_reader.go index 48f1bec2ea..997bb91a19 100644 --- a/internal/framework/events/eventsfakes/fake_reader.go +++ b/internal/framework/kubernetes/kubernetesfakes/fake_reader.go @@ -1,11 +1,11 @@ // Code generated by counterfeiter. DO NOT EDIT. -package eventsfakes +package kubernetesfakes import ( "context" "sync" - "github.com/nginx/nginx-gateway-fabric/internal/framework/events" + "github.com/nginx/nginx-gateway-fabric/internal/framework/kubernetes" "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -194,4 +194,4 @@ func (fake *FakeReader) recordInvocation(key string, args []interface{}) { fake.invocations[key] = append(fake.invocations[key], args) } -var _ events.Reader = new(FakeReader) +var _ kubernetes.Reader = new(FakeReader) diff --git a/internal/mode/static/telemetry/collector_test.go b/internal/mode/static/telemetry/collector_test.go index 506bfa0c9e..24f6e4e973 100644 --- a/internal/mode/static/telemetry/collector_test.go +++ b/internal/mode/static/telemetry/collector_test.go @@ -18,8 +18,8 @@ import ( gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" ngfAPI "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1" - "github.com/nginx/nginx-gateway-fabric/internal/framework/events/eventsfakes" "github.com/nginx/nginx-gateway-fabric/internal/framework/kinds" + "github.com/nginx/nginx-gateway-fabric/internal/framework/kubernetes/kubernetesfakes" "github.com/nginx/nginx-gateway-fabric/internal/mode/static/config" "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/dataplane" "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/graph" @@ -73,7 +73,7 @@ func createGetCallsFunc(objects ...client.Object) getCallsFunc { var _ = Describe("Collector", Ordered, func() { var ( - k8sClientReader *eventsfakes.FakeReader + k8sClientReader *kubernetesfakes.FakeReader fakeGraphGetter *telemetryfakes.FakeGraphGetter fakeConfigurationGetter *telemetryfakes.FakeConfigurationGetter dataCollector telemetry.DataCollector @@ -178,7 +178,7 @@ var _ = Describe("Collector", Ordered, func() { SnippetsFiltersDirectivesCount: []int64{}, } - k8sClientReader = &eventsfakes.FakeReader{} + k8sClientReader = &kubernetesfakes.FakeReader{} fakeGraphGetter = &telemetryfakes.FakeGraphGetter{} fakeConfigurationGetter = &telemetryfakes.FakeConfigurationGetter{}