From 61fb4a4ea848508313561fd6280be9e81d0018bd Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Thu, 5 Sep 2019 19:15:55 +0800 Subject: [PATCH] tools: fix TLS in pd control (#1729) Signed-off-by: Ryan Leung --- tests/pdctl/cluster/cluster_test.go | 15 +++++++++++++++ tools/pd-ctl/pdctl/ctl.go | 1 + 2 files changed, 16 insertions(+) diff --git a/tests/pdctl/cluster/cluster_test.go b/tests/pdctl/cluster/cluster_test.go index 26ee802d89b..d3ec229c656 100644 --- a/tests/pdctl/cluster/cluster_test.go +++ b/tests/pdctl/cluster/cluster_test.go @@ -15,6 +15,10 @@ package cluster_test import ( "encoding/json" + "io/ioutil" + "os" + "path/filepath" + "strings" "testing" . "github.com/pingcap/check" @@ -22,6 +26,7 @@ import ( "github.com/pingcap/pd/server" "github.com/pingcap/pd/tests" "github.com/pingcap/pd/tests/pdctl" + ctl "github.com/pingcap/pd/tools/pd-ctl/pdctl" ) func Test(t *testing.T) { @@ -56,6 +61,16 @@ func (s *clusterTestSuite) TestClusterAndPing(c *C) { c.Assert(json.Unmarshal(output, ci), IsNil) c.Assert(ci, DeepEquals, cluster.GetCluster()) + fname := filepath.Join(os.TempDir(), "stdout") + old := os.Stdout + temp, _ := os.Create(fname) + os.Stdout = temp + ctl.Start([]string{"-u", pdAddr, "--cacert=ca.pem", "cluster"}) + temp.Close() + os.Stdout = old + out, _ := ioutil.ReadFile(fname) + c.Assert(strings.Contains(string(out), "no such file or directory"), IsTrue) + // cluster status args = []string{"-u", pdAddr, "cluster", "status"} _, output, err = pdctl.ExecuteCommandC(cmd, args...) diff --git a/tools/pd-ctl/pdctl/ctl.go b/tools/pd-ctl/pdctl/ctl.go index dde22f9f472..dcbc2375349 100644 --- a/tools/pd-ctl/pdctl/ctl.go +++ b/tools/pd-ctl/pdctl/ctl.go @@ -67,6 +67,7 @@ func Start(args []string) { rootCmd.SetArgs(args) rootCmd.SilenceErrors = true + rootCmd.ParseFlags(args) rootCmd.SetUsageTemplate(command.UsageTemplate) rootCmd.SetOutput(os.Stdout)