-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #164 from carlosms/integration-gotest
Integration tests with `go test`
- Loading branch information
Showing
11 changed files
with
328 additions
and
285 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// +build integration | ||
|
||
package server_test | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
|
||
"github.com/src-d/lookout/util/cmdtest" | ||
) | ||
|
||
type IntegrationSuite struct { | ||
cmdtest.IntegrationSuite | ||
r io.Reader | ||
w io.WriteCloser | ||
} | ||
|
||
func (suite *IntegrationSuite) sendEvent(json string) { | ||
_, err := fmt.Fprintln(suite.w, json) | ||
suite.Require().NoError(err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// +build integration | ||
|
||
package server_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/src-d/lookout/util/cmdtest" | ||
|
||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
type DummyIntegrationSuite struct { | ||
IntegrationSuite | ||
} | ||
|
||
func (suite *DummyIntegrationSuite) SetupTest() { | ||
suite.ResetDB() | ||
|
||
suite.StoppableCtx() | ||
suite.StartDummy("--files") | ||
suite.r, suite.w = suite.StartServe("--provider", "json", | ||
"-c", "../../fixtures/dummy_config.yml", "dummy-repo-url") | ||
|
||
// make sure server started correctly | ||
cmdtest.GrepTrue(suite.r, "Starting watcher") | ||
} | ||
|
||
func (suite *DummyIntegrationSuite) TearDownTest() { | ||
suite.Stop() | ||
} | ||
|
||
const successJSON = `{"event":"review", "internal_id": "1", "number": 1, "commit_revision":{"base":{"internal_repository_url":"https://github.com/src-d/lookout.git","reference_name":"refs/heads/master","hash":"66924f49aa9987273a137857c979ee5f0e709e30"},"head":{"internal_repository_url":"https://github.com/src-d/lookout.git","reference_name":"refs/heads/master","hash":"2c9f56bcb55be47cf35d40d024ec755399f699c7"}}}` | ||
|
||
func (suite *DummyIntegrationSuite) TestSuccessReview() { | ||
suite.sendEvent(successJSON) | ||
cmdtest.GrepTrue(suite.r, "processing pull request") | ||
cmdtest.GrepTrue(suite.r, `{"analyzer-name":"Dummy","file":"cmd/lookout/push.go","line":13,"text":"This line exceeded 80 bytes."}`) | ||
cmdtest.GrepTrue(suite.r, `status=success`) | ||
} | ||
|
||
func (suite *DummyIntegrationSuite) TestSkipReview() { | ||
suite.sendEvent(successJSON) | ||
cmdtest.GrepTrue(suite.r, `status=success`) | ||
|
||
suite.sendEvent(successJSON) | ||
cmdtest.GrepTrue(suite.r, `event successfully processed, skipping...`) | ||
} | ||
|
||
func (suite *DummyIntegrationSuite) TestReviewDontPost() { | ||
suite.sendEvent(successJSON) | ||
cmdtest.GrepTrue(suite.r, `status=success`) | ||
|
||
json := `{"event":"review", "internal_id": "2", "number": 1, "commit_revision":{"base":{"internal_repository_url":"https://github.com/src-d/lookout.git","reference_name":"refs/heads/master","hash":"66924f49aa9987273a137857c979ee5f0e709e30"},"head":{"internal_repository_url":"https://github.com/src-d/lookout.git","reference_name":"refs/heads/master","hash":"2c9f56bcb55be47cf35d40d024ec755399f699c7"}}}` | ||
suite.sendEvent(json) | ||
cmdtest.GrepTrue(suite.r, "processing pull request") | ||
cmdtest.GrepAndNot(suite.r, `status=success`, `posting analysis`) | ||
} | ||
|
||
func (suite *DummyIntegrationSuite) TestWrongRevision() { | ||
json := `{"event":"review", "internal_id": "3", "number": 3, "commit_revision": {"base":{"internal_repository_url":"https://github.com/src-d/lookout.git","reference_name":"refs/heads/master","hash":"0000000000000000000000000000000000000000"},"head":{"internal_repository_url":"https://github.com/src-d/lookout.git","reference_name":"refs/heads/master","hash":"0000000000000000000000000000000000000000"}}}` | ||
suite.sendEvent(json) | ||
cmdtest.GrepTrue(suite.r, `event processing failed`) | ||
} | ||
|
||
func (suite *DummyIntegrationSuite) TestSuccessPush() { | ||
successPushJSON := `{"event":"push", "internal_id": "1", "commit_revision":{"base":{"internal_repository_url":"https://github.com/src-d/lookout.git","reference_name":"refs/heads/master","hash":"66924f49aa9987273a137857c979ee5f0e709e30"},"head":{"internal_repository_url":"https://github.com/src-d/lookout.git","reference_name":"refs/heads/master","hash":"2c9f56bcb55be47cf35d40d024ec755399f699c7"}}}` | ||
suite.sendEvent(successPushJSON) | ||
cmdtest.GrepTrue(suite.r, "processing push") | ||
cmdtest.GrepTrue(suite.r, "comments can belong only to review event but 1 is given") | ||
cmdtest.GrepTrue(suite.r, `status=success`) | ||
} | ||
|
||
func TestDummyIntegrationSuite(t *testing.T) { | ||
suite.Run(t, new(DummyIntegrationSuite)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// +build integration | ||
|
||
package server_test | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"testing" | ||
|
||
"github.com/src-d/lookout" | ||
"github.com/src-d/lookout/util/cmdtest" | ||
"github.com/src-d/lookout/util/grpchelper" | ||
log "gopkg.in/src-d/go-log.v1" | ||
|
||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
type errAnalyzer struct{} | ||
|
||
func (a *errAnalyzer) NotifyReviewEvent(ctx context.Context, e *lookout.ReviewEvent) (*lookout.EventResponse, error) { | ||
return nil, errors.New("review error") | ||
} | ||
|
||
func (a *errAnalyzer) NotifyPushEvent(ctx context.Context, e *lookout.PushEvent) (*lookout.EventResponse, error) { | ||
return nil, errors.New("push error") | ||
} | ||
|
||
type ErrorAnalyzerIntegrationSuite struct { | ||
IntegrationSuite | ||
} | ||
|
||
func (suite *ErrorAnalyzerIntegrationSuite) startAnalyzer(ctx context.Context, a lookout.AnalyzerServer) error { | ||
log.DefaultFactory = &log.LoggerFactory{ | ||
Level: log.ErrorLevel, | ||
} | ||
log.DefaultLogger = log.New(log.Fields{"app": "test"}) | ||
|
||
server := grpchelper.NewServer() | ||
lookout.RegisterAnalyzerServer(server, a) | ||
|
||
lis, err := grpchelper.Listen("ipv4://localhost:10302") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
go server.Serve(lis) | ||
go func() { | ||
<-ctx.Done() | ||
server.Stop() | ||
}() | ||
return nil | ||
} | ||
|
||
func (suite *ErrorAnalyzerIntegrationSuite) SetupTest() { | ||
suite.ResetDB() | ||
|
||
suite.StoppableCtx() | ||
suite.startAnalyzer(suite.Ctx, &errAnalyzer{}) | ||
suite.r, suite.w = suite.StartServe("--provider", "json", | ||
"-c", "../../fixtures/dummy_config.yml", "dummy-repo-url") | ||
|
||
// make sure server started correctly | ||
cmdtest.GrepTrue(suite.r, "Starting watcher") | ||
} | ||
|
||
func (suite *ErrorAnalyzerIntegrationSuite) TearDownTest() { | ||
suite.Stop() | ||
} | ||
|
||
func (suite *ErrorAnalyzerIntegrationSuite) TestAnalyzerErr() { | ||
suite.sendEvent(successJSON) | ||
|
||
cmdtest.GrepTrue(suite.r, `msg="analysis failed" analyzer=Dummy app=lookout error="rpc error: code = Unknown desc = review error"`) | ||
} | ||
|
||
func TestErrorAnalyzerIntegrationSuite(t *testing.T) { | ||
suite.Run(t, new(ErrorAnalyzerIntegrationSuite)) | ||
} |
Oops, something went wrong.