From 83d3e1a7c05f06b0f8af10a5b9ee2948bd47f454 Mon Sep 17 00:00:00 2001 From: Stavros Panakakis <53979866+Stavrospanakakis@users.noreply.github.com> Date: Mon, 23 Sep 2024 14:54:56 +0300 Subject: [PATCH] command: merge two container rename tests into one using table driven tests Co-authored-by: Laura Brehm --- cli/command/container/rename_test.go | 49 ++++++++++++++-------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/cli/command/container/rename_test.go b/cli/command/container/rename_test.go index 526d39fd2199..4b0350362782 100644 --- a/cli/command/container/rename_test.go +++ b/cli/command/container/rename_test.go @@ -28,34 +28,33 @@ func TestRunRename(t *testing.T) { assert.Equal(t, cli.OutBuffer().String(), expected) } -func TestRunRenameOldNameError(t *testing.T) { - cli := test.NewFakeCli(&fakeClient{}) - - cmd := NewRenameCommand(cli) - cmd.SetOut(io.Discard) - cmd.SetArgs([]string{"", "newName"}) - - err := cmd.Execute() - - assert.Assert(t, err != nil) - - expected := "Error: Neither old nor new names may be empty" - assert.ErrorContains(t, err, expected) -} - -func TestRunRenameNewNameError(t *testing.T) { - cli := test.NewFakeCli(&fakeClient{}) - - cmd := NewRenameCommand(cli) - cmd.SetOut(io.Discard) - cmd.SetArgs([]string{"oldName", ""}) +func TestRunRenameInputs(t *testing.T) { + testCases := []struct { + args []string + expectedErr string + } { + { + args: []string{"", "newName"}, + expectedErr: "Error: Neither old nor new names may be empty", + }, + { + args: []string{"oldName", ""} + expectedErr: "Error: Neither old nor new names may be empty", + }, + } + + for _, tc := range testCases { + cli := test.NewFakeCli(&fakeClient{}) - err := cmd.Execute() + cmd := NewRenameCommand(cli) + cmd.SetOut(io.Discard) + cmd.SetArgs(tc.args) - assert.Assert(t, err != nil) + err := cmd.Execute() - expected := "Error: Neither old nor new names may be empty" - assert.ErrorContains(t, err, expected) + assert.Assert(t, err != nil) + assert.ErrorContains(t, err, tc.expectedErr) + } } func TestRunRenameClientError(t *testing.T) {