Skip to content

Commit d6e3a0c

Browse files
committed
Automate Atlas connectivity tests
GODRIVER-145 Change-Id: I724b9b4316d86a7881765549fa45b2441aa511ef
1 parent 3f7dd57 commit d6e3a0c

File tree

3 files changed

+113
-0
lines changed

3 files changed

+113
-0
lines changed

.evergreen/config.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,37 @@ functions:
326326
export PATH="${GCC_PATH}:${GO_DIST}/bin:$PATH"
327327
MONGO_GO_DRIVER_COMPRESSOR="${MONGO_GO_DRIVER_COMPRESSOR}" make -s evg-test-auth
328328
329+
run-atlas-test:
330+
- command: shell.exec
331+
type: test
332+
params:
333+
working_dir: src/go.mongodb.org/mongo-driver
334+
script: |
335+
# DO NOT ECHO WITH XTRACE (which PREPARE_SHELL does)
336+
if [ "Windows_NT" = "$OS" ]; then
337+
export GOPATH=$(cygpath -w $(dirname $(dirname $(dirname `pwd`))))
338+
export GOCACHE=$(cygpath -w "$(pwd)/.cache")
339+
else
340+
export GOPATH=$(dirname $(dirname $(dirname `pwd`)))
341+
export GOCACHE="$(pwd)/.cache"
342+
fi;
343+
export GOPATH="$GOPATH"
344+
export GOROOT="${GO_DIST}"
345+
export GOCACHE="$GOCACHE"
346+
export PATH="${GCC_PATH}:${GO_DIST}/bin:$PATH"
347+
export ATLAS_FREE="${atlas_free_tier_uri}"
348+
export ATLAS_REPLSET="${atlas_replica_set_uri}"
349+
export ATLAS_SHARD="${atlas_sharded_uri}"
350+
export ATLAS_TLS11="${atlas_tls_v11_uri}"
351+
export ATLAS_TLS12="${atlas_tls_v12_uri}"
352+
export ATLAS_FREE_SRV="${atlas_free_tier_uri_srv}"
353+
export ATLAS_REPLSET_SRV="${atlas_replica_set_uri_srv}"
354+
export ATLAS_SHARD_SRV="${atlas_sharded_uri_srv}"
355+
export ATLAS_TLS11_SRV="${atlas_tls_v11_uri_srv}"
356+
export ATLAS_TLS12_SRV="${atlas_tls_v12_uri_srv}"
357+
make -s evg-test-atlas
358+
359+
329360
pre:
330361
- func: fetch-source
331362
- func: prepare-resources
@@ -655,6 +686,10 @@ tasks:
655686
targets: "build"
656687
BUILD_ENV: "GOARCH=ppc64le"
657688

689+
- name: "atlas-test"
690+
commands:
691+
- func: "run-atlas-test"
692+
658693
axes:
659694
- id: version
660695
display_name: MongoDB Version
@@ -753,6 +788,15 @@ buildvariants:
753788
tasks:
754789
- name: ".compile-check"
755790

791+
- name: atlas-test
792+
display_name: "Atlas test"
793+
run_on:
794+
- ubuntu1604-build
795+
expansions:
796+
GO_DIST: "/opt/golang/go1.12"
797+
tasks:
798+
- name: "atlas-test"
799+
756800
- matrix_name: "tests-legacy-auth-ssl"
757801
matrix_spec: { version: ["2.6", "3.0"], os-ssl-legacy: "*" }
758802
display_name: "${version} ${os-ssl-legacy}"

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ EXAMPLES_PKGS = $(shell etc/list_pkgs.sh ./examples)
1010
EXAMPLES_TEST_PKGS = $(shell etc/list_test_pkgs.sh ./examples)
1111
PKGS = $(BSON_PKGS) $(MONGO_PKGS) $(UNSTABLE_PKGS) $(TAG_PKG) $(EXAMPLES_PKGS)
1212
TEST_PKGS = $(BSON_TEST_PKGS) $(MONGO_TEST_PKGS) $(UNSTABLE_TEST_PKGS) $(TAG_PKG) $(EXAMPLES_TEST_PKGS)
13+
ATLAS_URIS = "$(ATLAS_FREE)" "$(ATLAS_REPLSET)" "$(ATLAS_SHARD)" "$(ATLAS_TLS11)" "$(ATLAS_TLS12)" "$(ATLAS_FREE_SRV)" "$(ATLAS_REPLSET_SRV)" "$(ATLAS_SHARD_SRV)" "$(ATLAS_TLS11_SRV)" "$(ATLAS_TLS12_SRV)"
1314

1415
TEST_TIMEOUT = 600
1516

@@ -125,6 +126,10 @@ evg-test:
125126
evg-test-auth:
126127
go run -tags gssapi ./x/mongo/driver/examples/count/main.go -uri $(MONGODB_URI)
127128

129+
.PHONY: evg-test-atlas
130+
evg-test-atlas:
131+
go run ./mongo/testatlas/main.go $(ATLAS_URIS)
132+
128133
# benchmark specific targets and support
129134
perf:driver-test-data.tar.gz
130135
tar -zxf $< $(if $(eq $(UNAME_S),Darwin),-s , --transform=s)/data/perf/

mongo/testatlas/main.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright (C) MongoDB, Inc. 2017-present.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
// not use this file except in compliance with the License. You may obtain
5+
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
7+
package main
8+
9+
import (
10+
"context"
11+
"flag"
12+
"log"
13+
14+
"go.mongodb.org/mongo-driver/bson"
15+
"go.mongodb.org/mongo-driver/mongo"
16+
"go.mongodb.org/mongo-driver/mongo/options"
17+
)
18+
19+
func main() {
20+
flag.Parse()
21+
uris := flag.Args()
22+
23+
for _, uri := range uris {
24+
ctx := context.Background()
25+
26+
client, err := mongo.Connect(ctx, options.Client().ApplyURI(uri))
27+
if err != nil {
28+
log.Fatal("failed creating and connecting to client: %v", err)
29+
}
30+
31+
db := client.Database("test")
32+
defer func() {
33+
err := db.Drop(ctx)
34+
if err != nil {
35+
log.Fatal("failed dropping database: %v", err)
36+
}
37+
38+
err = client.Disconnect(ctx)
39+
if err != nil {
40+
log.Fatal("failed disconnecting from client: %v", err)
41+
}
42+
}()
43+
44+
coll := db.Collection("test")
45+
46+
err = db.RunCommand(
47+
ctx,
48+
bson.D{{"isMaster", 1}},
49+
).Err()
50+
if err != nil {
51+
log.Fatalf("failed executing isMaster command: %v", err)
52+
}
53+
54+
_, err = coll.InsertOne(ctx, bson.D{{"x", 1}})
55+
if err != nil {
56+
log.Fatalf("failed executing insertOne command: %v", err)
57+
}
58+
59+
res := coll.FindOne(ctx, bson.D{{"x", 1}})
60+
if res.Err() != nil {
61+
log.Fatalf("failed executing findOne command: %v", res.Err())
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)