workflow-pr: tests

This commit is contained in:
Adam Majer 2024-11-27 16:13:37 +01:00
parent f281986c8f
commit 2bc9830a7a

View File

@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"errors" "errors"
"log" "log"
"os"
"testing" "testing"
"go.uber.org/mock/gomock" "go.uber.org/mock/gomock"
@ -195,9 +196,10 @@ func TestVerifyProjectState(t *testing.T) {
} }
}) })
t.Run("Project state with 1 PRs", func(t *testing.T) { t.Run("Project state with 1 PRs that doesn't trigger updates", func(t *testing.T) {
ctl := gomock.NewController(t) ctl := gomock.NewController(t)
gitea := mock_common.NewMockGitea(ctl) gitea := mock_common.NewMockGitea(ctl)
process := mock_main.NewMockPullRequestProcessor(ctl)
git := &common.GitHandler{ git := &common.GitHandler{
DebugLogger: true, DebugLogger: true,
@ -225,15 +227,49 @@ func TestVerifyProjectState(t *testing.T) {
gitea.EXPECT().CreateRepositoryIfNotExist(gomock.Any(), gomock.Any(), config1.GitProjectName).Return(&models.Repository{ gitea.EXPECT().CreateRepositoryIfNotExist(gomock.Any(), gomock.Any(), config1.GitProjectName).Return(&models.Repository{
SSHURL: "./prj", SSHURL: "./prj",
}, nil) }, nil)
gitea.EXPECT().GetRecentPullRequests(org, "testRepo").Return([]*models.PullRequest{ gitea.EXPECT().GetRecentPullRequests(org, "testRepo").Return([]*models.PullRequest{
&models.PullRequest{ &models.PullRequest{
}}, nil) ID: 1234,
URL: "url here",
Index: 1234,
State: "open",
Labels: []*models.Label{
&models.Label{
ID: 1,
},
},
User: &models.User{},
Base: &models.PRBranchInfo {
Name: "one",
Ref: "main",
Sha: "123",
Repo: &models.Repository {
Owner: &models.User {
},
},
},
Head: &models.PRBranchInfo {
Name: "one",
Ref: "main",
Sha: "123",
Repo: &models.Repository {
Owner: &models.User {
},
},
},
},
}, nil)
gitea.EXPECT().GetRecentCommits(org, "testRepo", "testing", gomock.Any()) gitea.EXPECT().GetRecentCommits(org, "testRepo", "testing", gomock.Any())
c := CreateDefaultStateChecker(false, configs, gitea, 0) c := CreateDefaultStateChecker(false, configs, gitea, 0)
c.git = &testGit{ c.git = &testGit{
git: git, git: git,
} }
process.EXPECT().Process(gomock.Any(), gomock.Any(), gomock.Any())
c.processor.Opened = process
err := c.VerifyProjectState("repo1_org", configs.configuredRepos[org], 0) err := c.VerifyProjectState("repo1_org", configs.configuredRepos[org], 0)