85 lines
1.7 KiB
Go
85 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"log"
|
|
"testing"
|
|
|
|
// "go.uber.org/mock/gomock"
|
|
"go.uber.org/mock/gomock"
|
|
"src.opensuse.org/autogits/common"
|
|
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)
|
|
defer log.SetOutput(oldOut)
|
|
|
|
testConfiguration := make(map[string][]*common.AutogitConfig)
|
|
|
|
testConfiguration["test"] = make([]*common.AutogitConfig, 1, 1)
|
|
testConfiguration["test"][0] = &common.AutogitConfig {
|
|
|
|
}
|
|
|
|
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",
|
|
Number: 1,
|
|
Pull_Request: &common.PullRequest {
|
|
Id: 1,
|
|
Base: common.Head {
|
|
Ref: "HEAD",
|
|
Sha: "abc",
|
|
Repo: &common.Repository {
|
|
Name: "testRepo",
|
|
},
|
|
},
|
|
Head: common.Head {
|
|
Ref: "HEAD",
|
|
Sha: "abc",
|
|
Repo: &common.Repository {
|
|
Name: "testRepo",
|
|
},
|
|
},
|
|
},
|
|
Repository: &common.Repository {
|
|
Owner: &common.Organization {
|
|
Username: "test",
|
|
},
|
|
},
|
|
}
|
|
|
|
err := req.ProcessFunc(&common.Request{
|
|
Data: event,
|
|
})
|
|
|
|
if err != nil {
|
|
t.Error("Error processing open PR", err)
|
|
t.Error(logBuf.String())
|
|
}
|
|
}
|
|
|
|
|