-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add additional unit tests for auto merge
Signed-off-by: davidwin93 <[email protected]>
- Loading branch information
1 parent
aed8c9e
commit 7b842ef
Showing
1 changed file
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package gitlab | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"testing" | ||
|
||
"github.com/hashicorp/go-tfe" | ||
gogitlab "github.com/xanzy/go-gitlab" | ||
"github.com/zapier/tfbuddy/pkg/mocks" | ||
"github.com/zapier/tfbuddy/pkg/runstream" | ||
"github.com/zapier/tfbuddy/pkg/vcs" | ||
"go.uber.org/mock/gomock" | ||
) | ||
|
||
func TestAutoMergeNoChangesApply(t *testing.T) { | ||
|
||
mockCtrl := gomock.NewController(t) | ||
defer mockCtrl.Finish() | ||
testSuite := mocks.CreateTestSuite(mockCtrl, mocks.TestOverrides{}, t) | ||
|
||
testSuite.MockGitClient.EXPECT().MergeMR(gomock.Any(), gomock.Any(), gomock.Any()) | ||
testSuite.MockGitClient.EXPECT().GetPipelinesForCommit(gomock.Any(), gomock.Any(), gomock.Any()).Return([]vcs.ProjectPipeline{&GitlabPipeline{&gogitlab.PipelineInfo{ID: 1}}}, nil).AnyTimes() | ||
testSuite.MockGitClient.EXPECT().SetCommitStatus(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("could not commit status")).AnyTimes() | ||
testSuite.InitTestSuite() | ||
r := &RunStatusUpdater{ | ||
tfc: testSuite.MockApiClient, | ||
client: testSuite.MockGitClient, | ||
rs: testSuite.MockStreamClient, | ||
} | ||
r.updateCommitStatusForRun(context.Background(), &tfe.Run{ | ||
Status: tfe.RunPlannedAndFinished, | ||
HasChanges: false, | ||
}, &runstream.TFRunMetadata{ | ||
Action: "apply", | ||
AutoMerge: true, | ||
}) | ||
} | ||
func TestAutoMergeTargetedNoChangesApply(t *testing.T) { | ||
|
||
mockCtrl := gomock.NewController(t) | ||
defer mockCtrl.Finish() | ||
testSuite := mocks.CreateTestSuite(mockCtrl, mocks.TestOverrides{}, t) | ||
|
||
testSuite.MockGitClient.EXPECT().MergeMR(gomock.Any(), gomock.Any(), gomock.Any()).MaxTimes(0) | ||
|
||
testSuite.MockGitClient.EXPECT().GetPipelinesForCommit(gomock.Any(), gomock.Any(), gomock.Any()).Return([]vcs.ProjectPipeline{&GitlabPipeline{&gogitlab.PipelineInfo{ID: 1}}}, nil).AnyTimes() | ||
testSuite.MockGitClient.EXPECT().SetCommitStatus(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("could not commit status")).AnyTimes() | ||
testSuite.InitTestSuite() | ||
r := &RunStatusUpdater{ | ||
tfc: testSuite.MockApiClient, | ||
client: testSuite.MockGitClient, | ||
rs: testSuite.MockStreamClient, | ||
} | ||
r.updateCommitStatusForRun(context.Background(), &tfe.Run{ | ||
Status: tfe.RunPlannedAndFinished, | ||
HasChanges: false, | ||
TargetAddrs: []string{"module.foo"}, | ||
}, &runstream.TFRunMetadata{ | ||
Action: "apply", | ||
AutoMerge: true, | ||
}) | ||
} | ||
|
||
func TestAutoMergeApply(t *testing.T) { | ||
|
||
mockCtrl := gomock.NewController(t) | ||
defer mockCtrl.Finish() | ||
testSuite := mocks.CreateTestSuite(mockCtrl, mocks.TestOverrides{}, t) | ||
|
||
testSuite.MockGitClient.EXPECT().MergeMR(gomock.Any(), gomock.Any(), gomock.Any()) | ||
testSuite.MockGitClient.EXPECT().GetPipelinesForCommit(gomock.Any(), gomock.Any(), gomock.Any()).Return([]vcs.ProjectPipeline{&GitlabPipeline{&gogitlab.PipelineInfo{ID: 1}}}, nil).AnyTimes() | ||
testSuite.MockGitClient.EXPECT().SetCommitStatus(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("could not commit status")).AnyTimes() | ||
testSuite.InitTestSuite() | ||
r := &RunStatusUpdater{ | ||
tfc: testSuite.MockApiClient, | ||
client: testSuite.MockGitClient, | ||
rs: testSuite.MockStreamClient, | ||
} | ||
r.updateCommitStatusForRun(context.Background(), &tfe.Run{ | ||
Status: tfe.RunApplied, | ||
HasChanges: true, | ||
}, &runstream.TFRunMetadata{ | ||
Action: "apply", | ||
AutoMerge: true, | ||
}) | ||
} | ||
|
||
func TestAutoMergeTargetedApply(t *testing.T) { | ||
|
||
mockCtrl := gomock.NewController(t) | ||
defer mockCtrl.Finish() | ||
testSuite := mocks.CreateTestSuite(mockCtrl, mocks.TestOverrides{}, t) | ||
|
||
testSuite.MockGitClient.EXPECT().MergeMR(gomock.Any(), gomock.Any(), gomock.Any()).MaxTimes(0) | ||
|
||
testSuite.MockGitClient.EXPECT().GetPipelinesForCommit(gomock.Any(), gomock.Any(), gomock.Any()).Return([]vcs.ProjectPipeline{&GitlabPipeline{&gogitlab.PipelineInfo{ID: 1}}}, nil).AnyTimes() | ||
testSuite.MockGitClient.EXPECT().SetCommitStatus(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("could not commit status")).AnyTimes() | ||
testSuite.InitTestSuite() | ||
r := &RunStatusUpdater{ | ||
tfc: testSuite.MockApiClient, | ||
client: testSuite.MockGitClient, | ||
rs: testSuite.MockStreamClient, | ||
} | ||
r.updateCommitStatusForRun(context.Background(), &tfe.Run{ | ||
Status: tfe.RunApplied, | ||
HasChanges: true, | ||
TargetAddrs: []string{"module.foo"}, | ||
}, &runstream.TFRunMetadata{ | ||
Action: "apply", | ||
AutoMerge: true, | ||
}) | ||
} |