nitter/nitters/gitea/pr_nitter_test.go
Peter Kurfer 0409dd2fba
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
fix(gitea): don't approve if token is owned by PR creator
2023-03-09 15:54:23 +01:00

50 lines
1.2 KiB
Go

package gitea_test
import (
"errors"
"testing"
giteasdk "code.gitea.io/sdk/gitea"
"github.com/golangci/golangci-lint/pkg/report"
"github.com/stretchr/testify/mock"
"code.icb4dc0.de/prskr/nitter/nitters/gitea"
"code.icb4dc0.de/prskr/nitter/nitters/gitea/mocks"
)
func Test_PRNitter_Report_MockCreatorError_Error(t *testing.T) {
t.Parallel()
expectedError := errors.New("error")
client := mocks.NewClient(t)
client.
EXPECT().
CreatePullReview(mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(nil, nil, expectedError).
Times(1)
client.
EXPECT().
GetMyUserInfo().
Return(&giteasdk.User{ID: 11}, nil, nil).
Times(1)
client.
EXPECT().
GetPullRequest(mock.Anything, mock.Anything, mock.Anything).
Return(&giteasdk.PullRequest{Poster: &giteasdk.User{}}, nil, nil)
client.
EXPECT().
ListPullReviews(mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(nil, nil, nil).
Times(1)
p := gitea.NewPRNitter(client, &gitea.GiteaPRConfig{})
if err := p.Report(new(report.Data), nil); err == nil {
t.Error("expected error bot got none")
} else if !errors.Is(err, expectedError) {
t.Errorf("Error %v was not expected", err)
}
}