mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-07 21:09:14 +00:00
PT-183 pt-mongodb-query-digest fails to connect
Fixed connection params to connect to a db using authentication
This commit is contained in:
29
src/go/mongolib/fingerprinter/figerprinter_test.go
Normal file
29
src/go/mongolib/fingerprinter/figerprinter_test.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package fingerprinter
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestFingerprint(t *testing.T) {
|
||||
|
||||
query := map[string]interface{}{
|
||||
"find": "feedback",
|
||||
"filter": map[string]interface{}{
|
||||
"tool": "Atlas",
|
||||
"potId": "2c9180865ae33e85015af1cc29243dc5",
|
||||
},
|
||||
"limit": 1,
|
||||
"singleBatch": true,
|
||||
}
|
||||
want := "potId,tool"
|
||||
|
||||
fp := NewFingerprinter(nil)
|
||||
got, err := fp.Fingerprint(query)
|
||||
|
||||
if err != nil {
|
||||
t.Error("Error in fingerprint")
|
||||
}
|
||||
|
||||
if got != want {
|
||||
t.Errorf("Invalid fingerprint. Got: %q, want %q", got, want)
|
||||
}
|
||||
|
||||
}
|
@@ -95,6 +95,8 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
log.Debugf("Command line options:\n%+v\n", opts)
|
||||
|
||||
di := getDialInfo(opts)
|
||||
if di.Database == "" {
|
||||
log.Errorln("must indicate a database as host:[port]/database")
|
||||
@@ -104,6 +106,7 @@ func main() {
|
||||
|
||||
dialer := pmgo.NewDialer()
|
||||
session, err := dialer.DialWithInfo(di)
|
||||
log.Debugf("Dial Info: %+v\n", di)
|
||||
if err != nil {
|
||||
log.Errorf("Error connecting to the db: %s while trying to connect to %s", err, di.Addrs[0])
|
||||
os.Exit(3)
|
||||
@@ -278,10 +281,10 @@ func getDialInfo(opts *options) *pmgo.DialInfo {
|
||||
di, _ := mgo.ParseURL(opts.Host)
|
||||
di.FailFast = true
|
||||
|
||||
if di.Username != "" {
|
||||
if di.Username == "" {
|
||||
di.Username = opts.User
|
||||
}
|
||||
if di.Password != "" {
|
||||
if di.Password == "" {
|
||||
di.Password = opts.Password
|
||||
}
|
||||
if opts.AuthDB != "" {
|
||||
|
Reference in New Issue
Block a user