autogits/workflow-pr/review_test.go
2024-12-16 18:12:54 +01:00

50 lines
1.3 KiB
Go

package main
import (
"errors"
"os"
"os/exec"
"path"
"testing"
"go.uber.org/mock/gomock"
"src.opensuse.org/autogits/common/gitea-generated/models"
mock_common "src.opensuse.org/autogits/common/mock"
)
func TestReview(t *testing.T) {
cwd, _ := os.Getwd()
cmd := exec.Command("/usr/bin/bash", path.Join(cwd, "test_repo_setup.sh"))
cmd.Dir = t.TempDir()
if out, err := cmd.CombinedOutput(); err != nil {
t.Fatal(string(out))
}
tests := []struct {
name string
org string
repo string
pr_no int64
pr *models.PullRequest
err error
}{
{name: "Error fetching ReviewSet if there are missing links", org: "test", repo: "repo", pr_no: 42, pr: &models.PullRequest{Body: ""}},
{name: "Error fetching ReviewSet if there are missing links", org: "test", repo: "repo", pr_no: 42, pr: &models.PullRequest{Body: ""}, err: errors.New("Missing PR")},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
ctl := gomock.NewController(t)
mock := mock_common.NewMockGiteaPRReviewFetcher(ctl)
mock.EXPECT().GetPullRequestAndReviews(test.org, test.repo, test.pr_no).Return(test.pr, nil, test.err)
_, err := FetchReviewSet(mock, "test", "repo", 42)
if test.err != nil && err == nil {
t.Fatal("Expected", test.err, "but got", err)
}
})
}
}