85 lines
1.8 KiB
Go
85 lines
1.8 KiB
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
|
"go.uber.org/mock/gomock"
|
||
|
"src.opensuse.org/autogits/common"
|
||
|
mock_common "src.opensuse.org/autogits/common/mock"
|
||
|
)
|
||
|
|
||
|
func TestClosePR(t *testing.T) {
|
||
|
pr := PullRequestClosed{}
|
||
|
|
||
|
config := &common.AutogitConfig{
|
||
|
Reviewers: []string{"reviewer1", "reviewer2"},
|
||
|
Branch: "branch",
|
||
|
Organization: "test",
|
||
|
GitProjectName: "prj",
|
||
|
}
|
||
|
|
||
|
event := &common.PullRequestWebhookEvent{
|
||
|
Action: "closed",
|
||
|
Number: 1,
|
||
|
Pull_Request: &common.PullRequest{
|
||
|
Id: 1,
|
||
|
Base: common.Head{
|
||
|
Ref: "branch",
|
||
|
Sha: "testing",
|
||
|
Repo: &common.Repository{
|
||
|
Name: "testRepo",
|
||
|
Default_Branch: "main1",
|
||
|
},
|
||
|
},
|
||
|
Head: common.Head{
|
||
|
Ref: "branch",
|
||
|
Sha: "testing",
|
||
|
Repo: &common.Repository{
|
||
|
Name: "testRepo",
|
||
|
Default_Branch: "main1",
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
Repository: &common.Repository{
|
||
|
Owner: &common.Organization{
|
||
|
Username: "test",
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
|
||
|
git := &common.GitHandler{
|
||
|
GitCommiter: "tester",
|
||
|
GitEmail: "test@suse.com",
|
||
|
}
|
||
|
|
||
|
t.Run("PR git closed request against PrjGit == no action", func(t *testing.T) {
|
||
|
ctl := gomock.NewController(t)
|
||
|
pr.gitea = mock_common.NewMockGitea(ctl)
|
||
|
|
||
|
git.GitPath = t.TempDir()
|
||
|
|
||
|
config.GitProjectName = "testRepo"
|
||
|
event.Repository.Name = "testRepo"
|
||
|
|
||
|
if err := pr.Process(event, git, config); err != nil {
|
||
|
t.Error("Error PrjGit closed request. Should be no error.", err)
|
||
|
}
|
||
|
})
|
||
|
|
||
|
t.Run("PR git closed", func(t *testing.T) {
|
||
|
ctl := gomock.NewController(t)
|
||
|
pr.gitea = mock_common.NewMockGitea(ctl)
|
||
|
|
||
|
git.GitPath = t.TempDir()
|
||
|
|
||
|
config.GitProjectName = "prjGit"
|
||
|
event.Repository.Name = "tester"
|
||
|
|
||
|
if err := pr.Process(event, git, config); err != nil {
|
||
|
t.Error("Error PrjGit closed request. Should be no error.", err)
|
||
|
}
|
||
|
})
|
||
|
|
||
|
}
|
||
|
|