Skip to content

Commit

Permalink
Followup to review comment: consolidate test functions into one.
Browse files Browse the repository at this point in the history
Signed-off-by: Cristian Ferretti <[email protected]>
  • Loading branch information
jcferretti committed Jul 2, 2024
1 parent 44c4307 commit e1872c7
Showing 1 changed file with 14 additions and 92 deletions.
106 changes: 14 additions & 92 deletions tests/e2e/ctl_v3_kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,11 @@ 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 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 TestCtlV3GetFormat(t *testing.T) { testCtl(t, getFormatTest) }
func TestCtlV3GetRev(t *testing.T) { testCtl(t, getRevTest) }
func TestCtlV3GetMinMaxCreateModRev(t *testing.T) { testCtl(t, getMinMaxCreateModRevTest) }
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 @@ -220,91 +217,13 @@ func getRevTest(cx ctlCtx) {
}
}

func getMaxCreateRevTest(cx ctlCtx) {
func getMinMaxCreateModRevTest(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
kvs = []kv{ // revision: store | key create | key modify
{"key1", "val1"}, // 2 2 2
{"key2", "val2"}, // 3 3 3
{"key1", "val3"}, // 4 2 4
{"key4", "val4"}, // 5 5 5
}
)
for i := range kvs {
Expand All @@ -318,6 +237,9 @@ func getMinModRevTest(cx ctlCtx) {

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

Expand Down

0 comments on commit e1872c7

Please sign in to comment.