Skip to content

Commit

Permalink
command: merge two container rename tests into one using table driven…
Browse files Browse the repository at this point in the history
… tests

Co-authored-by: Laura Brehm <[email protected]>
  • Loading branch information
Stavrospanakakis and laurazard authored Sep 23, 2024
1 parent 39ae576 commit 83d3e1a
Showing 1 changed file with 24 additions and 25 deletions.
49 changes: 24 additions & 25 deletions cli/command/container/rename_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 83d3e1a

Please sign in to comment.