mirror of https://github.com/status-im/consul.git
Merge pull request #3750 from hashicorp/kv-get-base64
Adds -base64 support to kv get command.
This commit is contained in:
commit
96e220a6a8
|
@ -169,7 +169,11 @@ func (c *cmd) Run(args []string) int {
|
|||
return 0
|
||||
}
|
||||
|
||||
c.UI.Info(string(pair.Value))
|
||||
if c.base64encode {
|
||||
c.UI.Info(base64.StdEncoding.EncodeToString(pair.Value))
|
||||
} else {
|
||||
c.UI.Info(string(pair.Value))
|
||||
}
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,6 +91,41 @@ func TestKVGetCommand(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestKVGetCommand_Base64(t *testing.T) {
|
||||
t.Parallel()
|
||||
a := agent.NewTestAgent(t.Name(), ``)
|
||||
defer a.Shutdown()
|
||||
client := a.Client()
|
||||
|
||||
ui := cli.NewMockUi()
|
||||
c := New(ui)
|
||||
|
||||
pair := &api.KVPair{
|
||||
Key: "foo",
|
||||
Value: []byte("bar"),
|
||||
}
|
||||
_, err := client.KV().Put(pair, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %#v", err)
|
||||
}
|
||||
|
||||
args := []string{
|
||||
"-http-addr=" + a.HTTPAddr(),
|
||||
"-base64",
|
||||
"foo",
|
||||
}
|
||||
|
||||
code := c.Run(args)
|
||||
if code != 0 {
|
||||
t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String())
|
||||
}
|
||||
|
||||
output := ui.OutputWriter.String()
|
||||
if !strings.Contains(output, base64.StdEncoding.EncodeToString(pair.Value)) {
|
||||
t.Errorf("bad: %#v", output)
|
||||
}
|
||||
}
|
||||
|
||||
func TestKVGetCommand_Missing(t *testing.T) {
|
||||
t.Parallel()
|
||||
a := agent.NewTestAgent(t.Name(), ``)
|
||||
|
|
Loading…
Reference in New Issue