Skip to content

Commit

Permalink
Add first go.mod files
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Nov 26, 2019
1 parent 6332353 commit 7635d3c
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
go.sum
12 changes: 9 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
15 changes: 13 additions & 2 deletions build-script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions v3/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/newrelic/go-agent/v3

go 1.13
8 changes: 8 additions & 0 deletions v3/integrations/nrgin/v1/go.mod
Original file line number Diff line number Diff line change
@@ -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
)
28 changes: 21 additions & 7 deletions v3/integrations/nrgin/v1/nrgin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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",
Expand All @@ -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))
Expand All @@ -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",
},
Expand Down
8 changes: 8 additions & 0 deletions v3/integrations/nrlambda/go.mod
Original file line number Diff line number Diff line change
@@ -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
)
8 changes: 8 additions & 0 deletions v3/integrations/nrsqlite3/go.mod
Original file line number Diff line number Diff line change
@@ -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
)

0 comments on commit 7635d3c

Please sign in to comment.