Skip to content

Commit

Permalink
Made new arg names more consistent with pre-existing; add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcferretti committed Jun 27, 2024
1 parent 9aafed4 commit 0205d8d
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 30 deletions.
52 changes: 26 additions & 26 deletions etcdctl/ctlv3/command/get_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ import (
)

var (
getConsistency string
getLimit int64
getSortOrder string
getSortTarget string
getPrefix bool
getFromKey bool
getRev int64
getKeysOnly bool
getCountOnly bool
printValueOnly bool
getMinCreateRevision int64
getMaxCreateRevision int64
getMinModRevision int64
getMaxModRevision int64
getConsistency string
getLimit int64
getSortOrder string
getSortTarget string
getPrefix bool
getFromKey bool
getRev int64
getKeysOnly bool
getCountOnly bool
printValueOnly bool
getMinCreateRev int64
getMaxCreateRev int64
getMinModRev int64
getMaxModRev int64
)

// NewGetCommand returns the cobra command for "get".
Expand All @@ -59,10 +59,10 @@ func NewGetCommand() *cobra.Command {
cmd.Flags().BoolVar(&getKeysOnly, "keys-only", false, "Get only the keys")
cmd.Flags().BoolVar(&getCountOnly, "count-only", false, "Get only the count")
cmd.Flags().BoolVar(&printValueOnly, "print-value-only", false, `Only write values when using the "simple" output format`)
cmd.Flags().Int64Var(&getMinCreateRevision, "min-create-revision", 0, "Minimum create revision")
cmd.Flags().Int64Var(&getMaxCreateRevision, "max-create-revision", 0, "Maximum create revision")
cmd.Flags().Int64Var(&getMinModRevision, "min-mod-revision", 0, "Minimum modification revision")
cmd.Flags().Int64Var(&getMaxModRevision, "max-mod-revision", 0, "Maximum modification revision")
cmd.Flags().Int64Var(&getMinCreateRev, "min-create-rev", 0, "Minimum create revision")
cmd.Flags().Int64Var(&getMaxCreateRev, "max-create-rev", 0, "Maximum create revision")
cmd.Flags().Int64Var(&getMinModRev, "min-mod-rev", 0, "Minimum modification revision")
cmd.Flags().Int64Var(&getMaxModRev, "max-mod-rev", 0, "Maximum modification revision")

cmd.RegisterFlagCompletionFunc("consistency", func(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
return []string{"l", "s"}, cobra.ShellCompDirectiveDefault
Expand Down Expand Up @@ -192,20 +192,20 @@ func getGetOp(args []string) (string, []clientv3.OpOption) {
opts = append(opts, clientv3.WithCountOnly())
}

if getMinCreateRevision > 0 {
opts = append(opts, clientv3.WithMinCreateRev(getMinCreateRevision))
if getMinCreateRev > 0 {
opts = append(opts, clientv3.WithMinCreateRev(getMinCreateRev))
}

if getMaxCreateRevision > 0 {
opts = append(opts, clientv3.WithMaxCreateRev(getMaxCreateRevision))
if getMaxCreateRev > 0 {
opts = append(opts, clientv3.WithMaxCreateRev(getMaxCreateRev))
}

if getMinModRevision > 0 {
opts = append(opts, clientv3.WithMinModRev(getMinModRevision))
if getMinModRev > 0 {
opts = append(opts, clientv3.WithMinModRev(getMinModRev))
}

if getMaxModRevision > 0 {
opts = append(opts, clientv3.WithMaxModRev(getMaxModRevision))
if getMaxModRev > 0 {
opts = append(opts, clientv3.WithMaxModRev(getMaxModRev))
}

return key, opts
Expand Down
120 changes: 116 additions & 4 deletions tests/e2e/ctl_v3_kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@ func TestCtlV3PutIgnoreLease(t *testing.T) { testCtl(t, putTestIgnoreLease) }

func TestCtlV3GetTimeout(t *testing.T) { testCtl(t, getTest, withDefaultDialTimeout()) }

func TestCtlV3GetFormat(t *testing.T) { testCtl(t, getFormatTest) }
func TestCtlV3GetRev(t *testing.T) { testCtl(t, getRevTest) }
func TestCtlV3GetKeysOnly(t *testing.T) { testCtl(t, getKeysOnlyTest) }
func TestCtlV3GetCountOnly(t *testing.T) { testCtl(t, getCountOnlyTest) }
func TestCtlV3GetFormat(t *testing.T) { testCtl(t, getFormatTest) }
func TestCtlV3GetRev(t *testing.T) { testCtl(t, getRevTest) }
func TestCtlV3GetMaxCreateRev(t *testing.T) { testCtl(t, getMaxCreateRevTest) }
func TestCtlV3GetMinCreateRev(t *testing.T) { testCtl(t, getMinCreateRevTest) }
func TestCtlV3GetMaxModRev(t *testing.T) { testCtl(t, getMaxModRevTest) }
func TestCtlV3GetMinModRev(t *testing.T) { testCtl(t, getMinModRevTest) }
func TestCtlV3GetKeysOnly(t *testing.T) { testCtl(t, getKeysOnlyTest) }
func TestCtlV3GetCountOnly(t *testing.T) { testCtl(t, getCountOnlyTest) }

func TestCtlV3DelTimeout(t *testing.T) { testCtl(t, delTest, withDefaultDialTimeout()) }

Expand Down Expand Up @@ -216,6 +220,114 @@ func getRevTest(cx ctlCtx) {
}
}

func getMaxCreateRevTest(cx ctlCtx) {
var (
kvs = []kv{{"key1", "val1"}, {"key2", "val2"}, {"key3", "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", "--prefix", "--max-create-rev", "3"}, kvs[:2]},
}

for i, tt := range tests {
if err := ctlV3Get(cx, tt.args, tt.wkv...); err != nil {
cx.t.Errorf("getMaxCreateRevTest #%d: ctlV3Get error (%v)", i, err)
}
}
}

func getMinCreateRevTest(cx ctlCtx) {
var (
kvs = []kv{{"key1", "val1"}, {"key2", "val2"}, {"key3", "val3"}}
)
for i := range kvs {
if err := ctlV3Put(cx, kvs[i].key, kvs[i].val, ""); err != nil {
cx.t.Fatalf("getMinCreateRevTest #%d: ctlV3Put error (%v)", i, err)
}
}

tests := []struct {
args []string

wkv []kv
}{
{[]string{"key", "--prefix", "--min-create-rev", "3"}, kvs[1:]},
}

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 getMaxModRevTest(cx ctlCtx) {
var (
kvs = []kv{ // store revision | key create revision | key modify revision
{"key1", "val1"}, // 2 2 2
{"key2", "val2"}, // 3 3 3
{"key2", "val3"}, // 4 2 4
}
)
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", "--prefix", "--max-mod-rev", "3"}, kvs[:1]},
}

for i, tt := range tests {
if err := ctlV3Get(cx, tt.args, tt.wkv...); err != nil {
cx.t.Errorf("getMaxModRevTest #%d: ctlV3Get error (%v)", i, err)
}
}
}

func getMinModRevTest(cx ctlCtx) {
var (
kvs = []kv{ // store revision | key create revision | key modify revision
{"key1", "val1"}, // 2 2 2
{"key2", "val2"}, // 3 3 3
{"key1", "val3"}, // 4 2 4
}
)
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", "--prefix", "--min-mod-rev", "4"}, kvs[2:]},
}

for i, tt := range tests {
if err := ctlV3Get(cx, tt.args, tt.wkv...); err != nil {
cx.t.Errorf("getMinModRevTest #%d: ctlV3Get error (%v)", i, err)
}
}
}

func getKeysOnlyTest(cx ctlCtx) {
if err := ctlV3Put(cx, "key", "val", ""); err != nil {
cx.t.Fatal(err)
Expand Down

0 comments on commit 0205d8d

Please sign in to comment.