Skip to content

Commit

Permalink
Merge pull request #570 from dpordomingo/from-PR
Browse files Browse the repository at this point in the history
Signed-off-by: David Pordomingo <[email protected]>
  • Loading branch information
dpordomingo authored Feb 28, 2019
2 parents 69f73be + 4020ce1 commit 75f3ff0
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 56 additions & 2 deletions cmd/server-test/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@ import (
"encoding/json"
"fmt"
"io"
"strconv"

"github.com/src-d/lookout"
fixtures "github.com/src-d/lookout-test-fixtures"
"github.com/src-d/lookout/util/cmdtest"
"github.com/src-d/lookout/util/grpchelper"
log "gopkg.in/src-d/go-log.v1"

"github.com/src-d/lookout-test-fixtures"
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-log.v1"
"gopkg.in/src-d/lookout-sdk.v0/pb"
)

const dummyConfigFile = "../../fixtures/dummy_config.yml"

type IntegrationSuite struct {
cmdtest.IntegrationSuite
r io.Reader
Expand Down Expand Up @@ -76,6 +81,55 @@ func startMockAnalyzer(ctx context.Context, a mockAnalyzer) error {
return nil
}

func castPullRequest(fixture *fixtures.Fixture) (*jsonReviewEvent, error) {
pr := fixture.GetPR()

baseRepoCloneUrl := pr.GetBase().GetRepo().GetCloneURL()
baseRepoInfo, err := pb.ParseRepositoryInfo(baseRepoCloneUrl)
if err != nil {
return nil, err
}

headRepoCloneUrl := pr.GetHead().GetRepo().GetCloneURL()
headRepoInfo, err := pb.ParseRepositoryInfo(headRepoCloneUrl)
if err != nil {
return nil, err
}

event := pb.ReviewEvent{}

event.Provider = "github"
event.InternalID = strconv.FormatInt(pr.GetID(), 10)

event.Number = uint32(pr.GetNumber())
event.RepositoryID = uint32(pr.GetHead().GetRepo().GetID())

sourceRefName := fmt.Sprintf("refs/heads/%s", pr.GetHead().GetRef())
event.Source = lookout.ReferencePointer{
InternalRepositoryURL: headRepoInfo.CloneURL,
ReferenceName: plumbing.ReferenceName(sourceRefName),
Hash: pr.GetHead().GetSHA(),
}

baseRefName := fmt.Sprintf("refs/heads/%s", pr.GetBase().GetRef())
event.Base = lookout.ReferencePointer{
InternalRepositoryURL: baseRepoInfo.CloneURL,
ReferenceName: plumbing.ReferenceName(baseRefName),
Hash: pr.GetBase().GetSHA(),
}

headRefName := fmt.Sprintf("refs/pull/%d/head", pr.GetNumber())
event.Head = lookout.ReferencePointer{
InternalRepositoryURL: baseRepoInfo.CloneURL,
ReferenceName: plumbing.ReferenceName(headRefName),
Hash: pr.GetHead().GetSHA(),
}

event.IsMergeable = pr.GetMergeable()

return &jsonReviewEvent{ReviewEvent: &event}, nil
}

var longLineFixture = fixtures.GetByName("new-go-file-too-long-line")

var successEvent = &jsonReviewEvent{
Expand Down
2 changes: 0 additions & 2 deletions cmd/server-test/dummy_analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"gopkg.in/src-d/lookout-sdk.v0/pb"
)

const dummyConfigFile = "../../fixtures/dummy_config.yml"

type DummyIntegrationSuite struct {
IntegrationSuite
}
Expand Down
49 changes: 49 additions & 0 deletions cmd/server-test/review_from_fork_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// +build integration

package server_test

import (
"testing"
"time"

"github.com/src-d/lookout-test-fixtures"
"github.com/stretchr/testify/suite"
)

func TestReviewPrFromForkIntegrationSuite(t *testing.T) {
suite.Run(t, new(reviewPrFromForkIntegrationSuite))
}

type reviewPrFromForkIntegrationSuite struct {
IntegrationSuite
}

func (suite *reviewPrFromForkIntegrationSuite) SetupTest() {
suite.ResetDB()

suite.StoppableCtx()
suite.r, suite.w = suite.StartLookoutd(dummyConfigFile)

suite.StartDummy("--files")
suite.GrepTrue(suite.r, `msg="connection state changed to 'READY'" addr="ipv4://localhost:9930" analyzer=Dummy`)
}

func (suite *reviewPrFromForkIntegrationSuite) TearDownTest() {
// TODO: for integration tests with RabbitMQ we wait a bit so the queue
// is depleted. Ideally this would be done with something similar to ResetDB
time.Sleep(5 * time.Second)
suite.Stop()
}

func (suite *reviewPrFromForkIntegrationSuite) TestReview() {
fixture := fixtures.GetByName("pr-from-fork")
jsonReviewEvent, err := castPullRequest(fixture)
suite.NoError(err)

expectedComments := []string{
`{"analyzer-name":"Dummy","file":"javascript.js",`,
}

suite.sendEvent(jsonReviewEvent.String())
suite.GrepAll(suite.r, expectedComments)
}
50 changes: 48 additions & 2 deletions vendor/github.com/src-d/lookout-test-fixtures/bindata.go

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions vendor/github.com/src-d/lookout-test-fixtures/main.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 75f3ff0

Please sign in to comment.