1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
// Copyright (C) MongoDB, Inc. 2014-present.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
package mongorestore
import (
"github.com/mongodb/mongo-tools-common/testtype"
. "github.com/smartystreets/goconvey/convey"
"go.mongodb.org/mongo-driver/mongo/writeconcern"
"testing"
)
func TestWriteConcernOptionParsing(t *testing.T) {
testtype.SkipUnlessTestType(t, testtype.UnitTestType)
Convey("Testing write concern parsing from command line and URI", t, func() {
Convey("Parsing with neither URI nor command line option should set a majority write concern", func() {
opts, err := ParseOptions([]string{}, "", "")
So(err, ShouldBeNil)
So(opts.OutputOptions.WriteConcern, ShouldEqual, "")
So(opts.ToolOptions.WriteConcern, ShouldResemble, writeconcern.New(writeconcern.WMajority()))
})
Convey("Parsing with URI with no write concern specified in it should set a majority write concern", func() {
args := []string{
"--uri", "mongodb://localhost:27017/test",
}
opts, err := ParseOptions(args, "", "")
So(err, ShouldBeNil)
So(opts.ToolOptions.WriteConcern, ShouldResemble, writeconcern.New(writeconcern.WMajority()))
})
Convey("Parsing with writeconcern only in URI should set it correctly", func() {
args := []string{
"--uri", "mongodb://localhost:27017/test?w=2",
}
opts, err := ParseOptions(args, "", "")
So(err, ShouldBeNil)
So(opts.OutputOptions.WriteConcern, ShouldEqual, "")
So(opts.ToolOptions.WriteConcern, ShouldResemble, writeconcern.New(writeconcern.W(2)))
})
Convey("Parsing with writeconcern only in command line should set it correctly", func() {
args := []string{
"--writeConcern", "{w: 2, j: true}",
}
opts, err := ParseOptions(args, "", "")
So(err, ShouldBeNil)
So(opts.ToolOptions.WriteConcern, ShouldResemble, writeconcern.New(writeconcern.W(2), writeconcern.J(true)))
})
})
}
|