Skip to content

Commit

Permalink
[CLC-334] Fix list add command with index (hazelcast#386)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtyazici authored Sep 13, 2023
1 parent 7ad4c6c commit 3f9d477
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
7 changes: 5 additions & 2 deletions base/commands/list/list_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ func (AddCommand) Exec(ctx context.Context, ec plug.ExecContext) error {
if err != nil {
return nil, err
}
return codec.DecodeListAddResponse(resp), err
if index >= 0 {
return true, nil
}
return codec.DecodeListAddResponse(resp), nil
})
if err != nil {
return err
Expand All @@ -75,7 +78,7 @@ func (AddCommand) Exec(ctx context.Context, ec plug.ExecContext) error {
ec.PrintlnUnnecessary(msg)
row := output.Row{
output.Column{
Name: "Value",
Name: "Value Changed",
Type: serialization.TypeBool,
Value: val,
},
Expand Down
18 changes: 18 additions & 0 deletions base/commands/list/list_it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func TestList(t *testing.T) {
f func(t *testing.T)
}{
{name: "Add_NonInteractive", f: add_NonInteractiveTest},
{name: "Add_WithIndex_NonInteractive", f: add_WithIndex_NonInteractiveTest},
{name: "Clear_NonInteractive", f: clear_NonInteractiveTest},
{name: "Contains_NonInteractive", f: contains_NonInteractiveTest},
{name: "RemoveIndex_Noninteractive", f: removeIndex_NonInteractiveTest},
Expand Down Expand Up @@ -50,6 +51,23 @@ func add_NonInteractiveTest(t *testing.T) {
})
}

func add_WithIndex_NonInteractiveTest(t *testing.T) {
it.ListTester(t, func(tcx it.TestContext, l *hz.List) {
t := tcx.T
ctx := context.Background()
tcx.WithReset(func() {
tcx.CLCExecute(ctx, "list", "-n", l.Name(), "--index", "0", "add", "foo")
tcx.CLCExecute(ctx, "list", "-n", l.Name(), "--index", "1", "add", "bar")
require.Equal(t, "foo", check.MustValue(l.Get(context.Background(), 0)))
require.Equal(t, "bar", check.MustValue(l.Get(context.Background(), 1)))
tcx.CLCExecute(ctx, "list", "-n", l.Name(), "--index", "1", "add", "second")
require.Equal(t, "foo", check.MustValue(l.Get(context.Background(), 0)))
require.Equal(t, "second", check.MustValue(l.Get(context.Background(), 1)))
require.Equal(t, "bar", check.MustValue(l.Get(context.Background(), 2)))
})
})
}

func clear_NonInteractiveTest(t *testing.T) {
it.ListTester(t, func(tcx it.TestContext, l *hz.List) {
t := tcx.T
Expand Down

0 comments on commit 3f9d477

Please sign in to comment.