Skip to content

Commit

Permalink
cli (ticdc): fix changefeed list does not contains failed changefeed (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Jul 26, 2022
1 parent 934824b commit b4eed60
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 10 deletions.
4 changes: 2 additions & 2 deletions pkg/cmd/cli/cli_changefeed_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ func (o *listChangefeedOptions) run(cmd *cobra.Command) error {

for _, cf := range *raw {
if !o.listAll {
if cf.FeedState == model.StateFailed ||
cf.FeedState == model.StateFinished {
if cf.FeedState == model.StateFinished ||
cf.FeedState == model.StateRemoved {
continue
}
}
Expand Down
54 changes: 46 additions & 8 deletions pkg/cmd/cli/cli_changefeed_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,35 +38,73 @@ func TestChangefeedListCli(t *testing.T) {
{
UpstreamID: 1,
Namespace: "default",
ID: "c1",
ID: "error-1",
CheckpointTime: model.JSONTime{},
RunningError: nil,
FeedState: model.StateError,
},
{
UpstreamID: 1,
Namespace: "default",
ID: "c2",
ID: "normal-2",
CheckpointTime: model.JSONTime{},
RunningError: nil,
FeedState: model.StateNormal,
},
{
UpstreamID: 1,
Namespace: "default",
ID: "c3",
ID: "failed-3",
CheckpointTime: model.JSONTime{},
RunningError: nil,
FeedState: model.StateFailed,
},
}, nil)
os.Args = []string{"list", "--all=true"}
{
UpstreamID: 1,
Namespace: "default",
ID: "removed-4",
CheckpointTime: model.JSONTime{},
RunningError: nil,
FeedState: model.StateRemoved,
},
{
UpstreamID: 1,
Namespace: "default",
ID: "finished-5",
CheckpointTime: model.JSONTime{},
RunningError: nil,
FeedState: model.StateFinished,
},
{
UpstreamID: 1,
Namespace: "default",
ID: "stopped-6",
CheckpointTime: model.JSONTime{},
RunningError: nil,
FeedState: model.StateStopped,
},
}, nil).Times(2)
// when --all=false, should contains StateNormal, StateError, StateFailed, StateStopped changefeed
os.Args = []string{"list", "--all=false"}
require.Nil(t, cmd.Execute())
out, err := ioutil.ReadAll(b)
require.Nil(t, err)
// make sure the output contains error state changefeed.
require.Contains(t, string(out), "c1")
require.Contains(t, string(out), "c2")
require.Contains(t, string(out), "error-1")
require.Contains(t, string(out), "normal-2")
require.Contains(t, string(out), "stopped-6")
require.Contains(t, string(out), "failed-3")

// when --all=true, should contains all changefeed
os.Args = []string{"list", "--all=true"}
require.Nil(t, cmd.Execute())
out, err = ioutil.ReadAll(b)
require.Nil(t, err)
require.Contains(t, string(out), "error-1")
require.Contains(t, string(out), "normal-2")
require.Contains(t, string(out), "failed-3")
require.Contains(t, string(out), "removed-4")
require.Contains(t, string(out), "finished-5")
require.Contains(t, string(out), "stopped-6")

os.Args = []string{"list", "--all=false"}
cf.EXPECT().List(gomock.Any(), gomock.Any()).Return(nil, errors.New("test"))
Expand Down

0 comments on commit b4eed60

Please sign in to comment.