etcdctl: respect --write-out

Support got clobbered about a month ago.
release-3.0
Anthony Romano 2016-04-11 15:16:11 -07:00
parent 3bad47d691
commit e5a2bd58ec
2 changed files with 40 additions and 0 deletions

View File

@ -38,6 +38,8 @@ func TestCtlV3GetPeerTLS(t *testing.T) { testCtl(t, getTest, withCfg(configPee
func TestCtlV3GetTimeout(t *testing.T) { testCtl(t, getTest, withDialTimeout(0)) }
func TestCtlV3GetQuorum(t *testing.T) { testCtl(t, getTest, withQuorum()) }
func TestCtlV3GetFormat(t *testing.T) { testCtl(t, getFormatTest) }
func TestCtlV3Del(t *testing.T) { testCtl(t, delTest) }
func TestCtlV3DelNoTLS(t *testing.T) { testCtl(t, delTest, withCfg(configNoTLS)) }
func TestCtlV3DelClientTLS(t *testing.T) { testCtl(t, delTest, withCfg(configClientTLS)) }
@ -218,6 +220,32 @@ func getTest(cx ctlCtx) {
}
}
func getFormatTest(cx ctlCtx) {
defer close(cx.errc)
if err := ctlV3Put(cx, "abc", "123", ""); err != nil {
cx.t.Fatal(err)
}
tests := []struct {
format string
wstr string
}{
{"simple", "abc"},
{"json", "\"key\":\"YWJj\""},
{"protobuf", "\x17\b\x93\xe7\xf6\x93\xd4ņ\xe14\x10\xed"},
}
for i, tt := range tests {
cmdArgs := append(ctlV3PrefixArgs(cx.epc, cx.dialTimeout), "get")
cmdArgs = append(cmdArgs, "--write-out="+tt.format)
cmdArgs = append(cmdArgs, "abc")
if err := spawnWithExpect(cmdArgs, tt.wstr); err != nil {
cx.t.Errorf("#%d: error (%v), wanted %v", i, err, tt.wstr)
}
}
}
func delTest(cx ctlCtx) {
defer close(cx.errc)

View File

@ -63,6 +63,18 @@ func mustClientFromCmd(cmd *cobra.Command) *clientv3.Client {
dialTimeout := dialTimeoutFromCmd(cmd)
sec := secureCfgFromCmd(cmd)
isHex, err := cmd.Flags().GetBool("hex")
if err != nil {
ExitWithError(ExitError, err)
}
outputType, err := cmd.Flags().GetString("write-out")
if err != nil {
ExitWithError(ExitError, err)
}
if display = NewPrinter(outputType, isHex); display == nil {
ExitWithError(ExitBadFeature, errors.New("unsupported output format"))
}
return mustClient(endpoints, dialTimeout, sec)
}