@@ -2,9 +2,12 @@ package events_test
22
33import  (
44	"context" 
5+ 	"errors" 
56
67	"github.com/nginxinc/nginx-gateway-kubernetes/internal/events" 
8+ 	"github.com/nginxinc/nginx-gateway-kubernetes/internal/state" 
79	"github.com/nginxinc/nginx-gateway-kubernetes/internal/state/statefakes" 
10+ 	"github.com/nginxinc/nginx-gateway-kubernetes/internal/status/statusfakes" 
811	. "github.com/onsi/ginkgo/v2" 
912	. "github.com/onsi/gomega" 
1013	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 
@@ -30,14 +33,16 @@ func (r *unsupportedResource) DeepCopyObject() runtime.Object {
3033var  _  =  Describe ("EventLoop" , func () {
3134	var  ctrl  * events.EventLoop 
3235	var  fakeConf  * statefakes.FakeConfiguration 
36+ 	var  fakeUpdater  * statusfakes.FakeUpdater 
3337	var  cancel  context.CancelFunc 
3438	var  eventCh  chan  interface {}
3539	var  errorCh  chan  error 
3640
3741	BeforeEach (func () {
3842		fakeConf  =  & statefakes.FakeConfiguration {}
3943		eventCh  =  make (chan  interface {})
40- 		ctrl  =  events .NewEventLoop (fakeConf , eventCh , zap .New ())
44+ 		fakeUpdater  =  & statusfakes.FakeUpdater {}
45+ 		ctrl  =  events .NewEventLoop (fakeConf , eventCh , fakeUpdater , zap .New ())
4146
4247		var  ctx  context.Context 
4348
@@ -59,6 +64,16 @@ var _ = Describe("EventLoop", func() {
5964		})
6065
6166		It ("should process upsert event" , func () {
67+ 			fakeStatusUpdates  :=  []state.StatusUpdate {
68+ 				{
69+ 					NamespacedName : types.NamespacedName {},
70+ 					Status :         nil ,
71+ 				},
72+ 			}
73+ 			// for now, we pass nil, because we don't need to test how EventLoop processes changes yet. We will start 
74+ 			// testing once we have NGINX Configuration Manager component. 
75+ 			fakeConf .UpsertHTTPRouteReturns (nil , fakeStatusUpdates )
76+ 
6277			hr  :=  & v1alpha2.HTTPRoute {}
6378
6479			eventCh  <-  & events.UpsertEvent {
@@ -69,9 +84,25 @@ var _ = Describe("EventLoop", func() {
6984			Eventually (func () * v1alpha2.HTTPRoute  {
7085				return  fakeConf .UpsertHTTPRouteArgsForCall (0 )
7186			}).Should (Equal (hr ))
87+ 
88+ 			Eventually (fakeUpdater .ProcessStatusUpdatesCallCount ()).Should (Equal (1 ))
89+ 			Eventually (func () []state.StatusUpdate  {
90+ 				_ , updates  :=  fakeUpdater .ProcessStatusUpdatesArgsForCall (0 )
91+ 				return  updates 
92+ 			}).Should (Equal (fakeStatusUpdates ))
7293		})
7394
7495		It ("should process delete event" , func () {
96+ 			fakeStatusUpdates  :=  []state.StatusUpdate {
97+ 				{
98+ 					NamespacedName : types.NamespacedName {},
99+ 					Status :         nil ,
100+ 				},
101+ 			}
102+ 			// for now, we pass nil, because we don't need to test how EventLoop processes changes yet. We will start 
103+ 			// testing once we have NGINX Configuration Manager component. 
104+ 			fakeConf .DeleteHTTPRouteReturns (nil , fakeStatusUpdates )
105+ 
75106			nsname  :=  types.NamespacedName {Namespace : "test" , Name : "route" }
76107
77108			eventCh  <-  & events.DeleteEvent {
@@ -83,6 +114,12 @@ var _ = Describe("EventLoop", func() {
83114			Eventually (func () types.NamespacedName  {
84115				return  fakeConf .DeleteHTTPRouteArgsForCall (0 )
85116			}).Should (Equal (nsname ))
117+ 
118+ 			Eventually (fakeUpdater .ProcessStatusUpdatesCallCount ()).Should (Equal (1 ))
119+ 			Eventually (func () []state.StatusUpdate  {
120+ 				_ , updates  :=  fakeUpdater .ProcessStatusUpdatesArgsForCall (0 )
121+ 				return  updates 
122+ 			}).Should (Equal (fakeStatusUpdates ))
86123		})
87124	})
88125
@@ -110,5 +147,18 @@ var _ = Describe("EventLoop", func() {
110147					Type : & unsupportedResource {},
111148				}),
112149		)
150+ 
151+ 		It ("should return error if status updater returns error" , func () {
152+ 			testError  :=  errors .New ("test" )
153+ 			fakeUpdater .ProcessStatusUpdatesReturns (testError )
154+ 
155+ 			eventCh  <-  & events.UpsertEvent {
156+ 				Resource : & v1alpha2.HTTPRoute {},
157+ 			}
158+ 
159+ 			var  err  error 
160+ 			Eventually (errorCh ).Should (Receive (& err ))
161+ 			Expect (err ).Should (Equal (testError ))
162+ 		})
113163	})
114164})
0 commit comments