test(gitea): add basic test for PR review creation
This commit is contained in:
parent
a71976604a
commit
1707692170
7 changed files with 68 additions and 11 deletions
32
.drone.yml
32
.drone.yml
|
@ -22,7 +22,30 @@ steps:
|
|||
- name: go-cache
|
||||
path: /go
|
||||
|
||||
- name: Lint
|
||||
- name: Lint PR
|
||||
image: docker.io/golangci/golangci-lint:latest
|
||||
network_mode: host
|
||||
environment:
|
||||
CGO_ENABLED: "0"
|
||||
GOMEMLIMIT: "1150MiB"
|
||||
NITTER_BASE_ADDRESS: https://code.icb4dc0.de
|
||||
NITTER_TOKEN:
|
||||
from_secret: gitea_token
|
||||
when:
|
||||
event:
|
||||
- pull_request
|
||||
commands:
|
||||
- apt-get update && apt-get install -y jq
|
||||
- mkdir out
|
||||
- golangci-lint run --out-format json --issues-exit-code 0 --new-from-rev "$(curl https://code.icb4dc0.de/api/v1/repos/prskr/nitter/pulls/1 | jq -r '.base.sha')" > out/results.json
|
||||
- go run main.go gitea pr --namespace "$${DRONE_REPO_NAMESPACE}" --repo "$${DRONE_REPO_NAME}" --result-file out/results.json --pull-index "$${DRONE_PULL_REQUEST}"
|
||||
depends_on:
|
||||
- Setup
|
||||
volumes:
|
||||
- name: go-cache
|
||||
path: /go
|
||||
|
||||
- name: Lint repo
|
||||
image: docker.io/golangci/golangci-lint:latest
|
||||
environment:
|
||||
CGO_ENABLED: "0"
|
||||
|
@ -30,10 +53,13 @@ steps:
|
|||
NITTER_BASE_ADDRESS: https://code.icb4dc0.de
|
||||
NITTER_TOKEN:
|
||||
from_secret: gitea_token
|
||||
when:
|
||||
event:
|
||||
- push
|
||||
- tag
|
||||
commands:
|
||||
- mkdir out
|
||||
- golangci-lint run --out-format json --issues-exit-code 0 > out/results.json
|
||||
- if [ -n "$DRONE_PULL_REQUEST}" ]; then go run main.go gitea pr --namespace "$${DRONE_REPO_NAMESPACE}" --repo "$${DRONE_REPO_NAME}" --result-file out/results.json --pull-index "$${DRONE_PULL_REQUEST}"; fi
|
||||
- golangci-lint run -v
|
||||
depends_on:
|
||||
- Setup
|
||||
volumes:
|
||||
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -12,6 +12,7 @@
|
|||
# Test binary, built with `go test -c`
|
||||
*.test
|
||||
mock_*_test.go
|
||||
*.mock.go
|
||||
|
||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||
*.out
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
inpackage: true
|
||||
inpackage: false
|
||||
with-expecter: true
|
||||
testonly: true
|
||||
keeptree: false
|
||||
testonly: false
|
||||
keeptree: true
|
||||
|
|
2
go.mod
2
go.mod
|
@ -8,6 +8,7 @@ require (
|
|||
github.com/spf13/cobra v1.6.1
|
||||
github.com/spf13/pflag v1.0.5
|
||||
github.com/spf13/viper v1.12.0
|
||||
github.com/stretchr/testify v1.8.2
|
||||
)
|
||||
|
||||
require (
|
||||
|
@ -30,7 +31,6 @@ require (
|
|||
github.com/spf13/cast v1.5.0 // indirect
|
||||
github.com/spf13/jwalterweatherman v1.1.0 // indirect
|
||||
github.com/stretchr/objx v0.5.0 // indirect
|
||||
github.com/stretchr/testify v1.8.1 // indirect
|
||||
github.com/subosito/gotenv v1.4.1 // indirect
|
||||
golang.org/x/mod v0.8.0 // indirect
|
||||
golang.org/x/sys v0.5.0 // indirect
|
||||
|
|
4
go.sum
4
go.sum
|
@ -191,8 +191,8 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
|
|||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
|
||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
|
||||
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/subosito/gotenv v1.4.1 h1:jyEFiXpy21Wm81FBN71l9VoMMV8H8jG+qIK3GCpY6Qs=
|
||||
github.com/subosito/gotenv v1.4.1/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0=
|
||||
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
|
|
|
@ -35,7 +35,7 @@ func NewPRNitter(cli PullReviewCreator, cfg *GiteaPRConfig) *prNitter {
|
|||
}
|
||||
}
|
||||
|
||||
//go:generate mockery --name PullReviewCreator
|
||||
//go:generate mockery --name PullReviewCreator --filename pull_review_creator.mock.go
|
||||
type PullReviewCreator interface {
|
||||
CreatePullReview(owner, repo string, index int64, opt gitea.CreatePullReviewOptions) (*gitea.PullReview, *gitea.Response, error)
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ func (p prNitter) Report(report *report.Data, issues []result.Issue) error {
|
|||
}
|
||||
|
||||
pullReviewOptions := gitea.CreatePullReviewOptions{
|
||||
State: "comment",
|
||||
State: gitea.ReviewStateComment,
|
||||
Body: templateBuf.String(),
|
||||
Comments: make([]gitea.CreatePullReviewComment, 0, len(issues)),
|
||||
}
|
||||
|
|
30
nitters/gitea/pr_nitter_test.go
Normal file
30
nitters/gitea/pr_nitter_test.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
package gitea_test
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"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) {
|
||||
expectedError := errors.New("error")
|
||||
creator := mocks.NewPullReviewCreator(t)
|
||||
creator.
|
||||
EXPECT().
|
||||
CreatePullReview(mock.Anything, mock.Anything, mock.Anything, mock.Anything).
|
||||
Return(nil, nil, expectedError).
|
||||
Times(1)
|
||||
|
||||
p := gitea.NewPRNitter(creator, &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)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue