From 3f9d477c75bc9fd9b477bfce8e6dc8ae7aed395d Mon Sep 17 00:00:00 2001 From: Muhammet Yazici <44066377+mtyazici@users.noreply.github.com> Date: Wed, 13 Sep 2023 20:51:33 +0300 Subject: [PATCH] [CLC-334] Fix list add command with index (#386) --- base/commands/list/list_add.go | 7 +++++-- base/commands/list/list_it_test.go | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/base/commands/list/list_add.go b/base/commands/list/list_add.go index 1b3dfa5c..9481ef9c 100644 --- a/base/commands/list/list_add.go +++ b/base/commands/list/list_add.go @@ -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 @@ -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, }, diff --git a/base/commands/list/list_it_test.go b/base/commands/list/list_it_test.go index 5ceb4107..520b8b63 100644 --- a/base/commands/list/list_it_test.go +++ b/base/commands/list/list_it_test.go @@ -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}, @@ -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