diff options
| author | Thomas Schubert <thomas.schubert@mongodb.com> | 2017-07-31 23:03:23 -0400 |
|---|---|---|
| committer | Thomas Schubert <thomas.schubert@mongodb.com> | 2017-07-31 23:03:23 -0400 |
| commit | cf38c1b8a0a8dca4a11737581beafef4fe120bcd (patch) | |
| tree | 548b58b5bbf6672b7423cf30f646c40cfea4f240 /src/mongo/gotools/mongorestore | |
| parent | 4463700eb94a5ee95c706d69cbb7bf44e67a50d2 (diff) | |
Import tools: 4f093ae71cdb4c6a6e9de7cd1dc67ea4405f0013 from branch v3.4r3.4.7-rc0r3.4.7
ref: 29b8883c56..4f093ae71c
for: 3.4.7
TOOLS-1109 failes to build on arm64 (syscall.Dup2 not supported)
TOOLS-1542 dump and export shouldn't count views before running
TOOLS-1563 windows tests are failing after `use mongodb 3.4 "current" tests`
TOOLS-1577 update the readme with information about mongoreplay
TOOLS-1713 Move mongoreplay evergreen config .evergreen.yml into common.yml
TOOLS-1741 mongoimport --uri throws errors when passed Atlas Connection String URI
TOOLS-1743 legacy24 and legacy26 dumprestore tests failing on master
Diffstat (limited to 'src/mongo/gotools/mongorestore')
| -rw-r--r-- | src/mongo/gotools/mongorestore/options.go | 9 | ||||
| -rw-r--r-- | src/mongo/gotools/mongorestore/options_test.go | 74 |
2 files changed, 80 insertions, 3 deletions
diff --git a/src/mongo/gotools/mongorestore/options.go b/src/mongo/gotools/mongorestore/options.go index 93965cc3e2b..0913cf52e21 100644 --- a/src/mongo/gotools/mongorestore/options.go +++ b/src/mongo/gotools/mongorestore/options.go @@ -29,9 +29,12 @@ func (*InputOptions) Name() string { // OutputOptions defines the set of options for restoring dump data. type OutputOptions struct { - Drop bool `long:"drop" description:"drop each collection before import"` - DryRun bool `long:"dryRun" description:"view summary without importing anything. recommended with verbosity"` - WriteConcern string `long:"writeConcern" value-name:"<write-concern>" default:"majority" default-mask:"-" description:"write concern options e.g. --writeConcern majority, --writeConcern '{w: 3, wtimeout: 500, fsync: true, j: true}' (defaults to 'majority')"` + Drop bool `long:"drop" description:"drop each collection before import"` + DryRun bool `long:"dryRun" description:"view summary without importing anything. recommended with verbosity"` + + // By default mongorestore uses a write concern of 'majority'. + // Cannot be used simultaneously with write concern options in a URI. + WriteConcern string `long:"writeConcern" value-name:"<write-concern>" default-mask:"-" description:"write concern options e.g. --writeConcern majority, --writeConcern '{w: 3, wtimeout: 500, fsync: true, j: true}'"` NoIndexRestore bool `long:"noIndexRestore" description:"don't restore indexes"` NoOptionsRestore bool `long:"noOptionsRestore" description:"don't restore collection options"` KeepIndexVersion bool `long:"keepIndexVersion" description:"don't update index version"` diff --git a/src/mongo/gotools/mongorestore/options_test.go b/src/mongo/gotools/mongorestore/options_test.go new file mode 100644 index 00000000000..5513ecf2f02 --- /dev/null +++ b/src/mongo/gotools/mongorestore/options_test.go @@ -0,0 +1,74 @@ +package mongorestore + +import ( + "fmt" + "testing" + + "github.com/mongodb/mongo-tools/common/db" + "github.com/mongodb/mongo-tools/common/options" + . "github.com/smartystreets/goconvey/convey" +) + +// Regression test for TOOLS-1741 +func TestWriteConcernWithURIParsing(t *testing.T) { + Convey("With an IngestOptions and ToolsOptions", t, func() { + + // create an 'EnabledOptions' to determine what options should be able to be + // parsed and set form the input. + enabled := options.EnabledOptions{URI: true} + + // create a new tools options to hold the parsed options + opts := options.New("", "", enabled) + + // create a 'OutputOptions', which holds the value of the write concern + // for mongorestore. + outputOpts := &OutputOptions{} + opts.AddOptions(outputOpts) + + // Specify that a write concern set on the URI is not an error and is a known + // possible option. + opts.URI.AddKnownURIParameters(options.KnownURIOptionsWriteConcern) + + Convey("Parsing with no value should leave write concern empty", func() { + _, err := opts.ParseArgs([]string{}) + So(err, ShouldBeNil) + So(outputOpts.WriteConcern, ShouldEqual, "") + Convey("and building write concern object, WMode should be majority", func() { + sessionSafety, err := db.BuildWriteConcern(outputOpts.WriteConcern, "", + opts.ParsedConnString()) + So(err, ShouldBeNil) + So(sessionSafety.WMode, ShouldEqual, "majority") + }) + }) + + Convey("Parsing with no writeconcern in URI should not error", func() { + args := []string{ + "--uri", "mongodb://localhost:27017/test", + } + _, err := opts.ParseArgs(args) + So(err, ShouldBeNil) + So(outputOpts.WriteConcern, ShouldEqual, "") + Convey("and parsing write concern, WMode should be majority", func() { + sessionSafety, err := db.BuildWriteConcern(outputOpts.WriteConcern, "", + opts.ParsedConnString()) + So(err, ShouldBeNil) + So(sessionSafety, ShouldNotBeNil) + So(sessionSafety.WMode, ShouldEqual, "majority") + }) + }) + Convey("Parsing with both writeconcern in URI and command line should error", func() { + args := []string{ + "--uri", "mongodb://localhost:27017/test", + "--writeConcern", "majority", + } + _, err := opts.ParseArgs(args) + So(err, ShouldBeNil) + So(outputOpts.WriteConcern, ShouldEqual, "majority") + Convey("and parsing write concern, WMode should be majority", func() { + _, err := db.BuildWriteConcern(outputOpts.WriteConcern, "", + opts.ParsedConnString()) + So(err, ShouldResemble, fmt.Errorf("cannot specify writeConcern string and connectionString object")) + }) + }) + }) +} |
