Merge pull request #2533 from mckennajones/bug2526
Fix for KV put command
This commit is contained in:
commit
dc37498327
|
@ -228,11 +228,15 @@ func (c *KVPutCommand) dataFromArgs(args []string) (string, string, error) {
|
|||
}
|
||||
return key, string(data), nil
|
||||
case '-':
|
||||
var b bytes.Buffer
|
||||
if _, err := io.Copy(&b, stdin); err != nil {
|
||||
return "", "", fmt.Errorf("Failed to read stdin: %s", err)
|
||||
if len(data) > 1 {
|
||||
return key, data, nil
|
||||
} else {
|
||||
var b bytes.Buffer
|
||||
if _, err := io.Copy(&b, stdin); err != nil {
|
||||
return "", "", fmt.Errorf("Failed to read stdin: %s", err)
|
||||
}
|
||||
return key, b.String(), nil
|
||||
}
|
||||
return key, b.String(), nil
|
||||
default:
|
||||
return key, data, nil
|
||||
}
|
||||
|
|
|
@ -194,6 +194,34 @@ func TestKVPutCommand_Stdin(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestKVPutCommand_NegativeVal(t *testing.T) {
|
||||
srv, client := testAgentWithAPIClient(t)
|
||||
defer srv.Shutdown()
|
||||
waitForLeader(t, srv.httpAddr)
|
||||
|
||||
ui := new(cli.MockUi)
|
||||
c := &KVPutCommand{Ui: ui}
|
||||
|
||||
args := []string{
|
||||
"-http-addr=" + srv.httpAddr,
|
||||
"foo", "-2",
|
||||
}
|
||||
|
||||
code := c.Run(args)
|
||||
if code != 0 {
|
||||
t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String())
|
||||
}
|
||||
|
||||
data, _, err := client.KV().Get("foo", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !bytes.Equal(data.Value, []byte("-2")) {
|
||||
t.Errorf("bad: %#v", data.Value)
|
||||
}
|
||||
}
|
||||
|
||||
func TestKVPutCommand_Flags(t *testing.T) {
|
||||
srv, client := testAgentWithAPIClient(t)
|
||||
defer srv.Shutdown()
|
||||
|
|
Loading…
Reference in a new issue