mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
etcdctl: respect --write-out
Support got clobbered about a month ago.
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user