-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
go.mongodb.org/mongo-driver/mongo: update to v1.1.0 (#489)
This change updates the MongoDB integration to use the latest stable and removes the hard coded dependency. Fixes #488
- Loading branch information
Showing
1,220 changed files
with
145 additions
and
202,743 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
132 changes: 132 additions & 0 deletions
132
contrib/go.mongodb.org/mongo-driver/mongo/mongo_test.go
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,132 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed | ||
// under the Apache License Version 2.0. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2016-2019 Datadog, Inc. | ||
|
||
package mongo | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"testing" | ||
"time" | ||
|
||
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/ext" | ||
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/mocktracer" | ||
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer" | ||
"gopkg.in/DataDog/dd-trace-go.v1/internal/globalconfig" | ||
|
||
"go.mongodb.org/mongo-driver/bson" | ||
"go.mongodb.org/mongo-driver/mongo" | ||
"go.mongodb.org/mongo-driver/mongo/options" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
_, ok := os.LookupEnv("INTEGRATION") | ||
if !ok { | ||
fmt.Println("--- SKIP: to enable integration test, set the INTEGRATION environment variable") | ||
os.Exit(0) | ||
} | ||
os.Exit(m.Run()) | ||
} | ||
|
||
func Test(t *testing.T) { | ||
mt := mocktracer.Start() | ||
defer mt.Stop() | ||
|
||
hostname, port := "localhost", "27017" | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*3) | ||
defer cancel() | ||
|
||
span, ctx := tracer.StartSpanFromContext(ctx, "mongodb-test") | ||
|
||
addr := fmt.Sprintf("mongodb://localhost:27017/?connect=direct") | ||
opts := options.Client() | ||
opts.Monitor = NewMonitor() | ||
opts.ApplyURI(addr) | ||
client, err := mongo.Connect(ctx, opts) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
client. | ||
Database("test-database"). | ||
Collection("test-collection"). | ||
InsertOne(ctx, bson.D{{Key: "test-item", Value: "test-value"}}) | ||
|
||
span.Finish() | ||
|
||
spans := mt.FinishedSpans() | ||
assert.Len(t, spans, 2) | ||
assert.Equal(t, spans[0].TraceID(), spans[1].TraceID()) | ||
|
||
s := spans[0] | ||
assert.Equal(t, "mongo", s.Tag(ext.ServiceName)) | ||
assert.Equal(t, "mongo.insert", s.Tag(ext.ResourceName)) | ||
assert.Equal(t, hostname, s.Tag(ext.PeerHostname)) | ||
assert.Equal(t, port, s.Tag(ext.PeerPort)) | ||
assert.Contains(t, s.Tag(ext.DBStatement), `"test-item":"test-value"`) | ||
assert.Equal(t, "test-database", s.Tag(ext.DBInstance)) | ||
assert.Equal(t, "mongo", s.Tag(ext.DBType)) | ||
} | ||
|
||
func TestAnalyticsSettings(t *testing.T) { | ||
assertRate := func(t *testing.T, mt mocktracer.Tracer, rate interface{}, opts ...Option) { | ||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*3) | ||
defer cancel() | ||
|
||
addr := fmt.Sprintf("mongodb://localhost:27017/?connect=direct") | ||
mongopts := options.Client() | ||
mongopts.Monitor = NewMonitor(opts...) | ||
mongopts.ApplyURI(addr) | ||
client, err := mongo.Connect(ctx, mongopts) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
client. | ||
Database("test-database"). | ||
Collection("test-collection"). | ||
InsertOne(ctx, bson.D{{Key: "test-item", Value: "test-value"}}) | ||
|
||
spans := mt.FinishedSpans() | ||
assert.Len(t, spans, 1) | ||
s := spans[0] | ||
assert.Equal(t, rate, s.Tag(ext.EventSampleRate)) | ||
} | ||
|
||
t.Run("defaults", func(t *testing.T) { | ||
mt := mocktracer.Start() | ||
defer mt.Stop() | ||
|
||
assertRate(t, mt, nil) | ||
}) | ||
|
||
t.Run("enabled", func(t *testing.T) { | ||
mt := mocktracer.Start() | ||
defer mt.Stop() | ||
|
||
assertRate(t, mt, 1.0, WithAnalytics(true)) | ||
}) | ||
|
||
t.Run("disabled", func(t *testing.T) { | ||
mt := mocktracer.Start() | ||
defer mt.Stop() | ||
|
||
assertRate(t, mt, nil, WithAnalytics(false)) | ||
}) | ||
|
||
t.Run("override", func(t *testing.T) { | ||
mt := mocktracer.Start() | ||
defer mt.Stop() | ||
|
||
rate := globalconfig.AnalyticsRate() | ||
defer globalconfig.SetAnalyticsRate(rate) | ||
globalconfig.SetAnalyticsRate(0.4) | ||
|
||
assertRate(t, mt, 0.23, WithAnalyticsRate(0.23)) | ||
}) | ||
} |
File renamed without changes.
Oops, something went wrong.