mirror of
https://github.com/status-im/consul.git
synced 2025-01-11 14:24:39 +00:00
Merge pull request #8331 from hashicorp/cli/fix-cas-when-zero
command: fix cas put when index=0 and better errors in put and delete
This commit is contained in:
commit
1cd5ef694f
@ -78,7 +78,7 @@ func (c *cmd) Run(args []string) int {
|
|||||||
|
|
||||||
// ModifyIndex is required for CAS
|
// ModifyIndex is required for CAS
|
||||||
if c.cas && c.modifyIndex == 0 {
|
if c.cas && c.modifyIndex == 0 {
|
||||||
c.UI.Error("Must specify -modify-index with -cas!")
|
c.UI.Error("Cannot delete a key that does not exist. Provide a -modify-index greater than than 0.")
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ func TestKVDeleteCommand_Validation(t *testing.T) {
|
|||||||
},
|
},
|
||||||
"-cas no -modify-index": {
|
"-cas no -modify-index": {
|
||||||
[]string{"-cas", "foo"},
|
[]string{"-cas", "foo"},
|
||||||
"Must specify -modify-index",
|
"Cannot delete a key that does not exist",
|
||||||
},
|
},
|
||||||
"-modify-index no -cas": {
|
"-modify-index no -cas": {
|
||||||
[]string{"-modify-index", "2", "foo"},
|
[]string{"-modify-index", "2", "foo"},
|
||||||
|
@ -99,12 +99,6 @@ func (c *cmd) Run(args []string) int {
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// ModifyIndex is required for CAS
|
|
||||||
if c.cas && c.modifyIndex == 0 {
|
|
||||||
c.UI.Error("Must specify -modify-index with -cas!")
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create and test the HTTP client
|
// Create and test the HTTP client
|
||||||
client, err := c.http.APIClient()
|
client, err := c.http.APIClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -127,6 +121,10 @@ func (c *cmd) Run(args []string) int {
|
|||||||
c.UI.Error(fmt.Sprintf("Error! Did not write to %s: %s", key, err))
|
c.UI.Error(fmt.Sprintf("Error! Did not write to %s: %s", key, err))
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
if !ok && c.modifyIndex == 0 {
|
||||||
|
c.UI.Error(fmt.Sprintf("Error! Did not write to %s: CAS performed with index=0 and key already exists.", key))
|
||||||
|
return 1
|
||||||
|
}
|
||||||
if !ok {
|
if !ok {
|
||||||
c.UI.Error(fmt.Sprintf("Error! Did not write to %s: CAS failed", key))
|
c.UI.Error(fmt.Sprintf("Error! Did not write to %s: CAS failed", key))
|
||||||
return 1
|
return 1
|
||||||
|
@ -39,10 +39,6 @@ func TestKVPutCommand_Validation(t *testing.T) {
|
|||||||
[]string{"-release", "foo"},
|
[]string{"-release", "foo"},
|
||||||
"Missing -session",
|
"Missing -session",
|
||||||
},
|
},
|
||||||
"-cas no -modify-index": {
|
|
||||||
[]string{"-cas", "foo"},
|
|
||||||
"Must specify -modify-index",
|
|
||||||
},
|
|
||||||
"no key": {
|
"no key": {
|
||||||
[]string{},
|
[]string{},
|
||||||
"Missing KEY argument",
|
"Missing KEY argument",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user