本文整理匯總了Golang中github.com/mongodb/mongo-tools/common/testutil.GetSSLOptions函數的典型用法代碼示例。如果您正苦於以下問題:Golang GetSSLOptions函數的具體用法?Golang GetSSLOptions怎麽用?Golang GetSSLOptions使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了GetSSLOptions函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: simpleMongoDumpInstance
func simpleMongoDumpInstance() *MongoDump {
ssl := testutil.GetSSLOptions()
auth := testutil.GetAuthOptions()
namespace := &options.Namespace{
DB: testDB,
}
connection := &options.Connection{
Host: testServer,
Port: testPort,
}
toolOptions := &options.ToolOptions{
SSL: &ssl,
Namespace: namespace,
Connection: connection,
Auth: &auth,
HiddenOptions: &options.HiddenOptions{},
Verbosity: &options.Verbosity{},
}
outputOptions := &OutputOptions{}
inputOptions := &InputOptions{}
log.SetVerbosity(toolOptions.Verbosity)
return &MongoDump{
ToolOptions: toolOptions,
InputOptions: inputOptions,
OutputOptions: outputOptions,
ProgressManager: progress.NewProgressBarManager(log.Writer(0), progressBarWaitTime),
HandleSignals: HandleSignals,
}
}
示例2: simpleMongoDumpInstance
func simpleMongoDumpInstance() *MongoDump {
ssl := testutil.GetSSLOptions()
auth := testutil.GetAuthOptions()
namespace := &options.Namespace{
DB: testDB,
}
connection := &options.Connection{
Host: testServer,
Port: testPort,
}
toolOptions := &options.ToolOptions{
SSL: &ssl,
Namespace: namespace,
Connection: connection,
Auth: &auth,
Verbosity: &options.Verbosity{},
}
outputOptions := &OutputOptions{
NumParallelCollections: 1,
}
inputOptions := &InputOptions{}
log.SetVerbosity(toolOptions.Verbosity)
return &MongoDump{
ToolOptions: toolOptions,
InputOptions: inputOptions,
OutputOptions: outputOptions,
}
}
示例3: getBasicToolOptions
// getBasicToolOptions returns a test helper to instantiate the session provider
// for calls to StreamDocument
func getBasicToolOptions() *options.ToolOptions {
ssl := testutil.GetSSLOptions()
auth := testutil.GetAuthOptions()
namespace := &options.Namespace{
DB: testDb,
Collection: testCollection,
}
connection := &options.Connection{
Host: "localhost",
Port: db.DefaultTestPort,
}
return &options.ToolOptions{
SSL: &ssl,
Namespace: namespace,
Connection: connection,
HiddenOptions: &options.HiddenOptions{},
Auth: &auth,
}
}
示例4: getBareSession
func getBareSession() (*mgo.Session, error) {
ssl := testutil.GetSSLOptions()
auth := testutil.GetAuthOptions()
sessionProvider, err := db.NewSessionProvider(options.ToolOptions{
Connection: &options.Connection{
Host: testServer,
Port: testPort,
},
Auth: &auth,
SSL: &ssl,
})
if err != nil {
return nil, err
}
session, err := sessionProvider.GetSession()
if err != nil {
return nil, err
}
return session, nil
}
示例5: TestCollectionExists
func TestCollectionExists(t *testing.T) {
testutil.VerifyTestType(t, testutil.IntegrationTestType)
Convey("With a test mongorestore", t, func() {
ssl := testutil.GetSSLOptions()
auth := testutil.GetAuthOptions()
sessionProvider, err := db.NewSessionProvider(commonOpts.ToolOptions{
Connection: &commonOpts.Connection{
Host: "localhost",
Port: db.DefaultTestPort,
},
Auth: &auth,
SSL: &ssl,
})
So(err, ShouldBeNil)
restore := &MongoRestore{
SessionProvider: sessionProvider,
}
Convey("and some test data in a server", func() {
session, err := restore.SessionProvider.GetSession()
So(err, ShouldBeNil)
So(session.DB(ExistsDB).C("one").Insert(bson.M{}), ShouldBeNil)
So(session.DB(ExistsDB).C("two").Insert(bson.M{}), ShouldBeNil)
So(session.DB(ExistsDB).C("three").Insert(bson.M{}), ShouldBeNil)
Convey("collections that exist should return true", func() {
exists, err := restore.CollectionExists(&intents.Intent{DB: ExistsDB, C: "one"})
So(err, ShouldBeNil)
So(exists, ShouldBeTrue)
exists, err = restore.CollectionExists(&intents.Intent{DB: ExistsDB, C: "two"})
So(err, ShouldBeNil)
So(exists, ShouldBeTrue)
exists, err = restore.CollectionExists(&intents.Intent{DB: ExistsDB, C: "three"})
So(err, ShouldBeNil)
So(exists, ShouldBeTrue)
Convey("and those that do not exist should return false", func() {
exists, err = restore.CollectionExists(&intents.Intent{DB: ExistsDB, C: "four"})
So(err, ShouldBeNil)
So(exists, ShouldBeFalse)
})
})
Reset(func() {
session.DB(ExistsDB).DropDatabase()
session.Close()
})
})
Convey("and a fake cache should be used instead of the server when it exists", func() {
restore.knownCollections = map[string][]string{
ExistsDB: []string{"cats", "dogs", "snakes"},
}
exists, err := restore.CollectionExists(&intents.Intent{DB: ExistsDB, C: "dogs"})
So(err, ShouldBeNil)
So(exists, ShouldBeTrue)
exists, err = restore.CollectionExists(&intents.Intent{DB: ExistsDB, C: "two"})
So(err, ShouldBeNil)
So(exists, ShouldBeFalse)
})
})
}
示例6: setUpGridFSTestData
"github.com/mongodb/mongo-tools/common/util"
. "github.com/smartystreets/goconvey/convey"
"gopkg.in/mgo.v2"
"io"
"io/ioutil"
"os"
"strings"
"testing"
)
var (
testDB = "mongofiles_test_db"
testServer = "localhost"
testPort = db.DefaultTestPort
ssl = testutil.GetSSLOptions()
auth = testutil.GetAuthOptions()
connection = &options.Connection{
Host: testServer,
Port: testPort,
}
toolOptions = &options.ToolOptions{
SSL: &ssl,
Connection: connection,
Auth: &auth,
Verbosity: &options.Verbosity{},
}
)
// put in some test data into GridFS
func setUpGridFSTestData() ([]interface{}, error) {
示例7: TestBasicOps
func TestBasicOps(t *testing.T) {
testutil.VerifyTestType(t, testutil.IntegrationTestType)
var opts *options.ToolOptions
var sourceOpts *SourceOptions
Convey("When replicating operations", t, func() {
ssl := testutil.GetSSLOptions()
auth := testutil.GetAuthOptions()
// specify localhost:33333 as the destination host
opts = &options.ToolOptions{
Namespace: &options.Namespace{},
SSL: &ssl,
Auth: &auth,
Kerberos: &options.Kerberos{},
Connection: &options.Connection{
Host: "localhost",
Port: db.DefaultTestPort,
},
}
// specify localhost:33333 as the source host
sourceOpts = &SourceOptions{
Seconds: 84600, // the default
OplogNS: "local.oplog.rs", // the default
}
Convey("all operations should be applied correctly, without"+
" error", func() {
// set the "oplog" we will use
sourceOpts.OplogNS = "mongooplog_test.oplog"
// initialize a session provider for the source
sourceSP, err := db.NewSessionProvider(*opts)
So(err, ShouldBeNil)
// initialize a session provider for the destination
destSP, err := db.NewSessionProvider(*opts)
So(err, ShouldBeNil)
// clear out the oplog
sess, err := sourceSP.GetSession()
So(err, ShouldBeNil)
defer sess.Close()
oplogColl := sess.DB("mongooplog_test").C("oplog")
oplogColl.DropCollection()
// create the oplog as a capped collection, so it can be tailed
So(sess.DB("mongooplog_test").Run(
bson.D{{"create", "oplog"}, {"capped", true},
{"size", 10000}},
bson.M{}),
ShouldBeNil)
// create the collection we are testing against (ignore errors)
sess.DB("mongooplog_test").C("data").Create(&mgo.CollectionInfo{})
// clear out the collection we'll use for testing
testColl := sess.DB("mongooplog_test").C("data")
_, err = testColl.RemoveAll(bson.M{})
So(err, ShouldBeNil)
// insert some "ops" into the oplog to be found and applied
op1 := &db.Oplog{
Timestamp: bson.MongoTimestamp(1<<63 - 1), // years in the future
HistoryID: 100,
Version: 2,
Operation: "i",
Namespace: "mongooplog_test.data",
Object: bson.D{
bson.DocElem{
"_id", 3,
},
},
}
So(oplogColl.Insert(op1), ShouldBeNil)
op2 := &db.Oplog{
Timestamp: bson.MongoTimestamp(1<<63 - 1), // years in the future
HistoryID: 200,
Version: 2,
Operation: "i",
Namespace: "mongooplog_test.data",
Object: bson.D{
bson.DocElem{
"_id", 4,
},
},
}
So(oplogColl.Insert(op2), ShouldBeNil)
// this one should be filtered out, since it occurred before the
// threshold
op3 := &db.Oplog{
Timestamp: bson.MongoTimestamp(1<<62 - 1), // more than 1 day in the past
HistoryID: 300,
Version: 2,
Operation: "i",
Namespace: "mongooplog_test.data",
//.........這裏部分代碼省略.........
示例8: TestMongorestore
func TestMongorestore(t *testing.T) {
ssl := testutil.GetSSLOptions()
auth := testutil.GetAuthOptions()
testutil.VerifyTestType(t, testutil.IntegrationTestType)
toolOptions := &options.ToolOptions{
Connection: &options.Connection{
Host: testServer,
Port: testPort,
},
Auth: &auth,
SSL: &ssl,
}
inputOptions := &InputOptions{}
outputOptions := &OutputOptions{
NumParallelCollections: 1,
NumInsertionWorkers: 1,
WriteConcern: "majority",
}
nsOptions := &NSOptions{}
Convey("With a test MongoRestore", t, func() {
provider, err := db.NewSessionProvider(*toolOptions)
if err != nil {
log.Logvf(log.Always, "error connecting to host: %v", err)
os.Exit(util.ExitError)
}
restore := MongoRestore{
ToolOptions: toolOptions,
OutputOptions: outputOptions,
InputOptions: inputOptions,
NSOptions: nsOptions,
SessionProvider: provider,
}
session, _ := provider.GetSession()
c1 := session.DB("db1").C("c1")
c1.DropCollection()
Convey("and an explicit target restores from that dump directory", func() {
restore.TargetDirectory = "testdata/testdirs"
err = restore.Restore()
So(err, ShouldBeNil)
count, err := c1.Count()
So(err, ShouldBeNil)
So(count, ShouldEqual, 100)
})
Convey("and an target of '-' restores from standard input", func() {
bsonFile, err := os.Open("testdata/testdirs/db1/c1.bson")
restore.NSOptions.Collection = "c1"
restore.NSOptions.DB = "db1"
So(err, ShouldBeNil)
restore.stdin = bsonFile
restore.TargetDirectory = "-"
err = restore.Restore()
So(err, ShouldBeNil)
count, err := c1.Count()
So(err, ShouldBeNil)
So(count, ShouldEqual, 100)
})
})
}