mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #5055 from gyuho/get_rev
*: add rev flag to get command
This commit is contained in:
commit
c8e860c4fa
@ -39,6 +39,7 @@ 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 TestCtlV3GetRev(t *testing.T) { testCtl(t, getRevTest) }
|
||||
|
||||
func TestCtlV3Del(t *testing.T) { testCtl(t, delTest) }
|
||||
func TestCtlV3DelNoTLS(t *testing.T) { testCtl(t, delTest, withCfg(configNoTLS)) }
|
||||
@ -185,6 +186,11 @@ func getTest(cx ctlCtx) {
|
||||
kvs = []kv{{"key1", "val1"}, {"key2", "val2"}, {"key3", "val3"}}
|
||||
revkvs = []kv{{"key3", "val3"}, {"key2", "val2"}, {"key1", "val1"}}
|
||||
)
|
||||
for i := range kvs {
|
||||
if err := ctlV3Put(cx, kvs[i].key, kvs[i].val, ""); err != nil {
|
||||
cx.t.Fatalf("getTest #%d: ctlV3Put error (%v)", i, err)
|
||||
}
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
args []string
|
||||
@ -199,12 +205,6 @@ func getTest(cx ctlCtx) {
|
||||
{[]string{"key", "--prefix", "--order=DESCEND", "--sort-by=CREATE"}, revkvs},
|
||||
{[]string{"key", "--prefix", "--order=DESCEND", "--sort-by=KEY"}, revkvs},
|
||||
}
|
||||
|
||||
for i := range kvs {
|
||||
if err := ctlV3Put(cx, kvs[i].key, kvs[i].val, ""); err != nil {
|
||||
cx.t.Fatalf("getTest #%d: ctlV3Put error (%v)", i, err)
|
||||
}
|
||||
}
|
||||
for i, tt := range tests {
|
||||
if err := ctlV3Get(cx, tt.args, tt.wkv...); err != nil {
|
||||
if cx.dialTimeout > 0 && !isGRPCTimedout(err) {
|
||||
@ -239,6 +239,33 @@ func getFormatTest(cx ctlCtx) {
|
||||
}
|
||||
}
|
||||
|
||||
func getRevTest(cx ctlCtx) {
|
||||
var (
|
||||
kvs = []kv{{"key", "val1"}, {"key", "val2"}, {"key", "val3"}}
|
||||
)
|
||||
for i := range kvs {
|
||||
if err := ctlV3Put(cx, kvs[i].key, kvs[i].val, ""); err != nil {
|
||||
cx.t.Fatalf("getRevTest #%d: ctlV3Put error (%v)", i, err)
|
||||
}
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
args []string
|
||||
|
||||
wkv []kv
|
||||
}{
|
||||
{[]string{"key", "--rev", "2"}, kvs[:1]},
|
||||
{[]string{"key", "--rev", "3"}, kvs[1:2]},
|
||||
{[]string{"key", "--rev", "4"}, kvs[2:]},
|
||||
}
|
||||
|
||||
for i, tt := range tests {
|
||||
if err := ctlV3Get(cx, tt.args, tt.wkv...); err != nil {
|
||||
cx.t.Errorf("getTest #%d: ctlV3Get error (%v)", i, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func delTest(cx ctlCtx) {
|
||||
tests := []struct {
|
||||
puts []kv
|
||||
|
@ -66,6 +66,8 @@ GET gets the key or a range of keys [key, range_end) if `range-end` is given.
|
||||
|
||||
- sort-by -- sort target; CREATE, KEY, MODIFY, VALUE, or VERSION
|
||||
|
||||
- rev -- specify the kv revision
|
||||
|
||||
TODO: add consistency, from, prefix
|
||||
|
||||
#### Return value
|
||||
|
@ -29,6 +29,7 @@ var (
|
||||
getSortTarget string
|
||||
getPrefix bool
|
||||
getFromKey bool
|
||||
getRev int64
|
||||
)
|
||||
|
||||
// NewGetCommand returns the cobra command for "get".
|
||||
@ -45,6 +46,7 @@ func NewGetCommand() *cobra.Command {
|
||||
cmd.Flags().Int64Var(&getLimit, "limit", 0, "maximum number of results")
|
||||
cmd.Flags().BoolVar(&getPrefix, "prefix", false, "get keys with matching prefix")
|
||||
cmd.Flags().BoolVar(&getFromKey, "from-key", false, "get keys that are greater than or equal to the given key")
|
||||
cmd.Flags().Int64Var(&getRev, "rev", 0, "specify the kv revision")
|
||||
return cmd
|
||||
}
|
||||
|
||||
@ -88,6 +90,9 @@ func getGetOp(cmd *cobra.Command, args []string) (string, []clientv3.OpOption) {
|
||||
}
|
||||
|
||||
opts = append(opts, clientv3.WithLimit(getLimit))
|
||||
if getRev > 0 {
|
||||
opts = append(opts, clientv3.WithRev(getRev))
|
||||
}
|
||||
|
||||
sortByOrder := clientv3.SortNone
|
||||
sortOrder := strings.ToUpper(getSortOrder)
|
||||
|
Loading…
x
Reference in New Issue
Block a user