@@ -177,12 +177,6 @@ func TestScanning(t *testing.T) {
177177 // should be only a single vulnerability
178178 assert .Nil (t , err )
179179 assert .Len (t , vulns , 1 )
180- // mark the vuln as accepted
181- vulns [0 ].State = models .VulnStateAccepted
182- // save it
183- err = dependencyVulnRepository .Save (nil , & vulns [0 ])
184- assert .Nil (t , err )
185-
186180 // create an accepted event inside the database
187181 acceptedEvent := models .NewAcceptedEvent (vulns [0 ].ID , vulns [0 ].GetType (), "abc" , "accepting the vulnerability" )
188182 err = dependencyVulnRepository .ApplyAndSave (nil , & vulns [0 ], & acceptedEvent )
@@ -219,12 +213,27 @@ func TestScanning(t *testing.T) {
219213 newVuln = v
220214 }
221215 }
216+
222217 assert .NotEmpty (t , newVuln .Events )
223218 lastTwoEvents := newVuln .Events [len (newVuln .Events )- 2 :]
224- assert .Equal (t , models .EventTypeAccepted , lastTwoEvents [0 ].Type )
225- assert .Equal (t , "accepting the vulnerability" , * lastTwoEvents [0 ].Justification )
226- assert .Equal (t , "main" , * lastTwoEvents [0 ].OriginalAssetVersionName )
227- assert .Equal (t , models .EventTypeDetectedOnAnotherBranch , lastTwoEvents [1 ].Type )
219+
220+ // we can not really rely on the created_at since the events are created in the same second
221+ // nevertheless - one has to be the accepted event and the other the detected on different branch event
222+ var accEvent models.VulnEvent
223+ var detectedOnAnotherBranchEvent models.VulnEvent
224+ for _ , ev := range lastTwoEvents {
225+ if ev .Type == models .EventTypeAccepted {
226+ accEvent = ev
227+ } else {
228+ detectedOnAnotherBranchEvent = ev
229+ }
230+ }
231+
232+ assert .NotEmpty (t , accEvent )
233+ assert .NotEmpty (t , detectedOnAnotherBranchEvent )
234+ assert .Equal (t , models .EventTypeAccepted , accEvent .Type )
235+ assert .Equal (t , "accepting the vulnerability" , * accEvent .Justification )
236+ assert .Equal (t , "main" , * accEvent .OriginalAssetVersionName )
228237 })
229238}
230239
0 commit comments