mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-20 10:55:01 +00:00
PMM-8575 migrate toolkit to modules (#512)
* PMM-8575 Fixed test Fixed sandbox used by go programs, updated all tests. * PMM-8575 Fixed test Fixed sandbox used by go programs, updated all tests. * Removed Gopkg * Switched to go 1.16 * Updated go.mod * Upgraded deps * Updated deps
This commit is contained in:
@@ -38,8 +38,8 @@ const (
|
||||
|
||||
envMongoDBStandalonePort = "TEST_MONGODB_STANDALONE_PORT"
|
||||
//
|
||||
envMongoDBUser = "TEST_MONGODB_ADMIN_USERNAME"
|
||||
envMongoDBPassword = "TEST_MONGODB_ADMIN_PASSWORD"
|
||||
envMongoDBUser = ""
|
||||
envMongoDBPassword = ""
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -86,9 +86,9 @@ var (
|
||||
// MongoDBMongosPort mongos port
|
||||
MongoDBMongosPort = getEnvDefault(envMongoDBMongosPort, "17000")
|
||||
// MongoDBUser username for all instances
|
||||
MongoDBUser = getEnvDefault(envMongoDBUser, "admin")
|
||||
MongoDBUser = getEnvDefault(envMongoDBUser, "")
|
||||
// MongoDBPassword password for all instances
|
||||
MongoDBPassword = getEnvDefault(envMongoDBPassword, "admin123456")
|
||||
MongoDBPassword = getEnvDefault(envMongoDBPassword, "")
|
||||
// MongoDBTimeout global connection timeout
|
||||
MongoDBTimeout = time.Duration(10) * time.Second
|
||||
|
||||
@@ -196,11 +196,13 @@ func TestClient(ctx context.Context, port string) (*mongo.Client, error) {
|
||||
ConnectTimeout: &to,
|
||||
Hosts: []string{net.JoinHostPort(hostname, port)},
|
||||
Direct: &direct,
|
||||
Auth: &options.Credential{
|
||||
}
|
||||
if MongoDBUser != "" {
|
||||
co.Auth = &options.Credential{
|
||||
Username: MongoDBUser,
|
||||
Password: MongoDBPassword,
|
||||
PasswordSet: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
client, err := mongo.Connect(ctx, co)
|
||||
@@ -215,3 +217,27 @@ func TestClient(ctx context.Context, port string) (*mongo.Client, error) {
|
||||
|
||||
return client, nil
|
||||
}
|
||||
|
||||
func TestClientOptions(port string) *options.ClientOptions {
|
||||
if port == "" {
|
||||
port = MongoDBShard1PrimaryPort
|
||||
}
|
||||
|
||||
hostname := "127.0.0.1"
|
||||
direct := true
|
||||
to := time.Second
|
||||
co := &options.ClientOptions{
|
||||
ConnectTimeout: &to,
|
||||
Hosts: []string{net.JoinHostPort(hostname, port)},
|
||||
Direct: &direct,
|
||||
}
|
||||
if MongoDBUser != "" {
|
||||
co.Auth = &options.Credential{
|
||||
Username: MongoDBUser,
|
||||
Password: MongoDBPassword,
|
||||
PasswordSet: true,
|
||||
}
|
||||
}
|
||||
|
||||
return co
|
||||
}
|
||||
|
Reference in New Issue
Block a user