@@ -28,14 +28,17 @@ func TestInstanceWatcherService_checkForUpdates(t *testing.T) {
2828 nginxConfigContext := testModel .ConfigContext ()
2929
3030 fakeProcessWatcher := & processfakes.FakeProcessOperatorInterface {}
31- fakeProcessWatcher .ProcessesReturns (nil , nil , nil )
31+ fakeProcessWatcher .ProcessesReturns (nil , nil )
3232
3333 fakeProcessParser := & instancefakes.FakeProcessParser {}
3434 fakeProcessParser .ParseReturns (map [string ]* mpi.Instance {
3535 protos .NginxOssInstance ([]string {}).GetInstanceMeta ().GetInstanceId (): protos .
3636 NginxOssInstance ([]string {}),
3737 })
3838
39+ fakeNginxAppProtectInstanceFinder := & instancefakes.FakeInstanceFinder {}
40+ fakeNginxAppProtectInstanceFinder .FindReturns (protos .NginxAppProtectInstance ())
41+
3942 fakeNginxConfigParser := & instancefakes.FakeNginxConfigParser {}
4043 fakeNginxConfigParser .ParseReturns (nginxConfigContext , nil )
4144 instanceUpdatesChannel := make (chan InstanceUpdatesMessage , 1 )
@@ -44,15 +47,15 @@ func TestInstanceWatcherService_checkForUpdates(t *testing.T) {
4447 instanceWatcherService := NewInstanceWatcherService (types .AgentConfig ())
4548 instanceWatcherService .processOperator = fakeProcessWatcher
4649 instanceWatcherService .nginxParser = fakeProcessParser
47- instanceWatcherService .nginxAppProtectProcessParser = fakeProcessParser
50+ instanceWatcherService .nginxAppProtectInstanceFinder = fakeNginxAppProtectInstanceFinder
4851 instanceWatcherService .nginxConfigParser = fakeNginxConfigParser
4952 instanceWatcherService .instancesChannel = instanceUpdatesChannel
5053 instanceWatcherService .nginxConfigContextChannel = nginxConfigContextChannel
5154
5255 instanceWatcherService .checkForUpdates (ctx )
5356
5457 instanceUpdatesMessage := <- instanceUpdatesChannel
55- assert .Len (t , instanceUpdatesMessage .InstanceUpdates .NewInstances , 2 )
58+ assert .Len (t , instanceUpdatesMessage .InstanceUpdates .NewInstances , 3 )
5659 assert .Empty (t , instanceUpdatesMessage .InstanceUpdates .DeletedInstances )
5760
5861 nginxConfigContextMessage := <- nginxConfigContextChannel
@@ -67,6 +70,7 @@ func TestInstanceWatcherService_instanceUpdates(t *testing.T) {
6770 nginxInstance := protos .NginxOssInstance ([]string {})
6871 nginxInstanceWithDifferentPID := protos .NginxOssInstance ([]string {})
6972 nginxInstanceWithDifferentPID .GetInstanceRuntime ().ProcessId = 3526
73+ napInstance := protos .NginxAppProtectInstance ()
7074
7175 tests := []struct {
7276 name string
@@ -78,6 +82,7 @@ func TestInstanceWatcherService_instanceUpdates(t *testing.T) {
7882 name : "Test 1: No updates" ,
7983 oldInstances : map [string ]* mpi.Instance {
8084 agentInstance .GetInstanceMeta ().GetInstanceId (): agentInstance ,
85+ napInstance .GetInstanceMeta ().GetInstanceId (): napInstance ,
8186 },
8287 parsedInstances : make (map [string ]* mpi.Instance ),
8388 expectedInstanceUpdates : InstanceUpdates {},
@@ -94,6 +99,7 @@ func TestInstanceWatcherService_instanceUpdates(t *testing.T) {
9499 expectedInstanceUpdates : InstanceUpdates {
95100 NewInstances : []* mpi.Instance {
96101 nginxInstance ,
102+ napInstance ,
97103 },
98104 },
99105 },
@@ -102,6 +108,7 @@ func TestInstanceWatcherService_instanceUpdates(t *testing.T) {
102108 oldInstances : map [string ]* mpi.Instance {
103109 agentInstance .GetInstanceMeta ().GetInstanceId (): agentInstance ,
104110 nginxInstanceWithDifferentPID .GetInstanceMeta ().GetInstanceId (): nginxInstanceWithDifferentPID ,
111+ napInstance .GetInstanceMeta ().GetInstanceId (): napInstance ,
105112 },
106113 parsedInstances : map [string ]* mpi.Instance {
107114 agentInstance .GetInstanceMeta ().GetInstanceId (): agentInstance ,
@@ -119,6 +126,7 @@ func TestInstanceWatcherService_instanceUpdates(t *testing.T) {
119126 agentInstance .GetInstanceMeta ().GetInstanceId (): agentInstance ,
120127 protos .NginxOssInstance ([]string {}).GetInstanceMeta ().
121128 GetInstanceId (): protos .NginxOssInstance ([]string {}),
129+ napInstance .GetInstanceMeta ().GetInstanceId (): napInstance ,
122130 },
123131 parsedInstances : make (map [string ]* mpi.Instance ),
124132 expectedInstanceUpdates : InstanceUpdates {
@@ -132,7 +140,7 @@ func TestInstanceWatcherService_instanceUpdates(t *testing.T) {
132140 for _ , test := range tests {
133141 t .Run (test .name , func (tt * testing.T ) {
134142 fakeProcessWatcher := & processfakes.FakeProcessOperatorInterface {}
135- fakeProcessWatcher .ProcessesReturns (nil , nil , nil )
143+ fakeProcessWatcher .ProcessesReturns (nil , nil )
136144
137145 fakeProcessParser := & instancefakes.FakeProcessParser {}
138146 fakeProcessParser .ParseReturns (test .parsedInstances )
@@ -141,10 +149,13 @@ func TestInstanceWatcherService_instanceUpdates(t *testing.T) {
141149 fakeExec .ExecutableReturns (defaultAgentPath , nil )
142150 fakeExec .ProcessIDReturns (processID )
143151
152+ fakeNginxAppProtectInstanceFinder := & instancefakes.FakeInstanceFinder {}
153+ fakeNginxAppProtectInstanceFinder .FindReturns (napInstance )
154+
144155 instanceWatcherService := NewInstanceWatcherService (types .AgentConfig ())
145156 instanceWatcherService .processOperator = fakeProcessWatcher
146157 instanceWatcherService .nginxParser = fakeProcessParser
147- instanceWatcherService .nginxAppProtectProcessParser = fakeProcessParser
158+ instanceWatcherService .nginxAppProtectInstanceFinder = fakeNginxAppProtectInstanceFinder
148159 instanceWatcherService .instanceCache = test .oldInstances
149160 instanceWatcherService .executer = fakeExec
150161
0 commit comments