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"
|
||||||
"go.uber.org/mock/gomock"
|
"go.uber.org/mock/gomock"
|
||||||
"src.opensuse.org/autogits/common"
|
"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"
|
mock_main "src.opensuse.org/workflow-pr/mock"
|
||||||
// "src.opensuse.org/autogits/common/mock"
|
// "src.opensuse.org/autogits/common/mock"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
func TestPRProcessor(t *testing.T) {
|
func TestPRProcessor(t *testing.T) {
|
||||||
ctl := gomock.NewController(t)
|
|
||||||
defer ctl.Finish()
|
|
||||||
|
|
||||||
var logBuf bytes.Buffer
|
var logBuf bytes.Buffer
|
||||||
oldOut := log.Writer()
|
oldOut := log.Writer()
|
||||||
log.SetOutput(&logBuf)
|
log.SetOutput(&logBuf)
|
||||||
@ -26,59 +23,72 @@ func TestPRProcessor(t *testing.T) {
|
|||||||
testConfiguration := make(map[string][]*common.AutogitConfig)
|
testConfiguration := make(map[string][]*common.AutogitConfig)
|
||||||
|
|
||||||
testConfiguration["test"] = make([]*common.AutogitConfig, 1, 1)
|
testConfiguration["test"] = make([]*common.AutogitConfig, 1, 1)
|
||||||
testConfiguration["test"][0] = &common.AutogitConfig {
|
testConfiguration["test"][0] = &common.AutogitConfig{
|
||||||
|
Branch: "branch",
|
||||||
}
|
}
|
||||||
|
|
||||||
req := &RequestProcessor {
|
req := &RequestProcessor{
|
||||||
Opened: mock_main.NewMockPullRequestProcessor(ctl),
|
|
||||||
Closed: mock_main.NewMockPullRequestProcessor(ctl),
|
|
||||||
Synced: mock_main.NewMockPullRequestProcessor(ctl),
|
|
||||||
|
|
||||||
gitea: mock_common.NewMockGitea(ctl),
|
|
||||||
configuredRepos: testConfiguration,
|
configuredRepos: testConfiguration,
|
||||||
}
|
}
|
||||||
|
|
||||||
// gitea := mock_common.NewMockGitea(ctl)
|
event := &common.PullRequestWebhookEvent{
|
||||||
pr_opened := mock_main.NewMockPullRequestProcessor(ctl)
|
// Action: "opened",
|
||||||
|
|
||||||
pr_opened.EXPECT().Process(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)
|
|
||||||
|
|
||||||
event := &common.PullRequestWebhookEvent {
|
|
||||||
Action: "opened",
|
|
||||||
Number: 1,
|
Number: 1,
|
||||||
Pull_Request: &common.PullRequest {
|
Pull_Request: &common.PullRequest{
|
||||||
Id: 1,
|
Id: 1,
|
||||||
Base: common.Head {
|
Base: common.Head{
|
||||||
Ref: "HEAD",
|
Ref: "branch",
|
||||||
Sha: "abc",
|
Repo: &common.Repository{
|
||||||
Repo: &common.Repository {
|
|
||||||
Name: "testRepo",
|
Name: "testRepo",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Head: common.Head {
|
Head: common.Head{
|
||||||
Ref: "HEAD",
|
Ref: "branch",
|
||||||
Sha: "abc",
|
Repo: &common.Repository{
|
||||||
Repo: &common.Repository {
|
|
||||||
Name: "testRepo",
|
Name: "testRepo",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Repository: &common.Repository {
|
Repository: &common.Repository{
|
||||||
Owner: &common.Organization {
|
Owner: &common.Organization{
|
||||||
Username: "test",
|
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{
|
err := req.ProcessFunc(&common.Request{
|
||||||
Data: event,
|
Data: event,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("Error processing open PR", err)
|
t.Error("Error processing open PR:", err)
|
||||||
t.Error(logBuf.String())
|
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…
x
Reference in New Issue
Block a user