fix(list): reset Truncated state and use Cobra stderr stream

Reset Truncated on each Run(), use cmd.ErrOrStderr(), and reorder tests
to cover early-return stale state.

Signed-off-by: John Weathers <weathers.johnb@gmail.com>
pull/31887/head
John Weathers 4 weeks ago
parent 66aa579adc
commit 1f77d24a86

@ -153,6 +153,8 @@ func (l *List) Run() ([]ri.Releaser, error) {
return nil, err
}
l.Truncated = false
var filter *regexp.Regexp
if l.Filter != "" {
var err error

@ -209,19 +209,20 @@ func TestList_Truncation(t *testing.T) {
is.Len(list, 1)
is.True(lister.Truncated, "Expected Truncated to be true when offset + limit < total")
// Early return path should reset Truncated even after a truncated run
lister.Limit = 1
lister.Offset = 2
lister.Offset = 3
list, err = lister.Run()
is.NoError(err)
is.Len(list, 1)
is.False(lister.Truncated, "Expected Truncated to be false when offset + limit == total")
is.Len(list, 0)
is.False(lister.Truncated, "Expected Truncated to be false when offset >= total")
lister.Limit = 1
lister.Offset = 3
lister.Offset = 2
list, err = lister.Run()
is.NoError(err)
is.Len(list, 0)
is.False(lister.Truncated, "Expected Truncated to be false when offset >= total")
is.Len(list, 1)
is.False(lister.Truncated, "Expected Truncated to be false when offset + limit == total")
}
func TestList_StateMask(t *testing.T) {

@ -119,7 +119,7 @@ func newListCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
outputFlag := cmd.Flag("output")
if outputFlag.Value.String() == "table" && client.Truncated && !cmd.Flags().Changed("max") {
fmt.Fprintln(os.Stderr, "WARNING: results were truncated due to the default --max limit. Use --max to show more releases.")
fmt.Fprintln(cmd.ErrOrStderr(), "WARNING: results were truncated due to the default --max limit. Use --max to show more releases.")
}
return nil

Loading…
Cancel
Save