This commit is contained in:
2024-12-16 08:15:49 +01:00
parent 8c6180a8cf
commit 50aab4c662
8 changed files with 136 additions and 54 deletions

View File

@@ -3,7 +3,6 @@ package main
import (
"bytes"
"errors"
"log"
"os"
"path"
"strings"
@@ -34,7 +33,10 @@ func TestSyncPR(t *testing.T) {
Ref: "branch",
Sha: "8a6a69a4232cabda04a4d9563030aa888ff5482f75aa4c6519da32a951a072e2",
Repo: &common.Repository{
Name: "testRepo",
Name: "testRepo",
Owner: &common.Organization{
Username: config.Organization,
},
Default_Branch: "main1",
},
},
@@ -49,13 +51,42 @@ func TestSyncPR(t *testing.T) {
},
Repository: &common.Repository{
Owner: &common.Organization{
Username: "test",
Username: config.Organization,
},
},
}
modelPR := &models.PullRequest{
Index: 42,
Body: "PR: test/prj#24",
Base: &models.PRBranchInfo{
Ref: "branch",
Sha: "8a6a69a4232cabda04a4d9563030aa888ff5482f75aa4c6519da32a951a072e2",
Repo: &models.Repository{
Name: "testRepo",
Owner: &models.User{
UserName: "test",
},
DefaultBranch: "main1",
},
},
Head: &models.PRBranchInfo{
Ref: "branch",
Sha: "11eb36d5a58d7bb376cac59ac729a1986c6a7bfc63e7818e14382f545ccda985",
Repo: &models.Repository{
Name: "testRepo",
Owner: &models.User {
UserName: "test",
},
DefaultBranch: "main1",
},
},
}
PrjGitPR := &models.PullRequest{
Title: "some pull request",
Body: "PR: test/testRepo#42",
Index: 24,
Head: &models.PRBranchInfo{
Name: "testing",
Sha: "db8adab91edb476b9762097d10c6379aa71efd6b60933a1c0e355ddacf419a95",
@@ -92,11 +123,13 @@ func TestSyncPR(t *testing.T) {
git.GitPath = t.TempDir()
config.GitProjectName = "prjGit"
event.Repository.Name = "tester"
event.Repository.Name = "testRepo"
setupGitForTests(t, git)
mock.EXPECT().GetAssociatedPrjGitPR(event).Return(PrjGitPR, nil)
// mock.EXPECT().GetAssociatedPrjGitPR(event).Return(PrjGitPR, nil)
mock.EXPECT().GetPullRequestAndReviews(config.Organization, "testRepo", event.Pull_Request.Number).Return(modelPR, nil, nil)
mock.EXPECT().GetPullRequestAndReviews(config.Organization, "prj", int64(24)).Return(PrjGitPR, nil, nil)
err := pr.Process(event, git, config)
@@ -129,9 +162,11 @@ func TestSyncPR(t *testing.T) {
t.Run("PR sync", func(t *testing.T) {
var b bytes.Buffer
/*
w := log.Writer()
log.SetOutput(&b)
defer log.SetOutput(w)
*/
ctl := gomock.NewController(t)
mock := mock_common.NewMockGitea(ctl)
@@ -146,7 +181,9 @@ func TestSyncPR(t *testing.T) {
git.DebugLogger = true
DebugMode = true
mock.EXPECT().GetAssociatedPrjGitPR(event).Return(PrjGitPR, nil)
// mock.EXPECT().GetAssociatedPrjGitPR(event).Return(PrjGitPR, nil)
mock.EXPECT().GetPullRequestAndReviews(config.Organization, "testRepo", event.Pull_Request.Number).Return(modelPR, nil, nil).AnyTimes()
mock.EXPECT().GetPullRequestAndReviews(config.Organization, "prj", int64(24)).Return(PrjGitPR, nil, nil)
err := pr.Process(event, git, config)