ammended action

This commit is contained in:
Queila Delgado 2021-12-12 15:40:17 -05:00
parent 968eee6dc8
commit bdcbbd8e8f
1 changed files with 78 additions and 0 deletions

View File

@ -0,0 +1,78 @@
package list
import (
"bytes"
"io/ioutil"
"testing"
"github.com/cli/cli/pkg/cmdutil"
"github.com/cli/cli/pkg/iostreams"
"github.com/google/shlex"
"github.com/stretchr/testify/assert"
)
func TestNewCmdList(t *testing.T) {
tests := []struct {
name string
cli string
tty bool
wants ListOptions
wantsErr bool
}{
{
name: "blank",
wants: ListOptions{
Limit: defaultLimit,
},
},
{
name: "limit",
cli: "--limit 100",
wants: ListOptions{
Limit: 100,
},
},
{
name: "bad limit",
cli: "--limit hi",
wantsErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
io, _, _, _ := iostreams.Test()
io.SetStdinTTY(tt.tty)
io.SetStdoutTTY(tt.tty)
f := &cmdutil.Factory{
IOStreams: io,
}
argv, err := shlex.Split(tt.cli)
assert.NoError(t, err)
var gotOpts *ListOptions
cmd := NewCmdList(f, func(opts *ListOptions) error {
gotOpts = opts
return nil
})
cmd.SetArgs(argv)
cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(ioutil.Discard)
cmd.SetErr(ioutil.Discard)
_, err = cmd.ExecuteC()
if tt.wantsErr {
assert.Error(t, err)
return
}
assert.Equal(t, tt.wants.Limit, gotOpts.Limit)
})
}
}
func TestForDemo(t *testing.T) {
assert.Equal(t, 1, 1)
}