From 2bc9830a7ac43af412f9641b1d5c2b548122c58717fe85e68e1d311d79e3ca4c Mon Sep 17 00:00:00 2001 From: Adam Majer Date: Wed, 27 Nov 2024 16:13:37 +0100 Subject: [PATCH] workflow-pr: tests --- workflow-pr/repo_check_test.go | 40 ++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/workflow-pr/repo_check_test.go b/workflow-pr/repo_check_test.go index 9abc6d6..1497863 100644 --- a/workflow-pr/repo_check_test.go +++ b/workflow-pr/repo_check_test.go @@ -4,6 +4,7 @@ import ( "bytes" "errors" "log" + "os" "testing" "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) gitea := mock_common.NewMockGitea(ctl) + process := mock_main.NewMockPullRequestProcessor(ctl) git := &common.GitHandler{ DebugLogger: true, @@ -225,15 +227,49 @@ func TestVerifyProjectState(t *testing.T) { gitea.EXPECT().CreateRepositoryIfNotExist(gomock.Any(), gomock.Any(), config1.GitProjectName).Return(&models.Repository{ SSHURL: "./prj", }, nil) + gitea.EXPECT().GetRecentPullRequests(org, "testRepo").Return([]*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()) c := CreateDefaultStateChecker(false, configs, gitea, 0) c.git = &testGit{ git: git, } + process.EXPECT().Process(gomock.Any(), gomock.Any(), gomock.Any()) + c.processor.Opened = process err := c.VerifyProjectState("repo1_org", configs.configuredRepos[org], 0)