diff options
Diffstat (limited to 'src/mongo/gotools/src/github.com/mongodb/mongo-tools/common')
68 files changed, 435 insertions, 220 deletions
diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/archive/multiplexer_roundtrip_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/archive/multiplexer_roundtrip_test.go index 8e6cabb6608..62bd54eb570 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/archive/multiplexer_roundtrip_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/archive/multiplexer_roundtrip_test.go @@ -16,6 +16,7 @@ import ( "github.com/mongodb/mongo-tools/common/db" "github.com/mongodb/mongo-tools/common/intents" + "github.com/mongodb/mongo-tools/common/testtype" . "github.com/smartystreets/goconvey/convey" "gopkg.in/mgo.v2/bson" ) @@ -61,6 +62,7 @@ type testNotifier struct{} func (n *testNotifier) Notify() {} func TestBasicMux(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) var err error Convey("with 10000 docs in each of five collections", t, func() { @@ -123,6 +125,7 @@ func TestBasicMux(t *testing.T) { } func TestParallelMux(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("parallel mux/demux over a pipe", t, func() { readPipe, writePipe, err := os.Pipe() So(err, ShouldBeNil) diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/archive/parser_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/archive/parser_test.go index 61f4ee4fd07..ef92ac0922f 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/archive/parser_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/archive/parser_test.go @@ -12,6 +12,7 @@ import ( "io" "testing" + "github.com/mongodb/mongo-tools/common/testtype" . "github.com/smartystreets/goconvey/convey" "gopkg.in/mgo.v2/bson" ) @@ -52,6 +53,7 @@ var term = []byte{0xFF, 0xFF, 0xFF, 0xFF} var notTerm = []byte{0xFF, 0xFF, 0xFF, 0xFE} func TestParsing(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("With a parser with a simple parser consumer", t, func() { tc := &testConsumer{} diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/archive/prelude_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/archive/prelude_test.go index 60e9eebeb93..d32e8458eb2 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/archive/prelude_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/archive/prelude_test.go @@ -11,10 +11,12 @@ import ( . "github.com/smartystreets/goconvey/convey" // "gopkg.in/mgo.v2/bson" + "github.com/mongodb/mongo-tools/common/testtype" "testing" ) func TestPrelude(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) var err error Convey("WritePrelude/ReadPrelude roundtrip", t, func() { diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/converter_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/converter_test.go index b3d694befdf..e43ae011f0f 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/converter_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/converter_test.go @@ -20,7 +20,7 @@ import ( ) func TestObjectIdBSONToJSON(t *testing.T) { - testtype.VerifyTestType(t, testtype.UnitTestType) + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("Converting a BSON ObjectId", t, func() { Convey("that is valid to JSON should produce a json.ObjectId", func() { @@ -39,7 +39,7 @@ func TestObjectIdBSONToJSON(t *testing.T) { } func TestArraysBSONToJSON(t *testing.T) { - testtype.VerifyTestType(t, testtype.UnitTestType) + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("Converting BSON arrays to JSON arrays", t, func() { Convey("should work for empty arrays", func() { @@ -94,7 +94,7 @@ func TestArraysBSONToJSON(t *testing.T) { } func TestDateBSONToJSON(t *testing.T) { - testtype.VerifyTestType(t, testtype.UnitTestType) + testtype.SkipUnlessTestType(t, testtype.UnitTestType) timeNow := time.Now() secs := int64(timeNow.Unix()) @@ -138,7 +138,7 @@ func TestDateBSONToJSON(t *testing.T) { } func TestMaxKeyBSONToJSON(t *testing.T) { - testtype.VerifyTestType(t, testtype.UnitTestType) + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("Converting a BSON Maxkey to JSON", t, func() { Convey("should produce a json.MaxKey", func() { @@ -153,7 +153,7 @@ func TestMaxKeyBSONToJSON(t *testing.T) { } func TestMinKeyBSONToJSON(t *testing.T) { - testtype.VerifyTestType(t, testtype.UnitTestType) + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("Converting a BSON Maxkey to JSON", t, func() { Convey("should produce a json.MinKey", func() { @@ -168,7 +168,7 @@ func TestMinKeyBSONToJSON(t *testing.T) { } func Test64BitIntBSONToJSON(t *testing.T) { - testtype.VerifyTestType(t, testtype.UnitTestType) + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("Converting a BSON int64 to JSON", t, func() { Convey("should produce a json.NumberLong", func() { @@ -184,7 +184,7 @@ func Test64BitIntBSONToJSON(t *testing.T) { } func Test32BitIntBSONToJSON(t *testing.T) { - testtype.VerifyTestType(t, testtype.UnitTestType) + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("Converting a BSON int32 integer to JSON", t, func() { Convey("should produce a json.NumberInt", func() { @@ -200,7 +200,7 @@ func Test32BitIntBSONToJSON(t *testing.T) { } func TestRegExBSONToJSON(t *testing.T) { - testtype.VerifyTestType(t, testtype.UnitTestType) + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("Converting a BSON Regular Expression (= /decision/gi) to JSON", t, func() { Convey("should produce a json.RegExp", func() { @@ -216,7 +216,7 @@ func TestRegExBSONToJSON(t *testing.T) { } func TestUndefinedValueBSONToJSON(t *testing.T) { - testtype.VerifyTestType(t, testtype.UnitTestType) + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("Converting a BSON Undefined type to JSON", t, func() { Convey("should produce a json.Undefined", func() { @@ -231,7 +231,7 @@ func TestUndefinedValueBSONToJSON(t *testing.T) { } func TestDBRefBSONToJSON(t *testing.T) { - testtype.VerifyTestType(t, testtype.UnitTestType) + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("Converting BSON DBRef to JSON", t, func() { Convey("should produce a json.DBRef", func() { @@ -247,7 +247,7 @@ func TestDBRefBSONToJSON(t *testing.T) { } func TestTimestampBSONToJSON(t *testing.T) { - testtype.VerifyTestType(t, testtype.UnitTestType) + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("Converting a BSON Timestamp to JSON", t, func() { Convey("should produce a json.Timestamp", func() { @@ -264,7 +264,7 @@ func TestTimestampBSONToJSON(t *testing.T) { } func TestBinaryBSONToJSON(t *testing.T) { - testtype.VerifyTestType(t, testtype.UnitTestType) + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("Converting BSON Binary data to JSON", t, func() { Convey("should produce a json.BinData", func() { @@ -282,7 +282,7 @@ func TestBinaryBSONToJSON(t *testing.T) { } func TestGenericBytesBSONToJSON(t *testing.T) { - testtype.VerifyTestType(t, testtype.UnitTestType) + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("Converting Go bytes to JSON", t, func() { Convey("should produce a json.BinData with Type=0x00 (Generic)", func() { @@ -299,7 +299,7 @@ func TestGenericBytesBSONToJSON(t *testing.T) { } func TestUnknownBSONTypeToJSON(t *testing.T) { - testtype.VerifyTestType(t, testtype.UnitTestType) + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("Converting an unknown BSON type to JSON", t, func() { Convey("should produce an error", func() { @@ -310,7 +310,7 @@ func TestUnknownBSONTypeToJSON(t *testing.T) { } func TestDBPointerBSONToJSON(t *testing.T) { - testtype.VerifyTestType(t, testtype.UnitTestType) + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("Converting BSON DBPointer to JSON", t, func() { Convey("should produce a json.DBPointer", func() { @@ -326,7 +326,7 @@ func TestDBPointerBSONToJSON(t *testing.T) { } func TestJSCodeBSONToJSON(t *testing.T) { - testtype.VerifyTestType(t, testtype.UnitTestType) + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("Converting BSON Javascript code to JSON", t, func() { Convey("should produce a json.Javascript", func() { diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/date_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/date_test.go index 5c8200b9cc1..f929c35c12b 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/date_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/date_test.go @@ -9,12 +9,14 @@ package bsonutil import ( "fmt" "github.com/mongodb/mongo-tools/common/json" + "github.com/mongodb/mongo-tools/common/testtype" . "github.com/smartystreets/goconvey/convey" "testing" "time" ) func TestDateValue(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("When converting JSON with Date values", t, func() { diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/marshal_d_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/marshal_d_test.go index 0ee5e02d61c..9961e488b18 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/marshal_d_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/marshal_d_test.go @@ -8,6 +8,7 @@ package bsonutil import ( "encoding/json" + "github.com/mongodb/mongo-tools/common/testtype" . "github.com/smartystreets/goconvey/convey" "gopkg.in/mgo.v2/bson" "strings" @@ -15,6 +16,7 @@ import ( ) func TestMarshalDMarshalJSON(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("With a valid bson.D", t, func() { testD := bson.D{ @@ -82,6 +84,7 @@ func TestMarshalDMarshalJSON(t *testing.T) { } func TestFindValueByKey(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("Given a bson.D document and a specific key", t, func() { subDocument := &bson.D{ bson.DocElem{Name: "field4", Value: "c"}, @@ -110,6 +113,7 @@ func TestFindValueByKey(t *testing.T) { } func TestEscapedKey(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("Given a bson.D document with a key that requires escaping", t, func() { document := bson.D{ bson.DocElem{Name: `foo"bar`, Value: "a"}, diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/maxkey_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/maxkey_test.go index 89eeed0af9a..f64df05ad4d 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/maxkey_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/maxkey_test.go @@ -8,12 +8,14 @@ package bsonutil import ( "github.com/mongodb/mongo-tools/common/json" + "github.com/mongodb/mongo-tools/common/testtype" . "github.com/smartystreets/goconvey/convey" "gopkg.in/mgo.v2/bson" "testing" ) func TestMaxKeyValue(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("When converting JSON with MaxKey values", t, func() { diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/minkey_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/minkey_test.go index 987576f54b1..22d6e3382ba 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/minkey_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/minkey_test.go @@ -8,12 +8,14 @@ package bsonutil import ( "github.com/mongodb/mongo-tools/common/json" + "github.com/mongodb/mongo-tools/common/testtype" . "github.com/smartystreets/goconvey/convey" "gopkg.in/mgo.v2/bson" "testing" ) func TestMinKeyValue(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("When converting JSON with MinKey values", t, func() { diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/numberint_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/numberint_test.go index 7ecee5b825e..78050471fdd 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/numberint_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/numberint_test.go @@ -8,11 +8,13 @@ package bsonutil import ( "github.com/mongodb/mongo-tools/common/json" + "github.com/mongodb/mongo-tools/common/testtype" . "github.com/smartystreets/goconvey/convey" "testing" ) func TestNumberIntValue(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("When converting JSON with NumberInt values", t, func() { diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/numberlong_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/numberlong_test.go index 97a1e8afe5e..9be09850f7c 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/numberlong_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/numberlong_test.go @@ -8,11 +8,13 @@ package bsonutil import ( "github.com/mongodb/mongo-tools/common/json" + "github.com/mongodb/mongo-tools/common/testtype" . "github.com/smartystreets/goconvey/convey" "testing" ) func TestNumberLongValue(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("When converting JSON with NumberLong values", t, func() { diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/objectid_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/objectid_test.go index 1adec240247..10a88ab9f8b 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/objectid_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/objectid_test.go @@ -8,12 +8,14 @@ package bsonutil import ( "github.com/mongodb/mongo-tools/common/json" + "github.com/mongodb/mongo-tools/common/testtype" . "github.com/smartystreets/goconvey/convey" "gopkg.in/mgo.v2/bson" "testing" ) func TestObjectIdValue(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("When converting JSON with ObjectId values", t, func() { diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/regexp_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/regexp_test.go index b4060158285..efa0891d9e2 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/regexp_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/regexp_test.go @@ -8,12 +8,14 @@ package bsonutil import ( "github.com/mongodb/mongo-tools/common/json" + "github.com/mongodb/mongo-tools/common/testtype" . "github.com/smartystreets/goconvey/convey" "gopkg.in/mgo.v2/bson" "testing" ) func TestRegExpValue(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("When converting JSON with RegExp values", t, func() { diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/timestamp_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/timestamp_test.go index d1d7de62777..9310e05ded0 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/timestamp_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/timestamp_test.go @@ -8,12 +8,14 @@ package bsonutil import ( "github.com/mongodb/mongo-tools/common/json" + "github.com/mongodb/mongo-tools/common/testtype" . "github.com/smartystreets/goconvey/convey" "gopkg.in/mgo.v2/bson" "testing" ) func TestTimestampValue(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("When converting JSON with Timestamp values", t, func() { testTS := bson.MongoTimestamp(123456<<32 | 55) diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/undefined_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/undefined_test.go index 8aee1a61488..02acc63188e 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/undefined_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/bsonutil/undefined_test.go @@ -8,12 +8,14 @@ package bsonutil import ( "github.com/mongodb/mongo-tools/common/json" + "github.com/mongodb/mongo-tools/common/testtype" . "github.com/smartystreets/goconvey/convey" "gopkg.in/mgo.v2/bson" "testing" ) func TestUndefinedValue(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("When converting JSON with undefined values", t, func() { diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/db/bson_stream_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/db/bson_stream_test.go index 55f485774ff..e26f6f3aeb0 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/db/bson_stream_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/db/bson_stream_test.go @@ -12,9 +12,12 @@ import ( "gopkg.in/mgo.v2/bson" "io/ioutil" "testing" + + "github.com/mongodb/mongo-tools/common/testtype" ) func TestBufferlessBSONSource(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.IntegrationTestType) var testValues = []bson.M{ {"_": bson.Binary{Kind: 0x80, Data: []byte("apples")}}, {"_": bson.Binary{Kind: 0x80, Data: []byte("bananas")}}, diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/db/buffered_bulk_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/db/buffered_bulk_test.go index 0df00d28ecd..9d7b98cfcd6 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/db/buffered_bulk_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/db/buffered_bulk_test.go @@ -7,6 +7,7 @@ package db import ( + "os" "testing" "github.com/mongodb/mongo-tools/common/options" @@ -15,18 +16,55 @@ import ( "gopkg.in/mgo.v2/bson" ) +// Copied this var block, GetSSLOptions, and GetAuthOptions from common/testutil/auth.go to avoid circular dependency +var ( + UserAdmin = "uAdmin" + UserAdminPassword = "password" + CreatedUserNameEnv = "TOOLS_TESTING_AUTH_USERNAME" + CreatedUserPasswordEnv = "TOOLS_TESTING_AUTH_PASSWORD" +) + +func DBGetSSLOptions() options.SSL { + if testtype.HasTestType(testtype.SSLTestType) { + return options.SSL{ + UseSSL: true, + SSLCAFile: "./openssl/testdata/ca.pem", + SSLPEMKeyFile: "./openssl/testdata/server.pem", + } + } + + return options.SSL{ + UseSSL: false, + } +} + +func DBGetAuthOptions() options.Auth { + if testtype.HasTestType(testtype.AuthTestType) { + return options.Auth{ + Username: os.Getenv(CreatedUserNameEnv), + Password: os.Getenv(CreatedUserPasswordEnv), + Source: "admin", + } + } + + return options.Auth{} +} + func TestBufferedBulkInserterInserts(t *testing.T) { var bufBulk *BufferedBulkInserter - testtype.VerifyTestType(t, "db") + testtype.SkipUnlessTestType(t, testtype.IntegrationTestType) + + auth := DBGetAuthOptions() + ssl := DBGetSSLOptions() Convey("With a valid session", t, func() { opts := options.ToolOptions{ Connection: &options.Connection{ Port: DefaultTestPort, }, - SSL: &options.SSL{}, - Auth: &options.Auth{}, + SSL: &ssl, + Auth: &auth, } provider, err := NewSessionProvider(opts) So(provider, ShouldNotBeNil) diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/db/connector_sasl_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/db/connector_sasl_test.go index dcde56fea08..00c6f640f4a 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/db/connector_sasl_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/db/connector_sasl_test.go @@ -28,7 +28,7 @@ var ( ) func TestKerberosAuthMechanism(t *testing.T) { - testtype.VerifyTestType(t, testtype.KerberosTestType) + testtype.SkipUnlessTestType(t, testtype.KerberosTestType) Convey("should be able to successfully connect", t, func() { connector := &db.VanillaDBConnector{} diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/db/connector_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/db/connector_test.go index 48ef3611587..18eb9b4b64f 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/db/connector_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/db/connector_test.go @@ -15,12 +15,15 @@ import ( "github.com/mongodb/mongo-tools/common/testtype" "github.com/mongodb/mongo-tools/common/testutil" . "github.com/smartystreets/goconvey/convey" - "gopkg.in/mgo.v2" ) func TestVanillaDBConnector(t *testing.T) { - testtype.VerifyTestType(t, "db") + testtype.SkipUnlessTestType(t, testtype.IntegrationTestType) + // VanillaDBConnector can't connect if SSL or Auth are enabled + if testtype.HasTestType(testtype.SSLTestType) || testtype.HasTestType(testtype.AuthTestType) { + t.SkipNow() + } Convey("With a vanilla db connector", t, func() { @@ -72,22 +75,17 @@ func TestVanillaDBConnector(t *testing.T) { } func TestVanillaDBConnectorWithAuth(t *testing.T) { - testtype.VerifyTestType(t, "auth") - session, err := mgo.Dial("localhost:33333") - if err != nil { - t.Fatalf("error dialing server: %v", err) + testtype.SkipUnlessTestType(t, testtype.AuthTestType) + // VanillaDBConnector can't connect if SSL is enabled + if testtype.HasTestType(testtype.SSLTestType) { + t.SkipNow() } - err = testutil.CreateUserAdmin(session) - So(err, ShouldBeNil) - err = testutil.CreateUserWithRole(session, "cAdmin", "password", - mgo.RoleClusterAdmin, true) - So(err, ShouldBeNil) - session.Close() - Convey("With a vanilla db connector and a mongod running with"+ " auth", t, func() { + auth := testutil.GetAuthOptions() + var connector *db.VanillaDBConnector Convey("connecting without authentication should not be able"+ @@ -123,10 +121,7 @@ func TestVanillaDBConnectorWithAuth(t *testing.T) { Host: "localhost", Port: db.DefaultTestPort, }, - Auth: &options.Auth{ - Username: "cAdmin", - Password: "password", - }, + Auth: &auth, } So(connector.Configure(opts), ShouldBeNil) diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/db/db_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/db/db_test.go index 44d60845740..a922bbdff44 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/db/db_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/db/db_test.go @@ -18,7 +18,9 @@ import ( func TestNewSessionProvider(t *testing.T) { - testtype.VerifyTestType(t, "db") + testtype.SkipUnlessTestType(t, testtype.IntegrationTestType) + auth := DBGetAuthOptions() + ssl := DBGetSSLOptions() Convey("When initializing a session provider", t, func() { @@ -28,13 +30,15 @@ func TestNewSessionProvider(t *testing.T) { Connection: &options.Connection{ Port: DefaultTestPort, }, - SSL: &options.SSL{}, - Auth: &options.Auth{}, + SSL: &ssl, + Auth: &auth, } provider, err := NewSessionProvider(opts) So(err, ShouldBeNil) - So(reflect.TypeOf(provider.connector), ShouldEqual, - reflect.TypeOf(&VanillaDBConnector{})) + if !testtype.HasTestType(testtype.SSLTestType) { + So(reflect.TypeOf(provider.connector), ShouldEqual, + reflect.TypeOf(&VanillaDBConnector{})) + } Convey("and should be closeable", func() { provider.Close() @@ -48,8 +52,8 @@ func TestNewSessionProvider(t *testing.T) { Connection: &options.Connection{ Port: DefaultTestPort, }, - SSL: &options.SSL{}, - Auth: &options.Auth{}, + SSL: &ssl, + Auth: &auth, } provider, err := NewSessionProvider(opts) So(err, ShouldBeNil) @@ -74,15 +78,17 @@ func TestNewSessionProvider(t *testing.T) { func TestGetIndexes(t *testing.T) { - testtype.VerifyTestType(t, "db") + testtype.SkipUnlessTestType(t, testtype.IntegrationTestType) Convey("With a valid session", t, func() { + auth := DBGetAuthOptions() + ssl := DBGetSSLOptions() opts := options.ToolOptions{ Connection: &options.Connection{ Port: DefaultTestPort, }, - SSL: &options.SSL{}, - Auth: &options.Auth{}, + SSL: &ssl, + Auth: &auth, } provider, err := NewSessionProvider(opts) So(err, ShouldBeNil) diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/db/namespaces_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/db/namespaces_test.go index 15ccb02f3ff..324ef59f151 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/db/namespaces_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/db/namespaces_test.go @@ -10,6 +10,7 @@ import ( "fmt" "testing" + "github.com/mongodb/mongo-tools/common/testtype" . "github.com/smartystreets/goconvey/convey" ) @@ -22,6 +23,7 @@ type stripDBFromNamespaceTestCase struct { } func TestStripDBFromNamespace(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("When testing StripDBFromNamespace with cases", t, func() { testCases := []stripDBFromNamespaceTestCase{ { diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/db/tlsgo/config_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/db/tlsgo/config_test.go index 9fa3585c5e2..be46a87dcf7 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/db/tlsgo/config_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/db/tlsgo/config_test.go @@ -8,7 +8,7 @@ import ( ) func TestAddClientCert(t *testing.T) { - testtype.VerifyTestType(t, testtype.UnitTestType) + testtype.SkipUnlessTestType(t, testtype.UnitTestType) cases := []struct { Path string diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/db/write_concern_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/db/write_concern_test.go index 94573bb2005..e9783525eeb 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/db/write_concern_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/db/write_concern_test.go @@ -8,6 +8,7 @@ package db import ( "github.com/mongodb/mongo-tools/common/connstring" + "github.com/mongodb/mongo-tools/common/testtype" . "github.com/smartystreets/goconvey/convey" "fmt" @@ -16,6 +17,7 @@ import ( ) func TestBuildWriteConcern(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("When building write concern object", t, func() { Convey("and given a write concern string value, and a boolean indicating if the "+ "write concern is to be used on a replica set, on calling BuildWriteConcern...", func() { @@ -100,6 +102,7 @@ func TestBuildWriteConcern(t *testing.T) { } func TestConstructWCObject(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("Given a write concern string value, on calling constructWCObject...", t, func() { Convey("non-JSON string values should be assigned to the 'WMode' "+ @@ -213,6 +216,7 @@ func TestConstructWCObject(t *testing.T) { } func TestConstructSafetyFromConnString(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("Given a parsed &connstring, on calling constructSafetyFromConnString...", t, func() { Convey("non string values should be assigned to the 'WMode' "+ diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/failpoint/failpoint_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/failpoint/failpoint_test.go index 88f95fa3485..713b0172717 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/failpoint/failpoint_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/failpoint/failpoint_test.go @@ -16,7 +16,7 @@ import ( ) func TestFailpointParsing(t *testing.T) { - testtype.VerifyTestType(t, testtype.UnitTestType) + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("With test args", t, func() { args := "foo=bar,baz,biz=,=a" diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/intents/intent_prioritizer_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/intents/intent_prioritizer_test.go index 7e79e72b927..4ab94bc7906 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/intents/intent_prioritizer_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/intents/intent_prioritizer_test.go @@ -17,7 +17,7 @@ import ( func TestLegacyPrioritizer(t *testing.T) { - testtype.VerifyTestType(t, testtype.UnitTestType) + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("With a legacyPrioritizer initialized with an ordered intent list", t, func() { testList := []*Intent{ @@ -43,7 +43,7 @@ func TestLegacyPrioritizer(t *testing.T) { func TestBasicDBHeapBehavior(t *testing.T) { var dbheap heap.Interface - testtype.VerifyTestType(t, testtype.UnitTestType) + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("With an empty dbHeap", t, func() { dbheap = &DBHeap{} @@ -93,7 +93,7 @@ func TestBasicDBHeapBehavior(t *testing.T) { func TestDBCounterCollectionSorting(t *testing.T) { - testtype.VerifyTestType(t, testtype.UnitTestType) + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("With a dbCounter and an unordered collection of intents", t, func() { dbc := &dbCounter{ @@ -120,7 +120,7 @@ func TestDBCounterCollectionSorting(t *testing.T) { func TestBySizeAndView(t *testing.T) { var prioritizer IntentPrioritizer - testtype.VerifyTestType(t, testtype.UnitTestType) + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("With a prioritizer initialized with on a set of intents", t, func() { intents := []*Intent{ @@ -151,7 +151,7 @@ func TestBySizeAndView(t *testing.T) { func TestSimulatedMultiDBJob(t *testing.T) { var prioritizer IntentPrioritizer - testtype.VerifyTestType(t, testtype.UnitTestType) + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("With a prioritizer initialized with a set of intents", t, func() { intents := []*Intent{ diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/intents/intent_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/intents/intent_test.go index e13b844969f..693994d1394 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/intents/intent_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/intents/intent_test.go @@ -16,7 +16,7 @@ import ( func TestIntentManager(t *testing.T) { var manager *Manager - testtype.VerifyTestType(t, testtype.UnitTestType) + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("With an empty IntentManager", t, func() { manager = NewIntentManager() diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/bench_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/bench_test.go index 9ed3c014078..ba34a4015fc 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/bench_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/bench_test.go @@ -18,6 +18,7 @@ package json import ( "bytes" "compress/gzip" + "github.com/mongodb/mongo-tools/common/testtype" "io/ioutil" "os" "testing" @@ -81,6 +82,7 @@ func codeInit() { } func BenchmarkCodeEncoder(b *testing.B) { + testtype.SkipUnlessBenchmarkType(b, testtype.UnitTestType) if codeJSON == nil { b.StopTimer() codeInit() @@ -96,6 +98,7 @@ func BenchmarkCodeEncoder(b *testing.B) { } func BenchmarkCodeMarshal(b *testing.B) { + testtype.SkipUnlessBenchmarkType(b, testtype.UnitTestType) if codeJSON == nil { b.StopTimer() codeInit() @@ -110,6 +113,7 @@ func BenchmarkCodeMarshal(b *testing.B) { } func BenchmarkCodeDecoder(b *testing.B) { + testtype.SkipUnlessBenchmarkType(b, testtype.UnitTestType) if codeJSON == nil { b.StopTimer() codeInit() @@ -132,6 +136,7 @@ func BenchmarkCodeDecoder(b *testing.B) { } func BenchmarkCodeUnmarshal(b *testing.B) { + testtype.SkipUnlessBenchmarkType(b, testtype.UnitTestType) if codeJSON == nil { b.StopTimer() codeInit() @@ -147,6 +152,7 @@ func BenchmarkCodeUnmarshal(b *testing.B) { } func BenchmarkCodeUnmarshalReuse(b *testing.B) { + testtype.SkipUnlessBenchmarkType(b, testtype.UnitTestType) if codeJSON == nil { b.StopTimer() codeInit() @@ -161,6 +167,7 @@ func BenchmarkCodeUnmarshalReuse(b *testing.B) { } func BenchmarkUnmarshalString(b *testing.B) { + testtype.SkipUnlessBenchmarkType(b, testtype.UnitTestType) data := []byte(`"hello, world"`) var s string @@ -172,6 +179,7 @@ func BenchmarkUnmarshalString(b *testing.B) { } func BenchmarkUnmarshalFloat64(b *testing.B) { + testtype.SkipUnlessBenchmarkType(b, testtype.UnitTestType) var f float64 data := []byte(`3.14`) @@ -183,6 +191,7 @@ func BenchmarkUnmarshalFloat64(b *testing.B) { } func BenchmarkUnmarshalInt64(b *testing.B) { + testtype.SkipUnlessBenchmarkType(b, testtype.UnitTestType) var x int64 data := []byte(`3`) diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/bindata_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/bindata_test.go index 7f5ea704f3e..cf38992217a 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/bindata_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/bindata_test.go @@ -8,11 +8,13 @@ package json import ( "fmt" + "github.com/mongodb/mongo-tools/common/testtype" . "github.com/smartystreets/goconvey/convey" "testing" ) func TestBinDataValue(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("When unmarshalling JSON with BinData values", t, func() { diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/boolean_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/boolean_test.go index 6b434eeafb7..6e41b09918d 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/boolean_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/boolean_test.go @@ -8,11 +8,13 @@ package json import ( "fmt" + "github.com/mongodb/mongo-tools/common/testtype" . "github.com/smartystreets/goconvey/convey" "testing" ) func TestBooleanValue(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("When unmarshalling JSON with Boolean values", t, func() { diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/date_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/date_test.go index d6e54d4e17b..79d9a84994c 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/date_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/date_test.go @@ -8,11 +8,13 @@ package json import ( "fmt" + "github.com/mongodb/mongo-tools/common/testtype" . "github.com/smartystreets/goconvey/convey" "testing" ) func TestDateValue(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("When unmarshalling JSON with Date values", t, func() { diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/dbpointer_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/dbpointer_test.go index 73bafbdc869..130321ddf4e 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/dbpointer_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/dbpointer_test.go @@ -8,12 +8,14 @@ package json import ( "fmt" + "github.com/mongodb/mongo-tools/common/testtype" . "github.com/smartystreets/goconvey/convey" "gopkg.in/mgo.v2/bson" "testing" ) func TestDBPointerValue(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("Unmarshalling JSON with DBPointer values", t, func() { key := "key" diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/dbref_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/dbref_test.go index b9b533706c1..c27522f6ec0 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/dbref_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/dbref_test.go @@ -8,13 +8,14 @@ package json import ( "fmt" + "github.com/mongodb/mongo-tools/common/testtype" . "github.com/smartystreets/goconvey/convey" "math" "testing" ) func TestDBRefValue(t *testing.T) { - + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("When unmarshalling JSON with DBRef values", t, func() { Convey("works for a single key", func() { diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/decode_d_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/decode_d_test.go index 2f867f99eeb..d08d9c2ef9f 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/decode_d_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/decode_d_test.go @@ -8,12 +8,14 @@ package json import ( "fmt" + "github.com/mongodb/mongo-tools/common/testtype" . "github.com/smartystreets/goconvey/convey" "gopkg.in/mgo.v2/bson" "testing" ) func TestDecodeBsonD(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("When unmarshalling JSON into a bson.D", t, func() { Convey("a document should be stored with keys in the same order", func() { data := `{"a":1, "b":2, "c":3, "d":4, "e":5, "f":6}` diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/decode_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/decode_test.go index 107321d1f5e..330792c0e3f 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/decode_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/decode_test.go @@ -13,6 +13,7 @@ import ( "bytes" "encoding" "fmt" + "github.com/mongodb/mongo-tools/common/testtype" "image" "reflect" "strings" @@ -422,6 +423,7 @@ var unmarshalTests = []unmarshalTest{ } func TestMarshal(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) b, err := Marshal(allValue) if err != nil { t.Fatalf("Marshal allValue: %v", err) @@ -455,6 +457,7 @@ var badUTF8 = []struct { } func TestMarshalBadUTF8(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) for _, tt := range badUTF8 { b, err := Marshal(tt.in) if string(b) != tt.out || err != nil { @@ -464,6 +467,7 @@ func TestMarshalBadUTF8(t *testing.T) { } func TestMarshalNumberZeroVal(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) var n Number out, err := Marshal(n) if err != nil { @@ -476,6 +480,7 @@ func TestMarshalNumberZeroVal(t *testing.T) { } func TestMarshalEmbeds(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) top := &Top{ Level0: 1, Embed0: Embed0{ @@ -515,6 +520,7 @@ func TestMarshalEmbeds(t *testing.T) { } func TestUnmarshal(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) for i, tt := range unmarshalTests { var scan scanner in := []byte(tt.in) @@ -573,6 +579,7 @@ func TestUnmarshal(t *testing.T) { } func TestUnmarshalMarshal(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) initBig() var v interface{} if err := Unmarshal(jsonBig, &v); err != nil { @@ -603,6 +610,7 @@ var numberTests = []struct { // Independent of Decode, basic coverage of the accessors in Number func TestNumberAccessors(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) for _, tt := range numberTests { n := Number(tt.in) if s := n.String(); s != tt.in { @@ -622,6 +630,7 @@ func TestNumberAccessors(t *testing.T) { } func TestLargeByteSlice(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) s0 := make([]byte, 2000) for i := range s0 { s0[i] = byte(i) @@ -645,6 +654,7 @@ type Xint struct { } func TestUnmarshalInterface(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) var xint Xint var i interface{} = &xint if err := Unmarshal([]byte(`{"X":1}`), &i); err != nil { @@ -656,6 +666,7 @@ func TestUnmarshalInterface(t *testing.T) { } func TestUnmarshalPtrPtr(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) var xint Xint pxint := &xint if err := Unmarshal([]byte(`{"X":1}`), &pxint); err != nil { @@ -667,6 +678,7 @@ func TestUnmarshalPtrPtr(t *testing.T) { } func TestEscape(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) const input = `"foobar"<html>` + " [\u2028 \u2029]" const expected = `"\"foobar\"\u003chtml\u003e [\u2028 \u2029]"` b, err := Marshal(input) @@ -696,6 +708,7 @@ var wrongStringTests = []wrongStringTest{ // If people misuse the ,string modifier, the error message should be // helpful, telling the user that they're doing it wrong. func TestErrorMessageFromMisusedString(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) for n, tt := range wrongStringTests { r := strings.NewReader(tt.in) var s WrongString @@ -1029,6 +1042,7 @@ var pallValueIndent = `{ var pallValueCompact = strings.Map(noSpace, pallValueIndent) func TestRefUnmarshal(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) type S struct { // Ref is defined in encode_test.go. R0 Ref @@ -1057,6 +1071,7 @@ func TestRefUnmarshal(t *testing.T) { // Test that the empty string doesn't panic decoding when ,string is specified // Issue 3450 func TestEmptyString(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) type T2 struct { Number1 int `json:",string"` Number2 int `json:",string"` @@ -1076,6 +1091,7 @@ func TestEmptyString(t *testing.T) { // Test that the returned error is non-nil when trying to unmarshal null string into int, for successive ,string option // Issue 7046 func TestNullString(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) type T struct { A int `json:",string"` B int `json:",string"` @@ -1121,6 +1137,7 @@ var interfaceSetTests = []struct { } func TestInterfaceSet(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) for _, tt := range interfaceSetTests { b := struct{ X interface{} }{tt.pre} blob := `{"X":` + tt.json + `}` @@ -1137,6 +1154,7 @@ func TestInterfaceSet(t *testing.T) { // JSON null values should be ignored for primitives and string values instead of resulting in an error. // Issue 2540 func TestUnmarshalNulls(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) jsonData := []byte(`{ "Bool" : null, "Int" : null, @@ -1182,6 +1200,7 @@ func TestUnmarshalNulls(t *testing.T) { } func TestStringKind(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) type stringKind string var m1, m2 map[stringKind]int @@ -1218,6 +1237,7 @@ var decodeTypeErrorTests = []struct { } func TestUnmarshalTypeError(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) for _, item := range decodeTypeErrorTests { err := Unmarshal([]byte(item.src), item.dest) if _, ok := err.(*UnmarshalTypeError); !ok { @@ -1239,6 +1259,7 @@ var unmarshalSyntaxTests = []string{ } func TestUnmarshalSyntax(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) var x interface{} for _, src := range unmarshalSyntaxTests { err := Unmarshal([]byte(src), &x) @@ -1257,6 +1278,7 @@ type unexportedFields struct { } func TestUnmarshalUnexported(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) input := `{"Name": "Bob", "m": {"x": 123}, "m2": {"y": 456}, "abcd": {"z": 789}}` want := &unexportedFields{Name: "Bob"} @@ -1287,6 +1309,7 @@ func (t *Time3339) UnmarshalJSON(b []byte) error { } func TestUnmarshalJSONLiteralError(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) var t3 Time3339 err := Unmarshal([]byte(`"0000-00-00T00:00:00Z"`), &t3) if err == nil { @@ -1301,6 +1324,7 @@ func TestUnmarshalJSONLiteralError(t *testing.T) { // "data changing underfoot" error. // Issue 3717 func TestSkipArrayObjects(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) json := `[{}]` var dest [0]interface{} @@ -1313,6 +1337,7 @@ func TestSkipArrayObjects(t *testing.T) { // Test semantics of pre-filled struct fields and pre-filled map fields. // Issue 4900. func TestPrefilled(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) ptrToMap := func(m map[string]interface{}) *map[string]interface{} { return &m } // Values here change, cannot reuse table across runs. @@ -1355,6 +1380,7 @@ var invalidUnmarshalTests = []struct { } func TestInvalidUnmarshal(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) buf := []byte(`{"a":"1"}`) for _, tt := range invalidUnmarshalTests { err := Unmarshal(buf, tt.v) diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/encode_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/encode_test.go index a0c0df8aa5e..e821c4583bb 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/encode_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/encode_test.go @@ -15,6 +15,8 @@ import ( "reflect" "testing" "unicode" + + "github.com/mongodb/mongo-tools/common/testtype" ) type Optionals struct { @@ -57,6 +59,7 @@ var optionalsExpected = `{ }` func TestOmitEmpty(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) var o Optionals o.Sw = "something" o.Mr = map[string]interface{}{} @@ -84,6 +87,7 @@ var stringTagExpected = `{ }` func TestStringTag(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) var s StringTag s.BoolStr = true s.IntStr = 42 @@ -113,6 +117,7 @@ type renamedByteSlice []byte type renamedRenamedByteSlice []renamedByte func TestEncodeRenamedByteSlice(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) s := renamedByteSlice("abc") result, err := Marshal(s) if err != nil { @@ -133,6 +138,7 @@ func TestEncodeRenamedByteSlice(t *testing.T) { } func TestFloatSpecialValues(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) _, err := Marshal(math.NaN()) if err != nil { t.Errorf("Got error for NaN: %v", err) @@ -188,6 +194,7 @@ func (ValText) MarshalText() ([]byte, error) { } func TestRefValMarshal(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) var s = struct { R0 Ref R1 *Ref @@ -232,6 +239,7 @@ func (CText) MarshalText() ([]byte, error) { } func TestMarshalerEscaping(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) var c C1 want := `"\u003c\u0026\u003e"` b, err := Marshal(c) @@ -260,6 +268,7 @@ type MyStruct struct { } func TestAnonymousNonstruct(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) var i IntType = 11 a := MyStruct{i} const want = `{"IntType":11}` @@ -295,6 +304,7 @@ type BugX struct { // Issue 5245. func TestEmbeddedBug(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) v := BugB{ BugA{"A"}, "B", @@ -335,6 +345,7 @@ type BugY struct { // Test that a field with a tag dominates untagged fields. func TestTaggedFieldDominates(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) v := BugY{ BugA{"BugA"}, BugD{"BugD"}, @@ -358,6 +369,7 @@ type BugZ struct { } func TestDuplicatedFieldDisappears(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) v := BugZ{ BugA{"BugA"}, BugC{"BugC"}, @@ -378,6 +390,7 @@ func TestDuplicatedFieldDisappears(t *testing.T) { } func TestStringBytes(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) // Test that encodeState.stringBytes and encodeState.string use the same encoding. es := &encodeState{} var r []rune @@ -424,6 +437,7 @@ func TestStringBytes(t *testing.T) { } func TestIssue6458(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) type Foo struct { M RawMessage } @@ -448,6 +462,7 @@ func TestIssue6458(t *testing.T) { } func TestHTMLEscape(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) var b, want bytes.Buffer m := `{"M":"<html>foo &` + "\xe2\x80\xa8 \xe2\x80\xa9" + `</html>"}` want.Write([]byte(`{"M":"\u003chtml\u003efoo \u0026\u2028 \u2029\u003c/html\u003e"}`)) diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/float_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/float_test.go index 062b330a1e1..787a2b7e137 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/float_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/float_test.go @@ -8,11 +8,13 @@ package json import ( "fmt" + "github.com/mongodb/mongo-tools/common/testtype" . "github.com/smartystreets/goconvey/convey" "testing" ) func TestNumberFloatValue(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("When unmarshaling JSON with float values", t, func() { diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/fold_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/fold_test.go index 1c10dbcf64b..9024ee08c80 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/fold_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/fold_test.go @@ -11,6 +11,7 @@ package json import ( "bytes" + "github.com/mongodb/mongo-tools/common/testtype" "strings" "testing" "unicode/utf8" @@ -45,6 +46,7 @@ var foldTests = []struct { } func TestFold(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) for i, tt := range foldTests { if got := tt.fn([]byte(tt.s), []byte(tt.t)); got != tt.want { t.Errorf("%d. %q, %q = %v; want %v", i, tt.s, tt.t, got, tt.want) @@ -57,6 +59,7 @@ func TestFold(t *testing.T) { } func TestFoldAgainstUnicode(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) const bufSize = 5 buf1 := make([]byte, 0, bufSize) buf2 := make([]byte, 0, bufSize) diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/frac_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/frac_test.go index ed8daae6a08..1a7a7b72bc4 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/frac_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/frac_test.go @@ -8,11 +8,13 @@ package json import ( "fmt" + "github.com/mongodb/mongo-tools/common/testtype" . "github.com/smartystreets/goconvey/convey" "testing" ) func TestFractionalNumber(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("When unmarshalling JSON with fractional numeric values "+ "without a leading zero", t, func() { diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/hex_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/hex_test.go index 0f6ed7686f3..7ea44bc351c 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/hex_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/hex_test.go @@ -8,11 +8,13 @@ package json import ( "fmt" + "github.com/mongodb/mongo-tools/common/testtype" . "github.com/smartystreets/goconvey/convey" "testing" ) func TestHexadecimalNumber(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) value := "0x123" intValue := 0x123 diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/infinity_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/infinity_test.go index 63a14d3b633..e01e7f621f9 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/infinity_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/infinity_test.go @@ -8,12 +8,14 @@ package json import ( "fmt" + "github.com/mongodb/mongo-tools/common/testtype" . "github.com/smartystreets/goconvey/convey" "math" "testing" ) func TestInfinityValue(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("When unmarshalling JSON with Infinity values", t, func() { diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/iso_date_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/iso_date_test.go index a61c4ce9225..95238dadfc6 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/iso_date_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/iso_date_test.go @@ -7,124 +7,121 @@ package json import ( - "fmt" - . "github.com/smartystreets/goconvey/convey" - "testing" + "fmt" + "github.com/mongodb/mongo-tools/common/testtype" + . "github.com/smartystreets/goconvey/convey" + "testing" ) func TestISODateValue(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) - Convey("When unmarshalling JSON with ISODate values", t, func() { + Convey("When unmarshalling JSON with ISODate values", t, func() { - Convey("works for a single key", func() { - var jsonMap map[string]interface{} + Convey("works for a single key", func() { + var jsonMap map[string]interface{} - key := "key" - value := "ISODate(\"2006-01-02T15:04-0700\")" - data := fmt.Sprintf(`{"%v":%v}`, key, value) + key := "key" + value := "ISODate(\"2006-01-02T15:04-0700\")" + data := fmt.Sprintf(`{"%v":%v}`, key, value) - err := Unmarshal([]byte(data), &jsonMap) - So(err, ShouldBeNil) + err := Unmarshal([]byte(data), &jsonMap) + So(err, ShouldBeNil) - jsonValue, ok := jsonMap[key].(ISODate) - So(ok, ShouldBeTrue) - So(jsonValue, ShouldEqual, ISODate("2006-01-02T15:04-0700")) - }) + jsonValue, ok := jsonMap[key].(ISODate) + So(ok, ShouldBeTrue) + So(jsonValue, ShouldEqual, ISODate("2006-01-02T15:04-0700")) + }) - Convey("works for multiple keys", func() { - var jsonMap map[string]interface{} + Convey("works for multiple keys", func() { + var jsonMap map[string]interface{} - key1, key2, key3 := "key1", "key2", "key3" - value1, value2, value3 := "ISODate(\"2006-01-02T15:04Z0700\")", "ISODate(\"2013-01-02T15:04Z0700\")", "ISODate(\"2014-02-02T15:04Z0700\")" - data := fmt.Sprintf(`{"%v":%v,"%v":%v,"%v":%v}`, - key1, value1, key2, value2, key3, value3) + key1, key2, key3 := "key1", "key2", "key3" + value1, value2, value3 := "ISODate(\"2006-01-02T15:04Z0700\")", "ISODate(\"2013-01-02T15:04Z0700\")", "ISODate(\"2014-02-02T15:04Z0700\")" + data := fmt.Sprintf(`{"%v":%v,"%v":%v,"%v":%v}`, + key1, value1, key2, value2, key3, value3) - err := Unmarshal([]byte(data), &jsonMap) - So(err, ShouldBeNil) + err := Unmarshal([]byte(data), &jsonMap) + So(err, ShouldBeNil) - jsonValue1, ok := jsonMap[key1].(ISODate) - So(ok, ShouldBeTrue) - So(jsonValue1, ShouldEqual, ISODate("2006-01-02T15:04Z0700")) + jsonValue1, ok := jsonMap[key1].(ISODate) + So(ok, ShouldBeTrue) + So(jsonValue1, ShouldEqual, ISODate("2006-01-02T15:04Z0700")) - jsonValue2, ok := jsonMap[key2].(ISODate) - So(ok, ShouldBeTrue) - So(jsonValue2, ShouldEqual, ISODate("2013-01-02T15:04Z0700")) + jsonValue2, ok := jsonMap[key2].(ISODate) + So(ok, ShouldBeTrue) + So(jsonValue2, ShouldEqual, ISODate("2013-01-02T15:04Z0700")) - jsonValue3, ok := jsonMap[key3].(ISODate) - So(ok, ShouldBeTrue) - So(jsonValue3, ShouldEqual, ISODate("2014-02-02T15:04Z0700")) - }) + jsonValue3, ok := jsonMap[key3].(ISODate) + So(ok, ShouldBeTrue) + So(jsonValue3, ShouldEqual, ISODate("2014-02-02T15:04Z0700")) + }) - Convey("works in an array", func() { - var jsonMap map[string]interface{} + Convey("works in an array", func() { + var jsonMap map[string]interface{} - key := "key" - value := "ISODate(\"2006-01-02T15:04-0700\")" - data := fmt.Sprintf(`{"%v":[%v,%v,%v]}`, - key, value, value, value) + key := "key" + value := "ISODate(\"2006-01-02T15:04-0700\")" + data := fmt.Sprintf(`{"%v":[%v,%v,%v]}`, + key, value, value, value) - err := Unmarshal([]byte(data), &jsonMap) - So(err, ShouldBeNil) + err := Unmarshal([]byte(data), &jsonMap) + So(err, ShouldBeNil) - jsonArray, ok := jsonMap[key].([]interface{}) - So(ok, ShouldBeTrue) + jsonArray, ok := jsonMap[key].([]interface{}) + So(ok, ShouldBeTrue) - for _, _jsonValue := range jsonArray { - jsonValue, ok := _jsonValue.(ISODate) - So(ok, ShouldBeTrue) - So(jsonValue, ShouldEqual, ISODate("2006-01-02T15:04-0700")) - } - }) + for _, _jsonValue := range jsonArray { + jsonValue, ok := _jsonValue.(ISODate) + So(ok, ShouldBeTrue) + So(jsonValue, ShouldEqual, ISODate("2006-01-02T15:04-0700")) + } + }) - Convey("will take valid format 2006-01-02T15:04:05.000-0700", func() { - var jsonMap map[string]interface{} + Convey("will take valid format 2006-01-02T15:04:05.000-0700", func() { + var jsonMap map[string]interface{} - key := "key" - value := "ISODate(\"2006-01-02T15:04:05.000-0700\")" - data := fmt.Sprintf(`{"%v":%v}`, key, value) + key := "key" + value := "ISODate(\"2006-01-02T15:04:05.000-0700\")" + data := fmt.Sprintf(`{"%v":%v}`, key, value) - err := Unmarshal([]byte(data), &jsonMap) - So(err, ShouldBeNil) + err := Unmarshal([]byte(data), &jsonMap) + So(err, ShouldBeNil) - jsonValue, ok := jsonMap[key].(ISODate) - So(ok, ShouldBeTrue) - So(jsonValue, ShouldEqual, ISODate("2006-01-02T15:04:05.000-0700")) - }) + jsonValue, ok := jsonMap[key].(ISODate) + So(ok, ShouldBeTrue) + So(jsonValue, ShouldEqual, ISODate("2006-01-02T15:04:05.000-0700")) + }) + Convey("will take valid format 2006-01-02T15:04:05", func() { + var jsonMap map[string]interface{} - Convey("will take valid format 2006-01-02T15:04:05", func() { - var jsonMap map[string]interface{} + key := "key" + value := "ISODate(\"2014-01-02T15:04:05Z\")" + data := fmt.Sprintf(`{"%v":%v}`, key, value) - key := "key" - value := "ISODate(\"2014-01-02T15:04:05Z\")" - data := fmt.Sprintf(`{"%v":%v}`, key, value) + err := Unmarshal([]byte(data), &jsonMap) + So(err, ShouldBeNil) - err := Unmarshal([]byte(data), &jsonMap) - So(err, ShouldBeNil) + jsonValue, ok := jsonMap[key].(ISODate) + So(ok, ShouldBeTrue) + So(jsonValue, ShouldEqual, ISODate("2014-01-02T15:04:05Z")) + }) - jsonValue, ok := jsonMap[key].(ISODate) - So(ok, ShouldBeTrue) - So(jsonValue, ShouldEqual, ISODate("2014-01-02T15:04:05Z")) - }) + Convey("will take valid format 2006-01-02T15:04-0700", func() { + var jsonMap map[string]interface{} + key := "key" + value := "ISODate(\"2006-01-02T15:04-0700\")" + data := fmt.Sprintf(`{"%v":%v}`, key, value) - Convey("will take valid format 2006-01-02T15:04-0700", func() { - var jsonMap map[string]interface{} + err := Unmarshal([]byte(data), &jsonMap) + So(err, ShouldBeNil) - key := "key" - value := "ISODate(\"2006-01-02T15:04-0700\")" - data := fmt.Sprintf(`{"%v":%v}`, key, value) + jsonValue, ok := jsonMap[key].(ISODate) + So(ok, ShouldBeTrue) + So(jsonValue, ShouldEqual, ISODate("2006-01-02T15:04-0700")) + }) - err := Unmarshal([]byte(data), &jsonMap) - So(err, ShouldBeNil) - - jsonValue, ok := jsonMap[key].(ISODate) - So(ok, ShouldBeTrue) - So(jsonValue, ShouldEqual, ISODate("2006-01-02T15:04-0700")) - }) - - - - }) + }) } - diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/maxkey_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/maxkey_test.go index 0934a75c0df..6914ba420d3 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/maxkey_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/maxkey_test.go @@ -8,11 +8,13 @@ package json import ( "fmt" + "github.com/mongodb/mongo-tools/common/testtype" . "github.com/smartystreets/goconvey/convey" "testing" ) func TestMaxKeyValue(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) key := "key" diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/minkey_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/minkey_test.go index d83325b67af..3fb469ea397 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/minkey_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/minkey_test.go @@ -8,11 +8,13 @@ package json import ( "fmt" + "github.com/mongodb/mongo-tools/common/testtype" . "github.com/smartystreets/goconvey/convey" "testing" ) func TestMinKeyValue(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) key := "key" Convey("Unmarshalling JSON with MinKey values", t, func() { diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/nan_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/nan_test.go index df26075a532..9cd4a920a11 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/nan_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/nan_test.go @@ -8,12 +8,14 @@ package json import ( "fmt" + "github.com/mongodb/mongo-tools/common/testtype" . "github.com/smartystreets/goconvey/convey" "math" "testing" ) func TestNaNValue(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("When unmarshalling JSON with NaN values", t, func() { diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/new_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/new_test.go index cbb9a132289..936327b1dc4 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/new_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/new_test.go @@ -8,11 +8,13 @@ package json import ( "fmt" + "github.com/mongodb/mongo-tools/common/testtype" . "github.com/smartystreets/goconvey/convey" "testing" ) func TestNewKeyword(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("When unmarshalling JSON using the new keyword", t, func() { diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/number_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/number_test.go index 99fc92f745e..3edadd93745 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/number_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/number_test.go @@ -8,11 +8,13 @@ package json import ( "fmt" + "github.com/mongodb/mongo-tools/common/testtype" . "github.com/smartystreets/goconvey/convey" "testing" ) func TestNumberIntValue(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("When unmarshalling JSON with NumberInt values", t, func() { @@ -105,6 +107,7 @@ func TestNumberIntValue(t *testing.T) { } func TestNumberLongValue(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("When unmarshalling JSON with NumberLong values", t, func() { diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/objectid_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/objectid_test.go index ab5bd99dd93..1f20af30170 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/objectid_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/objectid_test.go @@ -8,11 +8,13 @@ package json import ( "fmt" + "github.com/mongodb/mongo-tools/common/testtype" . "github.com/smartystreets/goconvey/convey" "testing" ) func TestObjectIdValue(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("When unmarshalling JSON with ObjectId values", t, func() { diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/regexp_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/regexp_test.go index d1632b76392..1eae1ddf389 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/regexp_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/regexp_test.go @@ -8,11 +8,13 @@ package json import ( "fmt" + "github.com/mongodb/mongo-tools/common/testtype" . "github.com/smartystreets/goconvey/convey" "testing" ) func TestRegExpValue(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("When unmarshalling JSON with RegExp values", t, func() { @@ -113,6 +115,7 @@ func TestRegExpValue(t *testing.T) { } func TestRegexpLiteral(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("When unmarshalling JSON with regular expression literals", t, func() { diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/scanner_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/scanner_test.go index 0c6cae7e081..51d842c1fdf 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/scanner_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/scanner_test.go @@ -11,6 +11,7 @@ package json import ( "bytes" + "github.com/mongodb/mongo-tools/common/testtype" "math" "math/rand" "reflect" @@ -49,6 +50,7 @@ var ex1i = `[ ]` func TestCompact(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) var buf bytes.Buffer for _, tt := range examples { buf.Reset() @@ -69,6 +71,7 @@ func TestCompact(t *testing.T) { } func TestCompactSeparators(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) // U+2028 and U+2029 should be escaped inside strings. // They should not appear outside strings. tests := []struct { @@ -88,6 +91,7 @@ func TestCompactSeparators(t *testing.T) { } func TestIndent(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) var buf bytes.Buffer for _, tt := range examples { buf.Reset() @@ -110,6 +114,7 @@ func TestIndent(t *testing.T) { // Tests of a large random structure. func TestCompactBig(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) initBig() var buf bytes.Buffer if err := Compact(&buf, jsonBig); err != nil { @@ -124,6 +129,7 @@ func TestCompactBig(t *testing.T) { } func TestIndentBig(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) initBig() var buf bytes.Buffer if err := Indent(&buf, jsonBig, "", "\t"); err != nil { @@ -172,6 +178,7 @@ var indentErrorTests = []indentErrorTest{ } func TestIndentErrors(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) for i, tt := range indentErrorTests { var slice []uint8 buf := bytes.NewBuffer(slice) @@ -185,6 +192,7 @@ func TestIndentErrors(t *testing.T) { } func TestNextValueBig(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) initBig() var scan scanner item, rest, err := nextValue(jsonBig, &scan) @@ -213,6 +221,7 @@ func TestNextValueBig(t *testing.T) { var benchScan scanner func BenchmarkSkipValue(b *testing.B) { + testtype.SkipUnlessBenchmarkType(b, testtype.UnitTestType) initBig() for i := 0; i < b.N; i++ { nextValue(jsonBig, &benchScan) @@ -221,6 +230,7 @@ func BenchmarkSkipValue(b *testing.B) { } func diff(t *testing.T, a, b []byte) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) for i := 0; ; i++ { if i >= len(a) || i >= len(b) || a[i] != b[i] { j := i - 10 diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/single_quoted_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/single_quoted_test.go index 741f96da037..596b0d0b08a 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/single_quoted_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/single_quoted_test.go @@ -8,11 +8,13 @@ package json import ( "fmt" + "github.com/mongodb/mongo-tools/common/testtype" . "github.com/smartystreets/goconvey/convey" "testing" ) func TestSingleQuotedKeys(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("When unmarshalling JSON with single quotes around its keys", t, func() { @@ -48,6 +50,7 @@ func TestSingleQuotedKeys(t *testing.T) { } func TestSingleQuotedValues(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("When unmarshalling JSON with single quotes around its values", t, func() { diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/stream_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/stream_test.go index ec8f4f54043..a45ac3d2ddf 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/stream_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/stream_test.go @@ -11,6 +11,7 @@ package json import ( "bytes" + "github.com/mongodb/mongo-tools/common/testtype" "io/ioutil" "net" "reflect" @@ -42,6 +43,7 @@ false ` func TestEncoder(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) for i := 0; i <= len(streamTest); i++ { var buf bytes.Buffer enc := NewEncoder(&buf) @@ -59,6 +61,7 @@ func TestEncoder(t *testing.T) { } func TestDecoder(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) for i := 0; i <= len(streamTest); i++ { // Use stream without newlines as input, // just to stress the decoder even more. @@ -91,6 +94,7 @@ func TestDecoder(t *testing.T) { } func TestDecoderBuffered(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) r := strings.NewReader(`{"Name": "Gopher"} extra `) var m struct { Name string @@ -127,6 +131,7 @@ func nlines(s string, n int) string { } func TestRawMessage(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) // TODO(rsc): Should not need the * in *RawMessage var data struct { X float64 @@ -152,6 +157,7 @@ func TestRawMessage(t *testing.T) { } func TestNullRawMessage(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) // TODO(rsc): Should not need the * in *RawMessage var data struct { X float64 @@ -182,6 +188,7 @@ var blockingTests = []string{ } func TestBlocking(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) for _, enc := range blockingTests { r, w := net.Pipe() go w.Write([]byte(enc)) @@ -198,6 +205,7 @@ func TestBlocking(t *testing.T) { } func BenchmarkEncoderEncode(b *testing.B) { + testtype.SkipUnlessBenchmarkType(b, testtype.UnitTestType) b.ReportAllocs() type T struct { X, Y string diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/tagkey_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/tagkey_test.go index 60e129dcf9f..67c2a852689 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/tagkey_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/tagkey_test.go @@ -10,6 +10,7 @@ package json import ( + "github.com/mongodb/mongo-tools/common/testtype" "testing" ) @@ -91,6 +92,7 @@ var structTagObjectKeyTests = []struct { } func TestStructTagObjectKey(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) for _, tt := range structTagObjectKeyTests { b, err := Marshal(tt.raw) if err != nil { diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/tags_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/tags_test.go index 24036587f0a..bf2a782c4ab 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/tags_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/tags_test.go @@ -10,10 +10,12 @@ package json import ( + "github.com/mongodb/mongo-tools/common/testtype" "testing" ) func TestTagParsing(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) name, opts := parseTag("field,foobar,foo") if name != "field" { t.Fatalf("name = %q, want field", name) diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/timestamp_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/timestamp_test.go index fdf2708a2a7..f522f923c70 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/timestamp_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/timestamp_test.go @@ -8,11 +8,13 @@ package json import ( "fmt" + "github.com/mongodb/mongo-tools/common/testtype" . "github.com/smartystreets/goconvey/convey" "testing" ) func TestTimestampValue(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("When unmarshalling JSON with Timestamp values", t, func() { diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/undefined_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/undefined_test.go index 76500bb607e..29df73bc9ae 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/undefined_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/undefined_test.go @@ -8,11 +8,13 @@ package json import ( "fmt" + "github.com/mongodb/mongo-tools/common/testtype" . "github.com/smartystreets/goconvey/convey" "testing" ) func TestUndefinedValue(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("When unmarshalling JSON with undefined values", t, func() { diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/unquoted_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/unquoted_test.go index d2a780c38c1..7a4a99a584b 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/unquoted_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/json/unquoted_test.go @@ -8,11 +8,13 @@ package json import ( "fmt" + "github.com/mongodb/mongo-tools/common/testtype" . "github.com/smartystreets/goconvey/convey" "testing" ) func TestUnquotedKeys(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("When unmarshalling JSON without quotes around its keys", t, func() { diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/log/tool_logger_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/log/tool_logger_test.go index 1244b1f30cf..d258b225980 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/log/tool_logger_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/log/tool_logger_test.go @@ -13,6 +13,7 @@ import ( "testing" "time" + "github.com/mongodb/mongo-tools/common/testtype" . "github.com/smartystreets/goconvey/convey" ) @@ -25,6 +26,7 @@ func (v verbosity) IsQuiet() bool { return v.Q } func (v verbosity) Level() int { return v.L } func TestBasicToolLoggerFunctionality(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) var tl *ToolLogger oldTime := time.Now() @@ -73,6 +75,7 @@ func TestBasicToolLoggerFunctionality(t *testing.T) { } func TestGlobalToolLoggerFunctionality(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) globalToolLogger = nil // just to be sure Convey("With an initialized global ToolLogger", t, func() { @@ -89,6 +92,7 @@ func TestGlobalToolLoggerFunctionality(t *testing.T) { } func TestToolLoggerWriter(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("With a tool logger that writes to a buffer", t, func() { buff := bytes.NewBuffer(make([]byte, 1024)) tl := NewToolLogger(&verbosity{L: 3}) diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/options/options_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/options/options_test.go index fbf603c8947..cda13773d75 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/options/options_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/options/options_test.go @@ -10,12 +10,14 @@ import ( "github.com/mongodb/mongo-tools/common/connstring" . "github.com/smartystreets/goconvey/convey" + "github.com/mongodb/mongo-tools/common/testtype" "runtime" "testing" "time" ) func TestVerbosityFlag(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("With a new ToolOptions", t, func() { enabled := EnabledOptions{false, false, false, false} optPtr := New("", "", enabled) @@ -96,6 +98,7 @@ type uriTester struct { } func TestParseAndSetOptions(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("With a matrix of URIs and expected results", t, func() { enabledURIOnly := EnabledOptions{false, false, false, true} testCases := []uriTester{ @@ -410,6 +413,7 @@ func TestParseAndSetOptions(t *testing.T) { // Regression test for TOOLS-1694 to prevent issue from TOOLS-1115 func TestHiddenOptionsDefaults(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("With a ToolOptions parsed", t, func() { enabled := EnabledOptions{Connection: true} opts := New("", "", enabled) diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/progress/manager_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/progress/manager_test.go index e9121cc7b68..1fc4d7f7c1c 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/progress/manager_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/progress/manager_test.go @@ -8,6 +8,7 @@ package progress import ( "bytes" + "github.com/mongodb/mongo-tools/common/testtype" . "github.com/smartystreets/goconvey/convey" "strconv" "strings" @@ -40,6 +41,7 @@ func (b *safeBuffer) Reset() { } func TestManagerAttachAndDetach(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) writeBuffer := new(safeBuffer) var manager *BarWriter @@ -111,6 +113,7 @@ func TestManagerAttachAndDetach(t *testing.T) { } func TestManagerStartAndStop(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) writeBuffer := new(safeBuffer) var manager *BarWriter @@ -143,6 +146,7 @@ func TestManagerStartAndStop(t *testing.T) { } func TestNumberOfWrites(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) var cw *CountWriter var manager *BarWriter Convey("With a test manager and counting writer", t, func() { diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/progress/progress_bar_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/progress/progress_bar_test.go index b6a58dadc37..f5851196ada 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/progress/progress_bar_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/progress/progress_bar_test.go @@ -15,9 +15,12 @@ import ( "strings" "testing" "time" + + "github.com/mongodb/mongo-tools/common/testtype" ) func TestBasicProgressBar(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) writeBuffer := &bytes.Buffer{} @@ -66,6 +69,7 @@ func TestBasicProgressBar(t *testing.T) { } func TestProgressBarWithNoMax(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) writeBuffer := &bytes.Buffer{} Convey("With a simple ProgressBar with no max value", t, func() { @@ -87,6 +91,7 @@ func TestProgressBarWithNoMax(t *testing.T) { } func TestBarConcurrency(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) writeBuffer := &bytes.Buffer{} Convey("With a simple ProgressBar", t, func() { @@ -123,6 +128,7 @@ func TestBarConcurrency(t *testing.T) { } func TestBarDrawing(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("Drawing some test bars and checking their character counts", t, func() { Convey("20 wide @ 50%", func() { b := drawBar(20, .5) @@ -170,6 +176,7 @@ func TestBarDrawing(t *testing.T) { } func TestBarUnits(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) writeBuffer := &bytes.Buffer{} Convey("With a simple ProgressBar with IsBytes==true", t, func() { diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/testtype/types.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/testtype/types.go index 52c6c58d187..0993f9b4cbc 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/testtype/types.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/testtype/types.go @@ -7,8 +7,7 @@ package testtype import ( - "flag" - "strings" + "os" "testing" ) @@ -16,48 +15,43 @@ const ( // Integration tests require a mongod running on localhost:33333. If your // mongod uses SSL you need to specify the "ssl" type below, and ditto for // if your mongod requires auth. - IntegrationTestType = "integration" + // First checks for a URI for a Mongod in the env variable TOOLS_TESTING_MONGOD. If it does not find it, looks on localhost:33333 + IntegrationTestType = "TOOLS_TESTING_INTEGRATION" // Unit tests don't require a real mongod. They may still do file I/O. - UnitTestType = "unit" + UnitTestType = "TOOLS_TESTING_UNIT" // Kerberos tests are a special type of integration test that test tools // with Kerberos authentication against the drivers Kerberos testing cluster // because setting up a KDC every time is too brittle and expensive. // (See https://wiki.mongodb.com/display/DH/Testing+Kerberos) - KerberosTestType = "kerberos" + KerberosTestType = "TOOLS_TESTING_KERBEROS" - // "ssl" and "auth" are used to configure integration tests to run against - // different mongod configurations. "ssl" will configure the integration tests - // to expect an SSL-enabled mongod on localhost:33333. "auth" will do the same + // "TOOLS_TESTING_SSL" and "TOOLS_TESTING_AUTH" are used to configure integration tests to run against + // different mongod configurations. "TOOLS_TESTING_SSL" will configure the integration tests + // to expect an SSL-enabled mongod on localhost:33333. "TOOLS_TESTING_AUTH" will do the same // for an auth-enabled mongod on localhost:33333. - SSLTestType = "ssl" - AuthTestType = "auth" -) + SSLTestType = "TOOLS_TESTING_SSL" + AuthTestType = "TOOLS_TESTING_AUTH" -var ( - // the types of tests that should be run - testTypes = flag.String("test.types", UnitTestType, "Comma-separated list of the"+ - " types of tests to be run") + // For now mongoreplay tests are unique, and will have to be explicitly run. + MongoReplayTestType = "TOOLS_TESTING_REPLAY" ) func HasTestType(testType string) bool { - if !flag.Parsed() { - flag.Parse() - } - - // skip the test if the passed-in type is not being run - for _, typ := range strings.Split(*testTypes, ",") { - if typ == testType { - return true - } - } - return false + envVal := os.Getenv(testType) + return envVal == "true" } // Skip the test if the specified type is not being run. -func VerifyTestType(t *testing.T, testType string) { +func SkipUnlessTestType(t *testing.T, testType string) { if !HasTestType(testType) { t.SkipNow() } } + +func SkipUnlessBenchmarkType(b *testing.B, testType string) { + if !HasTestType(testType) { + b.SkipNow() + } +} diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/testutil/auth.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/testutil/auth.go index 9264781b649..dbb21946015 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/testutil/auth.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/testutil/auth.go @@ -18,8 +18,8 @@ import ( var ( UserAdmin = "uAdmin" UserAdminPassword = "password" - CreatedUserNameEnv = "AUTH_USERNAME" - CreatedUserPasswordEnv = "AUTH_PASSWORD" + CreatedUserNameEnv = "TOOLS_TESTING_AUTH_USERNAME" + CreatedUserPasswordEnv = "TOOLS_TESTING_AUTH_PASSWORD" ) // Initialize a user admin, using the already-connected session passed in. diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/testutil/testutil.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/testutil/testutil.go index 5fdadc499e8..4efedd9e149 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/testutil/testutil.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/testutil/testutil.go @@ -38,7 +38,7 @@ func GetBareSessionProvider() (*db.SessionProvider, *options.ToolOptions, error) var toolOptions *options.ToolOptions // get ToolOptions from URI or defaults - if uri := os.Getenv("MONGOD"); uri != "" { + if uri := os.Getenv("TOOLS_TESTING_MONGOD"); uri != "" { fakeArgs := []string{"--uri=" + uri} toolOptions = options.New("mongodump", "", options.EnabledOptions{URI: true}) toolOptions.URI.AddKnownURIParameters(options.KnownURIOptionsReadPreference) diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/text/grid_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/text/grid_test.go index 39008d7f274..d55000959e9 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/text/grid_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/text/grid_test.go @@ -9,11 +9,13 @@ package text import ( "bytes" "fmt" + "github.com/mongodb/mongo-tools/common/testtype" . "github.com/smartystreets/goconvey/convey" "testing" ) func TestUpdateWidths(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("Using a grid writer, the cached column width", t, func() { gw := GridWriter{} defaultWidths := []int{1, 2, 3, 4} @@ -51,6 +53,7 @@ func writeData(gw *GridWriter) { } func TestWriteGrid(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("Test grid writer with no min width", t, func() { gw := GridWriter{} writeData(&gw) diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/text/units_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/text/units_test.go index bc25e14affc..90011240cbc 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/text/units_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/text/units_test.go @@ -7,12 +7,14 @@ package text import ( + "github.com/mongodb/mongo-tools/common/testtype" "testing" . "github.com/smartystreets/goconvey/convey" ) func TestFormatByteCount(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("With some sample byte amounts", t, func() { Convey("0 Bytes -> 0B", func() { So(FormatByteAmount(0), ShouldEqual, "0B") @@ -36,6 +38,7 @@ func TestFormatByteCount(t *testing.T) { } func TestOtherByteFormats(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("With some sample byte amounts", t, func() { Convey("with '10'", func() { Convey("FormatMegabyteAmount -> 10.0M", func() { @@ -64,6 +67,7 @@ func TestOtherByteFormats(t *testing.T) { } func TestBitFormatPrecision(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("With values less than 1k", t, func() { Convey("with '999'", func() { Convey("FormatBits -> 999b", func() { diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/util/bool_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/util/bool_test.go index 770b94c8912..0068defee3a 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/util/bool_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/util/bool_test.go @@ -7,6 +7,7 @@ package util import ( + "github.com/mongodb/mongo-tools/common/testtype" . "github.com/smartystreets/goconvey/convey" "gopkg.in/mgo.v2/bson" "math" @@ -14,6 +15,7 @@ import ( ) func TestJSTruthyValues(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("With some sample values", t, func() { Convey("known server code edge cases are correct", func() { Convey("true -> true", func() { diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/util/format_date_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/util/format_date_test.go index 5ae5923731a..73a4aca64de 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/util/format_date_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/util/format_date_test.go @@ -7,49 +7,47 @@ package util import ( - . "github.com/smartystreets/goconvey/convey" - "testing" + "github.com/mongodb/mongo-tools/common/testtype" + . "github.com/smartystreets/goconvey/convey" + "testing" ) func TestFormatDate(t *testing.T) { - - Convey("will take valid format 2006-01-02T15:04:05.000Z", t, func() { - _, err := FormatDate("2014-01-02T15:04:05.000Z") - So(err, ShouldBeNil) - }) - - - Convey("will take valid format 2006-01-02T15:04:05Z", t, func() { - _, err := FormatDate("2014-03-02T15:05:05Z") - So(err, ShouldBeNil) - }) - - - Convey("will take valid format 2006-01-02T15:04Z", t, func() { - _, err := FormatDate("2014-04-02T15:04Z") - So(err, ShouldBeNil) - }) - - Convey("will take valid format 2006-01-02T15:04-0700", t, func() { - _, err := FormatDate("2014-04-02T15:04-0800") - So(err, ShouldBeNil) - }) - - Convey("will take valid format 2006-01-02T15:04:05.000-0700", t, func() { - _, err := FormatDate("2014-04-02T15:04:05.000-0600") - So(err, ShouldBeNil) - }) - - - Convey("will take valid format 2006-01-02T15:04:05-0700", t, func() { - _, err := FormatDate("2014-04-02T15:04:05-0500") - So(err, ShouldBeNil) - }) - - Convey("will return an error for an invalid format", t, func() { - _, err := FormatDate("invalid string format") - So(err, ShouldNotBeNil) - }) + testtype.SkipUnlessTestType(t, testtype.UnitTestType) + + Convey("will take valid format 2006-01-02T15:04:05.000Z", t, func() { + _, err := FormatDate("2014-01-02T15:04:05.000Z") + So(err, ShouldBeNil) + }) + + Convey("will take valid format 2006-01-02T15:04:05Z", t, func() { + _, err := FormatDate("2014-03-02T15:05:05Z") + So(err, ShouldBeNil) + }) + + Convey("will take valid format 2006-01-02T15:04Z", t, func() { + _, err := FormatDate("2014-04-02T15:04Z") + So(err, ShouldBeNil) + }) + + Convey("will take valid format 2006-01-02T15:04-0700", t, func() { + _, err := FormatDate("2014-04-02T15:04-0800") + So(err, ShouldBeNil) + }) + + Convey("will take valid format 2006-01-02T15:04:05.000-0700", t, func() { + _, err := FormatDate("2014-04-02T15:04:05.000-0600") + So(err, ShouldBeNil) + }) + + Convey("will take valid format 2006-01-02T15:04:05-0700", t, func() { + _, err := FormatDate("2014-04-02T15:04:05-0500") + So(err, ShouldBeNil) + }) + + Convey("will return an error for an invalid format", t, func() { + _, err := FormatDate("invalid string format") + So(err, ShouldNotBeNil) + }) } - diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/util/math_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/util/math_test.go index 51bf93a986f..43349931237 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/util/math_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/util/math_test.go @@ -16,7 +16,7 @@ import ( func TestMaxInt(t *testing.T) { - testtype.VerifyTestType(t, testtype.UnitTestType) + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("When finding the maximum of two ints", t, func() { @@ -32,7 +32,7 @@ func TestMaxInt(t *testing.T) { func TestNumberConverter(t *testing.T) { - testtype.VerifyTestType(t, testtype.UnitTestType) + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("With a number converter for float32", t, func() { floatConverter := newNumberConverter(reflect.TypeOf(float32(0))) @@ -62,7 +62,7 @@ func TestNumberConverter(t *testing.T) { func TestUInt32Converter(t *testing.T) { - testtype.VerifyTestType(t, testtype.UnitTestType) + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("With a series of test values, conversions should pass", t, func() { out, err := ToUInt32(int64(99)) diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/util/mongo_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/util/mongo_test.go index 15ced783966..0bff112d8e5 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/util/mongo_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/common/util/mongo_test.go @@ -15,7 +15,7 @@ import ( func TestParseConnectionString(t *testing.T) { - testtype.VerifyTestType(t, testtype.UnitTestType) + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("When extracting the replica set and hosts from a connection"+ " url", t, func() { @@ -47,7 +47,7 @@ func TestParseConnectionString(t *testing.T) { func TestCreateConnectionAddrs(t *testing.T) { - testtype.VerifyTestType(t, testtype.UnitTestType) + testtype.SkipUnlessTestType(t, testtype.UnitTestType) Convey("When creating the slice of connection addresses", t, func() { @@ -73,6 +73,8 @@ func TestCreateConnectionAddrs(t *testing.T) { func TestInvalidNames(t *testing.T) { + testtype.SkipUnlessTestType(t, testtype.UnitTestType) + Convey("Checking some invalid collection names, ", t, func() { Convey("test.col$ is invalid", func() { So(ValidateDBName("test"), ShouldBeNil) |