PT-183 pt-mongodb-query-digest fails to connect

Fixed connection params to connect to a db using authentication
This commit is contained in:
Carlos Salguero
2017-08-02 15:23:35 -03:00
parent b46e8bc7c1
commit 05769ba234
2 changed files with 34 additions and 2 deletions

View 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)
}
}

View File

@@ -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 != "" {