@@ -22,6 +22,10 @@ func TestAutoMergeNoChangesApply(t *testing.T) {
2222 testSuite .MockGitClient .EXPECT ().MergeMR (gomock .Any (), gomock .Any (), gomock .Any ())
2323 testSuite .MockGitClient .EXPECT ().GetPipelinesForCommit (gomock .Any (), gomock .Any (), gomock .Any ()).Return ([]vcs.ProjectPipeline {& GitlabPipeline {& gogitlab.PipelineInfo {ID : 1 }}}, nil ).AnyTimes ()
2424 testSuite .MockGitClient .EXPECT ().SetCommitStatus (gomock .Any (), gomock .Any (), gomock .Any (), gomock .Any ()).Return (nil , errors .New ("could not commit status" )).AnyTimes ()
25+ testSuite .MockStreamClient .EXPECT ().GetWorkspaceMeta (gomock .Any (), gomock .Any ()).Return (& runstream.TFCWorkspacesMetadata {
26+ CountExecutedWorkspaces : 0 ,
27+ CountTotalWorkspaces : 1 ,
28+ }, nil )
2529 testSuite .InitTestSuite ()
2630 r := & RunStatusUpdater {
2731 tfc : testSuite .MockApiClient ,
@@ -71,6 +75,12 @@ func TestAutoMergeApply(t *testing.T) {
7175 testSuite .MockGitClient .EXPECT ().MergeMR (gomock .Any (), gomock .Any (), gomock .Any ())
7276 testSuite .MockGitClient .EXPECT ().GetPipelinesForCommit (gomock .Any (), gomock .Any (), gomock .Any ()).Return ([]vcs.ProjectPipeline {& GitlabPipeline {& gogitlab.PipelineInfo {ID : 1 }}}, nil ).AnyTimes ()
7377 testSuite .MockGitClient .EXPECT ().SetCommitStatus (gomock .Any (), gomock .Any (), gomock .Any (), gomock .Any ()).Return (nil , errors .New ("could not commit status" )).AnyTimes ()
78+
79+ testSuite .MockStreamClient .EXPECT ().GetWorkspaceMeta (gomock .Any (), gomock .Any ()).Return (& runstream.TFCWorkspacesMetadata {
80+ CountExecutedWorkspaces : 0 ,
81+ CountTotalWorkspaces : 1 ,
82+ }, nil )
83+
7484 testSuite .InitTestSuite ()
7585 r := & RunStatusUpdater {
7686 tfc : testSuite .MockApiClient ,
@@ -86,6 +96,54 @@ func TestAutoMergeApply(t *testing.T) {
8696 })
8797}
8898
99+ func TestAutoMergeApplyMultiWorkspace (t * testing.T ) {
100+
101+ mockCtrl := gomock .NewController (t )
102+ defer mockCtrl .Finish ()
103+
104+ testSuite := mocks .CreateTestSuite (mockCtrl , mocks.TestOverrides {}, t )
105+
106+ testSuite .MockGitClient .EXPECT ().MergeMR (gomock .Any (), gomock .Any (), gomock .Any ())
107+ testSuite .MockGitClient .EXPECT ().GetPipelinesForCommit (gomock .Any (), gomock .Any (), gomock .Any ()).Return ([]vcs.ProjectPipeline {& GitlabPipeline {& gogitlab.PipelineInfo {ID : 1 }}}, nil ).AnyTimes ()
108+ testSuite .MockGitClient .EXPECT ().SetCommitStatus (gomock .Any (), gomock .Any (), gomock .Any (), gomock .Any ()).Return (nil , errors .New ("could not commit status" )).AnyTimes ()
109+
110+ //workspace 1 in same mr
111+ testSuite .MockStreamClient .EXPECT ().GetWorkspaceMeta ("101" , "zapier/test" ).Return (& runstream.TFCWorkspacesMetadata {
112+ CountExecutedWorkspaces : 0 ,
113+ CountTotalWorkspaces : 2 ,
114+ }, nil )
115+ //workspace 2 in same mr
116+ testSuite .MockStreamClient .EXPECT ().GetWorkspaceMeta ("101" , "zapier/test" ).Return (& runstream.TFCWorkspacesMetadata {
117+ CountExecutedWorkspaces : 1 ,
118+ CountTotalWorkspaces : 2 ,
119+ }, nil )
120+
121+ testSuite .InitTestSuite ()
122+ r := & RunStatusUpdater {
123+ tfc : testSuite .MockApiClient ,
124+ client : testSuite .MockGitClient ,
125+ rs : testSuite .MockStreamClient ,
126+ }
127+ r .updateCommitStatusForRun (context .Background (), & tfe.Run {
128+ Status : tfe .RunApplied ,
129+ HasChanges : true ,
130+ }, & runstream.TFRunMetadata {
131+ Action : "apply" ,
132+ AutoMerge : true ,
133+ MergeRequestIID : 101 ,
134+ MergeRequestProjectNameWithNamespace : "zapier/test" ,
135+ })
136+
137+ r .updateCommitStatusForRun (context .Background (), & tfe.Run {
138+ Status : tfe .RunApplied ,
139+ HasChanges : true ,
140+ }, & runstream.TFRunMetadata {
141+ Action : "apply" ,
142+ AutoMerge : true ,
143+ MergeRequestIID : 101 ,
144+ MergeRequestProjectNameWithNamespace : "zapier/test" ,
145+ })
146+ }
89147func TestAutoMergeTargetedApply (t * testing.T ) {
90148
91149 mockCtrl := gomock .NewController (t )
0 commit comments