Author: Guillem Jover <gjover@sipwise.com>
Forwarded: no
Description: Do not require a running MongoDB server to run the test suite.

---
 examples/documentation_examples/examples_test.go |   20 ++++++++++++++++++++
 mongo/client_options_test.go                     |    5 +++++
 mongo/client_test.go                             |    5 +++++
 mongo/gridfs/gridfs_test.go                      |    5 +++++
 mongo/with_transactions_test.go                  |    5 +++++
 5 files changed, 40 insertions(+)

--- a/examples/documentation_examples/examples_test.go
+++ b/examples/documentation_examples/examples_test.go
@@ -27,6 +27,10 @@ import (
 )
 
 func TestDocumentationExamples(t *testing.T) {
+	if os.Getenv("TEST_MONGODB_SERVER") == "" {
+		t.Skip()
+	}
+
 	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
 	defer cancel()
 
@@ -63,6 +67,10 @@ func TestDocumentationExamples(t *testin
 }
 
 func TestAggregationExamples(t *testing.T) {
+	if os.Getenv("TEST_MONGODB_SERVER") == "" {
+		t.Skip()
+	}
+
 	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
 	defer cancel()
 
@@ -81,6 +89,10 @@ func TestAggregationExamples(t *testing.
 }
 
 func TestTransactionExamples(t *testing.T) {
+	if os.Getenv("TEST_MONGODB_SERVER") == "" {
+		t.Skip()
+	}
+
 	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
 	defer cancel()
 	topo := createTopology(t)
@@ -97,6 +109,10 @@ func TestTransactionExamples(t *testing.
 }
 
 func TestChangeStreamExamples(t *testing.T) {
+	if os.Getenv("TEST_MONGODB_SERVER") == "" {
+		t.Skip()
+	}
+
 	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
 	defer cancel()
 	topo := createTopology(t)
@@ -113,6 +129,10 @@ func TestChangeStreamExamples(t *testing
 }
 
 func TestCausalConsistencyExamples(t *testing.T) {
+	if os.Getenv("TEST_MONGODB_SERVER") == "" {
+		t.Skip()
+	}
+
 	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
 	defer cancel()
 	cs := testutil.ConnString(t)
--- a/mongo/client_options_test.go
+++ b/mongo/client_options_test.go
@@ -9,6 +9,7 @@ package mongo
 import (
 	"context"
 	"net"
+	"os"
 	"sync/atomic"
 	"testing"
 
@@ -19,6 +20,10 @@ import (
 )
 
 func TestClientOptions_CustomDialer(t *testing.T) {
+	if os.Getenv("TEST_MONGODB_SERVER") == "" {
+		t.Skip()
+	}
+
 	td := &testDialer{d: &net.Dialer{}}
 	cs := testutil.ConnString(t)
 	opts := options.Client().ApplyURI(cs.String()).SetDialer(td)
--- a/mongo/client_test.go
+++ b/mongo/client_test.go
@@ -10,6 +10,7 @@ import (
 	"context"
 	"errors"
 	"math"
+	"os"
 	"testing"
 	"time"
 
@@ -264,6 +265,10 @@ func TestClient(t *testing.T) {
 		})
 	})
 	t.Run("endSessions", func(t *testing.T) {
+		if os.Getenv("TEST_MONGODB_SERVER") == "" {
+			t.Skip()
+		}
+
 		cs := testutil.ConnString(t)
 		originalBatchSize := endSessionsBatchSize
 		endSessionsBatchSize = 2
--- a/mongo/gridfs/gridfs_test.go
+++ b/mongo/gridfs/gridfs_test.go
@@ -8,6 +8,7 @@ package gridfs
 
 import (
 	"context"
+	"os"
 	"testing"
 
 	"go.mongodb.org/mongo-driver/event"
@@ -24,6 +25,10 @@ var (
 )
 
 func TestGridFS(t *testing.T) {
+	if os.Getenv("TEST_MONGODB_SERVER") == "" {
+		t.Skip()
+	}
+
 	cs := testutil.ConnString(t)
 	poolMonitor := &event.PoolMonitor{
 		Event: func(evt *event.PoolEvent) {
--- a/mongo/with_transactions_test.go
+++ b/mongo/with_transactions_test.go
@@ -10,6 +10,7 @@ import (
 	"context"
 	"errors"
 	"math"
+	"os"
 	"strconv"
 	"strings"
 	"testing"
@@ -45,6 +46,10 @@ func (we wrappedError) Unwrap() error {
 }
 
 func TestConvenientTransactions(t *testing.T) {
+	if os.Getenv("TEST_MONGODB_SERVER") == "" {
+		t.Skip()
+	}
+
 	client := setupConvenientTransactions(t)
 	db := client.Database("TestConvenientTransactions")
 	dbAdmin := client.Database("admin")
