wip
This commit is contained in:
parent
0a7978569e
commit
c757b50c65
@ -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)
|
||||
@ -26,59 +23,72 @@ func TestPRProcessor(t *testing.T) {
|
||||
testConfiguration := make(map[string][]*common.AutogitConfig)
|
||||
|
||||
testConfiguration["test"] = make([]*common.AutogitConfig, 1, 1)
|
||||
testConfiguration["test"][0] = &common.AutogitConfig {
|
||||
|
||||
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),
|
||||
req := &RequestProcessor{
|
||||
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",
|
||||
event := &common.PullRequestWebhookEvent{
|
||||
// Action: "opened",
|
||||
Number: 1,
|
||||
Pull_Request: &common.PullRequest {
|
||||
Pull_Request: &common.PullRequest{
|
||||
Id: 1,
|
||||
Base: common.Head {
|
||||
Ref: "HEAD",
|
||||
Sha: "abc",
|
||||
Repo: &common.Repository {
|
||||
Base: common.Head{
|
||||
Ref: "branch",
|
||||
Repo: &common.Repository{
|
||||
Name: "testRepo",
|
||||
},
|
||||
},
|
||||
Head: common.Head {
|
||||
Ref: "HEAD",
|
||||
Sha: "abc",
|
||||
Repo: &common.Repository {
|
||||
Head: common.Head{
|
||||
Ref: "branch",
|
||||
Repo: &common.Repository{
|
||||
Name: "testRepo",
|
||||
},
|
||||
},
|
||||
},
|
||||
Repository: &common.Repository {
|
||||
Owner: &common.Organization {
|
||||
Repository: &common.Repository{
|
||||
Owner: &common.Organization{
|
||||
Username: "test",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
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())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user