diff --git a/command/issue_test.go b/command/issue_test.go index 418de25d3..cc23b7bda 100644 --- a/command/issue_test.go +++ b/command/issue_test.go @@ -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() diff --git a/command/pr.go b/command/pr.go index 67e9086d7..c9b29d187 100644 --- a/command/pr.go +++ b/command/pr.go @@ -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 { diff --git a/command/pr_test.go b/command/pr_test.go index e7e1e2dc3..91a1150c6 100644 --- a/command/pr_test.go +++ b/command/pr_test.go @@ -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