create new test file for first browse branch

This commit is contained in:
ttran112 2021-06-05 23:31:19 -07:00
parent 1a9704dbfb
commit e425e897a6

View file

@ -0,0 +1,116 @@
package browse
import (
"bytes"
"io/ioutil"
"net/http"
"testing"
"github.com/cli/cli/internal/config"
"github.com/cli/cli/internal/ghrepo"
"github.com/cli/cli/pkg/cmdutil"
"github.com/cli/cli/pkg/iostreams"
"github.com/cli/cli/test"
"github.com/google/shlex"
"github.com/spf13/cobra"
)
func TestNewCmdBrowse(t *testing.T) {
// TODO test the use of the api using "gh browse"
// instead of opening multiple browsers for each test,
// we can test the http code sent back after calling a site
}
func runCommand(isTTY bool, cli string) (*test.CmdOut, error) {
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(isTTY)
io.SetStdinTTY(isTTY)
io.SetStderrTTY(isTTY)
factory := &cmdutil.Factory{
IOStreams: io,
HttpClient: func() (*http.Client, error) {
return &http.Client{Transport: rt}, nil
},
Config: func() (config.Config, error) {
return config.NewBlankConfig(), nil
},
BaseRepo: func() (ghrepo.Interface, error) {
return ghrepo.New("OWNER", "REPO"), nil
},
}
cmd := NewCmdBrowse(factory)
argv, err := shlex.Split(cli)
if err != nil {
return nil, err
}
cmd.SetArgs(argv)
cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(ioutil.Discard)
cmd.SetErr(ioutil.Discard)
_, err = cmd.ExecuteC()
return &test.CmdOut{
OutBuf: stdout,
ErrBuf: stderr,
}, err
}
func TestBrowseOpen(t *testing.T) {
runCommand(true, "")
}
func Test_browseList(t *testing.T) {
type args struct {
repo ghrepo.Interface
cli string
}
tests := []struct {
name string
args args
urlExpected string
exitExpected exitCode
}{}
for _, test := range tests {
}
}
func createCommand(repo ghrepo.Interface, cli string) *cobra.Command {
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(false)
io.SetStdinTTY(false) // Ask the team about TTY
io.SetStderrTTY(false)
factory := &cmdutil.Factory{
IOStreams: io,
Config: func() (config.Config, error) {
return config.NewBlankConfig(), nil
},
BaseRepo: func() (ghrepo.Interface, error) {
return ghrepo.New("OWNER", "REPO"), nil
},
}
cmd := NewCmdView(factory, nil)
argv, err := shlex.Split(cli)
if err != nil {
return nil, err
}
cmd.SetArgs(argv)
cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(ioutil.Discard)
cmd.SetErr(ioutil.Discard)
_, err = cmd.ExecuteC()
return &test.CmdOut{
OutBuf: stdout,
ErrBuf: stderr,
}, err
}