From 43094be4583ffc3319f666a4e6bea41bda6c07f4 Mon Sep 17 00:00:00 2001 From: Carlos Salguero Date: Mon, 13 Nov 2017 23:28:59 -0300 Subject: [PATCH] Fixed pt-mongodb-query-digest tests --- src/go/pt-mongodb-query-digest/main.go | 3 ++- src/go/pt-mongodb-query-digest/main_test.go | 26 +++++++-------------- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/src/go/pt-mongodb-query-digest/main.go b/src/go/pt-mongodb-query-digest/main.go index ee09e9a1..04f23095 100644 --- a/src/go/pt-mongodb-query-digest/main.go +++ b/src/go/pt-mongodb-query-digest/main.go @@ -255,6 +255,7 @@ func getOptions() (*options, error) { OrderBy: strings.Split(DEFAULT_ORDERBY, ","), SkipCollections: strings.Split(DEFAULT_SKIPCOLLECTIONS, ","), AuthDB: DEFAULT_AUTHDB, + OutputFormat: "text", } gop := getopt.New() @@ -308,8 +309,8 @@ func getOptions() (*options, error) { } if opts.OutputFormat != "json" && opts.OutputFormat != "text" { - opts.OutputFormat = "text" log.Infof("Invalid output format '%s'. Using text format", opts.OutputFormat) + opts.OutputFormat = "text" } if gop.IsSet("password") && opts.Password == "" { diff --git a/src/go/pt-mongodb-query-digest/main_test.go b/src/go/pt-mongodb-query-digest/main_test.go index 0bcf15a8..7e86b752 100644 --- a/src/go/pt-mongodb-query-digest/main_test.go +++ b/src/go/pt-mongodb-query-digest/main_test.go @@ -18,6 +18,7 @@ import ( "text/template" "time" + "github.com/kr/pretty" "github.com/pborman/getopt/v2" "github.com/percona/percona-toolkit/src/go/lib/profiling" "github.com/percona/percona-toolkit/src/go/lib/tutil" @@ -235,24 +236,10 @@ func testEmptySystemProfile(t *testing.T, data Data) { t.Error(err) } - expected := `pt-mongodb-query-digest .+ -Host: ` + data.url + ` -Skipping profiled queries on these collections: \[system\.profile\] - - -# Totals -# Ratio 0.00 \(docs scanned/returned\) -# Attribute pct total min max avg 95% stddev median -# ================== === ======== ======== ======== ======== ======== ======= ======== -# Count \(docs\) 0\s -# Exec Time ms 0 NaN NaN NaN NaN NaN NaN NaN\s -# Docs Scanned 0 NaN NaN NaN NaN NaN NaN NaN\s -# Docs Returned 0 NaN NaN NaN NaN NaN NaN NaN\s -# Bytes sent 0 NaN NaN NaN NaN NaN NaN NaN\s -#\s -` - - assertRegexpLines(t, expected, string(output)) + expected := "No queries found in profiler information for database \\\"test\\\"" + if !strings.Contains(string(output), expected) { + t.Errorf("Empty system.profile.\nGot:\n%s\nWant:\n%s\n", string(output), expected) + } } func testAllOperationsTemplate(t *testing.T, data Data) { @@ -463,6 +450,9 @@ Skipping profiled queries on these collections: \[system\.profile\] expected += buf.String() } + fmt.Println("====================================================================================================") + pretty.Println(string(output)) + fmt.Println("====================================================================================================") assertRegexpLines(t, expected, string(output)) }