@@ -331,3 +331,59 @@ func TestProcessNoteEventPlanFailedMultipleWorkspaces(t *testing.T) {
331331 t .Fatal ("expected a project name to be returned" )
332332 }
333333}
334+
335+ func TestProcessNoteEventNoErrorNoRuns (t * testing.T ) {
336+ os .Setenv (allow_list .GitlabProjectAllowListEnv , "zapier/" )
337+ defer os .Unsetenv (allow_list .GitlabProjectAllowListEnv )
338+ mockCtrl := gomock .NewController (t )
339+ defer mockCtrl .Finish ()
340+ mockGitClient := mocks .NewMockGitClient (mockCtrl )
341+
342+ mockApiClient := mocks .NewMockApiClient (mockCtrl )
343+ mockStreamClient := mocks .NewMockStreamClient (mockCtrl )
344+ mockProject := mocks .NewMockProject (mockCtrl )
345+ mockProject .EXPECT ().GetPathWithNamespace ().Return ("zapier/service-tf-buddy" )
346+
347+ mockLastCommit := mocks .NewMockCommit (mockCtrl )
348+ mockLastCommit .EXPECT ().GetSHA ().Return ("abvc12345" )
349+
350+ mockAttributes := mocks .NewMockMRAttributes (mockCtrl )
351+
352+ mockAttributes .EXPECT ().GetNote ().Return ("tfc plan -w service-tf-buddy" )
353+ mockAttributes .EXPECT ().GetType ().Return ("SomeNote" )
354+
355+ mockMREvent := mocks .NewMockMRCommentEvent (mockCtrl )
356+ mockMREvent .EXPECT ().GetProject ().Return (mockProject )
357+ mockMREvent .EXPECT ().GetAttributes ().Return (mockAttributes ).Times (2 )
358+ mockMREvent .EXPECT ().GetLastCommit ().Return (mockLastCommit )
359+
360+ mockSimpleMR := mocks .NewMockMR (mockCtrl )
361+ mockSimpleMR .EXPECT ().GetSourceBranch ().Return ("DTA-2009" )
362+
363+ mockSimpleMR .EXPECT ().GetInternalID ().Return (101 )
364+ mockMREvent .EXPECT ().GetMR ().Return (mockSimpleMR ).Times (2 )
365+
366+ mockTFCTrigger := mocks .NewMockTrigger (mockCtrl )
367+ mockTFCConfig := mocks .NewMockTriggerConfig (mockCtrl )
368+ mockTFCConfig .EXPECT ().SetAction (tfc_trigger .PlanAction )
369+ mockTFCConfig .EXPECT ().SetWorkspace ("service-tf-buddy" )
370+ mockTFCTrigger .EXPECT ().GetConfig ().Return (mockTFCConfig ).Times (2 )
371+ mockTFCTrigger .EXPECT ().TriggerTFCEvents ().Return (nil , nil )
372+
373+ client := & GitlabEventWorker {
374+ gl : mockGitClient ,
375+ tfc : mockApiClient ,
376+ runstream : mockStreamClient ,
377+ triggerCreation : func (gl vcs.GitClient , tfc tfc_api.ApiClient , runstream runstream.StreamClient , cfg tfc_trigger.TriggerConfig ) tfc_trigger.Trigger {
378+ return mockTFCTrigger
379+ },
380+ }
381+
382+ proj , err := client .processNoteEvent (mockMREvent )
383+ if err != nil {
384+ t .Fatal (err )
385+ }
386+ if proj != "zapier/service-tf-buddy" {
387+ t .Fatal ("expected a project name to be returned" )
388+ }
389+ }
0 commit comments