diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..c14a2974a --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +go.sum \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 230439a49..e9c415f4f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,7 +24,9 @@ matrix: - go: "1.13" env: DIRS=v3/integrations/nrecho - go: "1.13" - env: DIRS=v3/integrations/nrgin/v1 + env: + - DIRS=v3/integrations/nrgin/v1 + - TESTMASTER=github.com/gin-gonic/gin - go: "1.13" env: DIRS=v3/integrations/nrgorilla/v1 - go: "1.13" @@ -34,13 +36,17 @@ matrix: - go: "1.13" env: DIRS=v3/integrations/nrpkgerrors - go: "1.13" - env: DIRS=v3/integrations/nrlambda + env: + - DIRS=v3/integrations/nrlambda + - TESTMASTER=github.com/aws/aws-lambda-go - go: "1.13" env: DIRS=v3/integrations/nrmysql - go: "1.13" env: DIRS=v3/integrations/nrpq - go: "1.13" - env: DIRS=v3/integrations/nrsqlite3 + env: + - DIRS=v3/integrations/nrsqlite3 + - TESTMASTER=github.com/mattn/go-sqlite3 - go: "1.13" env: DIRS=v3/integrations/nrgrpc # As of October 2019, errors result from go get -u github.com/micro/go-micro diff --git a/build-script.sh b/build-script.sh index 1fc470e59..042556f2e 100755 --- a/build-script.sh +++ b/build-script.sh @@ -10,12 +10,23 @@ for dir in $DIRS do cd "$pwd/$dir" - # This can be removed once we add go.mod files for everything. - go get -t ./... + if [ -f "go.mod" ]; then + go mod edit -replace github.com/newrelic/go-agent/v3=$pwd/v3 + else + go get -t ./... + fi go test -race -benchtime=1ms -bench=. ./... go vet ./... + # Test again against the latest version of the dependencies to ensure that + # our instrumentation is up to date. TODO: Perhaps it is possible to + # upgrade all go.mod dependencies to latest master with a go command. + if [ -n "$TESTMASTER" ]; then + go get -u "$TESTMASTER@master" + go test -race -benchtime=1ms -bench=. ./... + fi + if [[ -n "$(go version | grep $LATEST_VERSION)" ]]; then # golint requires a supported version of Go, which in practice is currently 1.9+. # See: https://github.com/golang/lint#installation diff --git a/v3/go.mod b/v3/go.mod new file mode 100644 index 000000000..3b2215053 --- /dev/null +++ b/v3/go.mod @@ -0,0 +1,3 @@ +module github.com/newrelic/go-agent/v3 + +go 1.13 diff --git a/v3/integrations/nrgin/v1/go.mod b/v3/integrations/nrgin/v1/go.mod new file mode 100644 index 000000000..5e355d698 --- /dev/null +++ b/v3/integrations/nrgin/v1/go.mod @@ -0,0 +1,8 @@ +module github.com/newrelic/go-agent/v3/integrations/nrgin/v1 + +go 1.13 + +require ( + github.com/gin-gonic/gin v1.4.0 + github.com/newrelic/go-agent/v3 v3.0.0 +) diff --git a/v3/integrations/nrgin/v1/nrgin_test.go b/v3/integrations/nrgin/v1/nrgin_test.go index 3056f1d17..e28c34356 100644 --- a/v3/integrations/nrgin/v1/nrgin_test.go +++ b/v3/integrations/nrgin/v1/nrgin_test.go @@ -174,11 +174,21 @@ func errorStatus(c *gin.Context) { c.String(500, "an error happened") } +const ( + // The Gin.Context.Status method behavior changed with this pull + // request: https://github.com/gin-gonic/gin/pull/1606. This change + // affects our ability to instrument the response code. In Gin v1.4.0 + // and below, we always recorded a 200 status, whereas with newer Gin + // versions we now correctly capture the status. + statusFixVersion = "v1.4.0-dev" +) + func TestStatusCodes(t *testing.T) { // Test that we are correctly able to collect status code. - // This behavior changed with this pull request: https://github.com/gin-gonic/gin/pull/1606 - // In Gin v1.4.0 and below, we always recorded a 200 status, whereas with - // newer Gin versions we now correctly capture the status. + expectCode := 200 + if gin.Version == statusFixVersion { + expectCode = 500 + } app := integrationsupport.NewBasicTestApp() router := gin.Default() router.Use(Middleware(app.Application)) @@ -203,8 +213,8 @@ func TestStatusCodes(t *testing.T) { }, UserAttributes: map[string]interface{}{}, AgentAttributes: map[string]interface{}{ - "httpResponseCode": 500, - "response.statusCode": 500, + "httpResponseCode": expectCode, + "response.statusCode": expectCode, "request.method": "GET", "request.uri": "/err", "response.headers.contentType": "text/plain; charset=utf-8", @@ -219,6 +229,10 @@ func noBody(c *gin.Context) { func TestNoResponseBody(t *testing.T) { // Test that when no response body is sent (i.e. c.Writer.Write is never // called) that we still capture status code. + expectCode := 200 + if gin.Version == statusFixVersion { + expectCode = 500 + } app := integrationsupport.NewBasicTestApp() router := gin.Default() router.Use(Middleware(app.Application)) @@ -243,8 +257,8 @@ func TestNoResponseBody(t *testing.T) { }, UserAttributes: map[string]interface{}{}, AgentAttributes: map[string]interface{}{ - "httpResponseCode": 500, - "response.statusCode": 500, + "httpResponseCode": expectCode, + "response.statusCode": expectCode, "request.method": "GET", "request.uri": "/nobody", }, diff --git a/v3/integrations/nrlambda/go.mod b/v3/integrations/nrlambda/go.mod new file mode 100644 index 000000000..b699ecaf8 --- /dev/null +++ b/v3/integrations/nrlambda/go.mod @@ -0,0 +1,8 @@ +module github.com/newrelic/go-agent/v3/integrations/nrlambda + +go 1.13 + +require ( + github.com/aws/aws-lambda-go v1.11.0 + github.com/newrelic/go-agent/v3 v3.0.0 +) diff --git a/v3/integrations/nrsqlite3/go.mod b/v3/integrations/nrsqlite3/go.mod new file mode 100644 index 000000000..433e768c4 --- /dev/null +++ b/v3/integrations/nrsqlite3/go.mod @@ -0,0 +1,8 @@ +module github.com/newrelic/go-agent/v3/integrations/nrsqlite3 + +go 1.13 + +require ( + github.com/mattn/go-sqlite3 v1.0.0 + github.com/newrelic/go-agent/v3 v3.0.0 +)