Tests for --web flag in issue and pr list

This commit is contained in:
AliabbasMerchant 2020-06-28 23:17:57 +05:30
parent c12243ce10
commit 77a610f071
3 changed files with 66 additions and 1 deletions

View file

@ -239,6 +239,33 @@ func TestIssueList_disabledIssues(t *testing.T) {
}
}
func TestIssueList_web(t *testing.T) {
initBlankContext("", "OWNER/REPO", "master")
http := initFakeHTTP()
http.StubRepoResponse("OWNER", "REPO")
var seenCmd *exec.Cmd
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
seenCmd = cmd
return &test.OutputStub{}
})
defer restoreCmd()
output, err := RunCommand("issue list --web -a peter -A john -l bug -l docs -L 10 -s all")
if err != nil {
t.Errorf("error running command `issue list` with `--web` flag: %v", err)
}
eq(t, output.String(), "")
eq(t, output.Stderr(), "Opening https://github.com/OWNER/REPO/issues?q=is%3Aissue+assignee%3Apeter+label%3Abug+label%3Adocs+author%3Ajohn+ in your browser.\n")
if seenCmd == nil {
t.Fatal("expected a command to run")
}
url := seenCmd.Args[len(seenCmd.Args)-1]
eq(t, url, "https://github.com/OWNER/REPO/issues?q=is%3Aissue+assignee%3Apeter+label%3Abug+label%3Adocs+author%3Ajohn+")
}
func TestIssueView_web(t *testing.T) {
initBlankContext("", "OWNER/REPO", "master")
http := initFakeHTTP()

View file

@ -231,7 +231,7 @@ func prList(cmd *cobra.Command, args []string) error {
return err
}
if author != "" && !web {
return errors.New("the --author flag is currently supported only with --web")
return errors.New("the --author flag is currently supported only with the --web flag")
}
if web {

View file

@ -480,6 +480,44 @@ func TestPRList_withInvalidLimitFlag(t *testing.T) {
}
}
func TestPRList_AuthorWithoutWebFlag(t *testing.T) {
initBlankContext("", "OWNER/REPO", "master")
http := initFakeHTTP()
http.StubRepoResponse("OWNER", "REPO")
_, err := RunCommand(`pr list --author abc`)
if err == nil && err.Error() != "the --author flag is currently supported only with the --web flag" {
t.Errorf("error running command `issue list`: %v", err)
}
}
func TestPRList_web(t *testing.T) {
initBlankContext("", "OWNER/REPO", "master")
http := initFakeHTTP()
http.StubRepoResponse("OWNER", "REPO")
var seenCmd *exec.Cmd
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
seenCmd = cmd
return &test.OutputStub{}
})
defer restoreCmd()
output, err := RunCommand("pr list --web -a peter -A john -l bug -l docs -L 10 -s merged -B trunk")
if err != nil {
t.Errorf("error running command `pr list` with `--web` flag: %v", err)
}
eq(t, output.String(), "")
eq(t, output.Stderr(), "Opening https://github.com/OWNER/REPO/pulls?q=is%3Apr+is%3Amerged+assignee%3Apeter+label%3Abug+label%3Adocs+author%3Ajohn+base%3Atrunk+ in your browser.\n")
if seenCmd == nil {
t.Fatal("expected a command to run")
}
url := seenCmd.Args[len(seenCmd.Args)-1]
eq(t, url, "https://github.com/OWNER/REPO/pulls?q=is%3Apr+is%3Amerged+assignee%3Apeter+label%3Abug+label%3Adocs+author%3Ajohn+base%3Atrunk+")
}
func TestPRView_Preview(t *testing.T) {
tests := map[string]struct {
ownerRepo string