This commit is contained in:
Adam Majer 2024-11-10 23:19:23 +01:00
parent 0a7978569e
commit c757b50c65

View File

@ -8,16 +8,13 @@ import (
// "go.uber.org/mock/gomock"
"go.uber.org/mock/gomock"
"src.opensuse.org/autogits/common"
mock_common "src.opensuse.org/autogits/common/mock"
// mock_common "src.opensuse.org/autogits/common/mock"
mock_main "src.opensuse.org/workflow-pr/mock"
// "src.opensuse.org/autogits/common/mock"
)
func TestPRProcessor(t *testing.T) {
ctl := gomock.NewController(t)
defer ctl.Finish()
var logBuf bytes.Buffer
oldOut := log.Writer()
log.SetOutput(&logBuf)
@ -27,38 +24,26 @@ func TestPRProcessor(t *testing.T) {
testConfiguration["test"] = make([]*common.AutogitConfig, 1, 1)
testConfiguration["test"][0] = &common.AutogitConfig{
Branch: "branch",
}
req := &RequestProcessor{
Opened: mock_main.NewMockPullRequestProcessor(ctl),
Closed: mock_main.NewMockPullRequestProcessor(ctl),
Synced: mock_main.NewMockPullRequestProcessor(ctl),
gitea: mock_common.NewMockGitea(ctl),
configuredRepos: testConfiguration,
}
// gitea := mock_common.NewMockGitea(ctl)
pr_opened := mock_main.NewMockPullRequestProcessor(ctl)
pr_opened.EXPECT().Process(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)
event := &common.PullRequestWebhookEvent{
Action: "opened",
// Action: "opened",
Number: 1,
Pull_Request: &common.PullRequest{
Id: 1,
Base: common.Head{
Ref: "HEAD",
Sha: "abc",
Ref: "branch",
Repo: &common.Repository{
Name: "testRepo",
},
},
Head: common.Head{
Ref: "HEAD",
Sha: "abc",
Ref: "branch",
Repo: &common.Repository{
Name: "testRepo",
},
@ -71,14 +56,39 @@ func TestPRProcessor(t *testing.T) {
},
}
t.Run("Open routine called for PR opening", func(t *testing.T) {
ctl := gomock.NewController(t)
openedMock := mock_main.NewMockPullRequestProcessor(ctl)
openedMock.EXPECT().Process(event, gomock.Any(), testConfiguration["test"][0]).Return(nil)
req.Opened = openedMock
event.Action = "opened"
err := req.ProcessFunc(&common.Request{
Data: event,
})
if err != nil {
t.Error("Error processing open PR", err)
t.Error("Error processing open PR:", err)
t.Error(logBuf.String())
}
})
t.Run("Close routine called for PR closing", func(t *testing.T) {
ctl := gomock.NewController(t)
closedMock := mock_main.NewMockPullRequestProcessor(ctl)
closedMock.EXPECT().Process(event, gomock.Any(), testConfiguration["test"][0]).Return(nil)
req.Closed = closedMock
event.Action = "closed"
err := req.ProcessFunc(&common.Request{
Data: event,
})
if err != nil {
t.Error("Error processing open PR:", err)
t.Error(logBuf.String())
}
})
}