mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-20 19:04:59 +00:00
PT-2236 - pt-secure-collect, pt-pg-summary do not follow PT standard (#652)
* PT-2236 - pt-secure-collect, pt-pg-summary do not follow PT standard for option --version - Redirected UsageWriter to os.Stdout for kingpin, so --version output goes to STDOUT, not to STDERR - Adjusted text, printed by the --version flag - Added test cases to check how --version flag works - Adjusted test cases, so they use TOOLNAME constant * PT-2236 - pt-secure-collect, pt-pg-summary do not follow PT standard for option --version Run go mod tidy as requested by Artem Gavrilov * PT-2236 - pt-secure-collect, pt-pg-summary do not follow PT standard for option --version Renamed const TOOLNAME to toolname to follow Go coding standards
This commit is contained in:
@@ -67,7 +67,7 @@ type myDefaults struct {
|
||||
}
|
||||
|
||||
const (
|
||||
TOOLNAME = "pt-secure-collect"
|
||||
toolname = "pt-secure-collect"
|
||||
|
||||
decryptCmd = "decrypt"
|
||||
encryptCmd = "encrypt"
|
||||
@@ -172,15 +172,17 @@ func processCliParams(baseTempPath string, usageWriter io.Writer) (*cliOptions,
|
||||
}
|
||||
msg += "\n "
|
||||
|
||||
app := kingpin.New(TOOLNAME, msg)
|
||||
app := kingpin.New(toolname, msg)
|
||||
if usageWriter != nil {
|
||||
app.UsageWriter(usageWriter)
|
||||
app.Terminate(nil)
|
||||
} else {
|
||||
app.UsageWriter(os.Stdout)
|
||||
}
|
||||
|
||||
// Add support for --version flag
|
||||
app.Version(TOOLNAME + "\nVersion " + Version + "\nBuild: " + Build + " using " + GoVersion +
|
||||
" Go version: " + GoVersion)
|
||||
app.Version(toolname + "\nVersion " + Version + "\nBuild: " + Build + " using " + GoVersion +
|
||||
"\nCommit:" + Commit)
|
||||
|
||||
opts := &cliOptions{
|
||||
CollectCommand: app.Command(collectCmd, "Collect, sanitize, pack and encrypt data from pt-tools."),
|
||||
|
@@ -4,7 +4,9 @@ import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"os"
|
||||
"os/exec"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -38,3 +40,18 @@ func TestProcessCliParams(t *testing.T) {
|
||||
|
||||
func TestCollect(t *testing.T) {
|
||||
}
|
||||
|
||||
/*
|
||||
Option --version
|
||||
*/
|
||||
func TestVersionOption(t *testing.T) {
|
||||
out, err := exec.Command("../../../bin/"+toolname, "--version").Output()
|
||||
if err != nil {
|
||||
t.Errorf("error executing %s --version: %s", toolname, err.Error())
|
||||
}
|
||||
// We are using MustCompile here, because hard-coded RE should not fail
|
||||
re := regexp.MustCompile(toolname + `\n.*Version v?\d+\.\d+\.\d+\n`)
|
||||
if !re.Match(out) {
|
||||
t.Errorf("%s --version returns wrong result:\n%s", toolname, out)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user