Revert test changes
This commit is contained in:
parent
b66c34e0ec
commit
d025d2d4f3
3 changed files with 156 additions and 34 deletions
|
|
@ -45,11 +45,12 @@ func TestIssueStatus_blankSlate(t *testing.T) {
|
|||
http := initFakeHTTP()
|
||||
|
||||
http.StubResponse(200, bytes.NewBufferString(`
|
||||
{ "data": {
|
||||
"assigned": { "issues": { "nodes": [] } },
|
||||
"mentioned": { "issues": { "nodes": [] } },
|
||||
"authored": { "issues": { "nodes": [] } }
|
||||
} }
|
||||
{ "data": { "repository": {
|
||||
"hasIssuesEnabled": true,
|
||||
"assigned": { "nodes": [] },
|
||||
"mentioned": { "nodes": [] },
|
||||
"authored": { "nodes": [] }
|
||||
} } }
|
||||
`))
|
||||
|
||||
output, err := RunCommand(issueStatusCmd, "issue status")
|
||||
|
|
@ -72,6 +73,22 @@ Issues opened by you
|
|||
}
|
||||
}
|
||||
|
||||
func TestIssueStatus_disabledIssues(t *testing.T) {
|
||||
initBlankContext("OWNER/REPO", "master")
|
||||
http := initFakeHTTP()
|
||||
|
||||
http.StubResponse(200, bytes.NewBufferString(`
|
||||
{ "data": { "repository": {
|
||||
"hasIssuesEnabled": false
|
||||
} } }
|
||||
`))
|
||||
|
||||
_, err := RunCommand(issueStatusCmd, "issue status")
|
||||
if err == nil || err.Error() != "the 'OWNER/REPO' repository has disabled issues" {
|
||||
t.Errorf("error running command `issue status`: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIssueList(t *testing.T) {
|
||||
initBlankContext("OWNER/REPO", "master")
|
||||
http := initFakeHTTP()
|
||||
|
|
@ -100,16 +117,22 @@ func TestIssueList(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestIssueList_withFlags(t *testing.T) {
|
||||
initBlankContext("OWNER/REPO", "master")
|
||||
http := initFakeHTTP()
|
||||
|
||||
http.StubResponse(200, bytes.NewBufferString(`{"data": {}}`)) // Since we are testing that the flags are passed, we don't care about the response
|
||||
http.StubResponse(200, bytes.NewBufferString(`
|
||||
{ "data": { "repository": {
|
||||
"hasIssuesEnabled": true,
|
||||
"issues": { "nodes": [] }
|
||||
} } }
|
||||
`))
|
||||
|
||||
output, err := RunCommand(issueListCmd, "issue list -a probablyCher -l web,bug -s open")
|
||||
if err != nil {
|
||||
t.Errorf("error running command `issue list`: %v", err)
|
||||
}
|
||||
|
||||
eq(t, output.String(), "\nIssues for OWNER/REPO\n\n")
|
||||
eq(t, output.String(), "")
|
||||
eq(t, output.Stderr(), "No issues match your search\n")
|
||||
|
||||
bodyBytes, _ := ioutil.ReadAll(http.Requests[0].Body)
|
||||
|
|
@ -127,6 +150,50 @@ func TestIssueList_withFlags(t *testing.T) {
|
|||
eq(t, reqBody.Variables.States, []string{"OPEN"})
|
||||
}
|
||||
|
||||
func TestIssueList_nullAssigneeLabels(t *testing.T) {
|
||||
initBlankContext("OWNER/REPO", "master")
|
||||
http := initFakeHTTP()
|
||||
|
||||
http.StubResponse(200, bytes.NewBufferString(`
|
||||
{ "data": { "repository": {
|
||||
"hasIssuesEnabled": true,
|
||||
"issues": { "nodes": [] }
|
||||
} } }
|
||||
`))
|
||||
|
||||
_, err := RunCommand(issueListCmd, "issue list")
|
||||
if err != nil {
|
||||
t.Errorf("error running command `issue list`: %v", err)
|
||||
}
|
||||
|
||||
bodyBytes, _ := ioutil.ReadAll(http.Requests[0].Body)
|
||||
reqBody := struct {
|
||||
Variables map[string]interface{}
|
||||
}{}
|
||||
json.Unmarshal(bodyBytes, &reqBody)
|
||||
|
||||
_, assigneeDeclared := reqBody.Variables["assignee"]
|
||||
_, labelsDeclared := reqBody.Variables["labels"]
|
||||
eq(t, assigneeDeclared, false)
|
||||
eq(t, labelsDeclared, false)
|
||||
}
|
||||
|
||||
func TestIssueList_disabledIssues(t *testing.T) {
|
||||
initBlankContext("OWNER/REPO", "master")
|
||||
http := initFakeHTTP()
|
||||
|
||||
http.StubResponse(200, bytes.NewBufferString(`
|
||||
{ "data": { "repository": {
|
||||
"hasIssuesEnabled": false
|
||||
} } }
|
||||
`))
|
||||
|
||||
_, err := RunCommand(issueListCmd, "issue list")
|
||||
if err == nil || err.Error() != "the 'OWNER/REPO' repository has disabled issues" {
|
||||
t.Errorf("error running command `issue list`: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIssueView(t *testing.T) {
|
||||
initBlankContext("OWNER/REPO", "master")
|
||||
http := initFakeHTTP()
|
||||
|
|
@ -225,7 +292,8 @@ func TestIssueCreate(t *testing.T) {
|
|||
|
||||
http.StubResponse(200, bytes.NewBufferString(`
|
||||
{ "data": { "repository": {
|
||||
"id": "REPOID"
|
||||
"id": "REPOID",
|
||||
"hasIssuesEnabled": true
|
||||
} } }
|
||||
`))
|
||||
http.StubResponse(200, bytes.NewBufferString(`
|
||||
|
|
@ -255,11 +323,24 @@ func TestIssueCreate(t *testing.T) {
|
|||
eq(t, reqBody.Variables.Input.Title, "hello")
|
||||
eq(t, reqBody.Variables.Input.Body, "cash rules everything around me")
|
||||
|
||||
eq(t, output.String(), `
|
||||
Creating issue in OWNER/REPO
|
||||
eq(t, output.String(), "https://github.com/OWNER/REPO/issues/12\n")
|
||||
}
|
||||
|
||||
https://github.com/OWNER/REPO/issues/12
|
||||
`)
|
||||
func TestIssueCreate_disabledIssues(t *testing.T) {
|
||||
initBlankContext("OWNER/REPO", "master")
|
||||
http := initFakeHTTP()
|
||||
|
||||
http.StubResponse(200, bytes.NewBufferString(`
|
||||
{ "data": { "repository": {
|
||||
"id": "REPOID",
|
||||
"hasIssuesEnabled": false
|
||||
} } }
|
||||
`))
|
||||
|
||||
_, err := RunCommand(issueCreateCmd, `issue create -t heres -b johnny`)
|
||||
if err == nil || err.Error() != "the 'OWNER/REPO' repository has disabled issues" {
|
||||
t.Errorf("error running command `issue create`: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIssueCreate_web(t *testing.T) {
|
||||
|
|
@ -283,9 +364,5 @@ func TestIssueCreate_web(t *testing.T) {
|
|||
}
|
||||
url := seenCmd.Args[len(seenCmd.Args)-1]
|
||||
eq(t, url, "https://github.com/OWNER/REPO/issues/new")
|
||||
eq(t, output.String(), `
|
||||
Creating issue in OWNER/REPO
|
||||
|
||||
Opening https://github.com/OWNER/REPO/issues/new in your browser.
|
||||
`)
|
||||
eq(t, output.String(), "Opening https://github.com/OWNER/REPO/issues/new in your browser.\n")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,11 +91,7 @@ func TestPRCreate(t *testing.T) {
|
|||
eq(t, reqBody.Variables.Input.BaseRefName, "master")
|
||||
eq(t, reqBody.Variables.Input.HeadRefName, "feature")
|
||||
|
||||
eq(t, output.String(), `
|
||||
Creating pull request for feature in OWNER/REPO
|
||||
|
||||
https://github.com/OWNER/REPO/pull/12
|
||||
`)
|
||||
eq(t, output.String(), "https://github.com/OWNER/REPO/pull/12\n")
|
||||
}
|
||||
|
||||
func TestPRCreate_web(t *testing.T) {
|
||||
|
|
@ -119,7 +115,7 @@ func TestPRCreate_web(t *testing.T) {
|
|||
output, err := RunCommand(prCreateCmd, `pr create --web`)
|
||||
eq(t, err, nil)
|
||||
|
||||
eq(t, output.String(), "\nCreating pull request for feature in OWNER/REPO\n\n")
|
||||
eq(t, output.String(), "")
|
||||
eq(t, output.Stderr(), "Opening https://github.com/OWNER/REPO/pull/feature in your browser.\n")
|
||||
|
||||
eq(t, len(ranCommands), 3)
|
||||
|
|
@ -158,10 +154,6 @@ func TestPRCreate_ReportsUncommittedChanges(t *testing.T) {
|
|||
output, err := RunCommand(prCreateCmd, `pr create -t "my title" -b "my body"`)
|
||||
eq(t, err, nil)
|
||||
|
||||
eq(t, output.String(), `
|
||||
Creating pull request for feature in OWNER/REPO
|
||||
|
||||
https://github.com/OWNER/REPO/pull/12
|
||||
`)
|
||||
eq(t, output.String(), "https://github.com/OWNER/REPO/pull/12\n")
|
||||
eq(t, output.Stderr(), "Warning: 1 uncommitted change\n")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,12 +50,14 @@ func RunCommand(cmd *cobra.Command, args string) (*cmdOut, error) {
|
|||
cmd.SetErr(&errBuf)
|
||||
|
||||
// Reset flag values so they don't leak between tests
|
||||
// FIXME: change how we initialize Cobra commands to render this hack unnecessary
|
||||
cmd.Flags().VisitAll(func(f *pflag.Flag) {
|
||||
switch v := f.Value.(type) {
|
||||
case pflag.SliceValue:
|
||||
v.Replace([]string{})
|
||||
default:
|
||||
if v.Type() == "bool" {
|
||||
switch v.Type() {
|
||||
case "bool", "string":
|
||||
v.Set(f.DefValue)
|
||||
}
|
||||
}
|
||||
|
|
@ -95,6 +97,60 @@ func TestPRStatus(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestPRStatus_reviewsAndChecks(t *testing.T) {
|
||||
initBlankContext("OWNER/REPO", "blueberries")
|
||||
http := initFakeHTTP()
|
||||
|
||||
jsonFile, _ := os.Open("../test/fixtures/prStatusChecks.json")
|
||||
defer jsonFile.Close()
|
||||
http.StubResponse(200, jsonFile)
|
||||
|
||||
output, err := RunCommand(prStatusCmd, "pr status")
|
||||
if err != nil {
|
||||
t.Errorf("error running command `pr status`: %v", err)
|
||||
}
|
||||
|
||||
expected := []string{
|
||||
"- Checks passing - changes requested",
|
||||
"- Checks pending - approved",
|
||||
"- 1/3 checks failing - review required",
|
||||
}
|
||||
|
||||
for _, line := range expected {
|
||||
if !strings.Contains(output.String(), line) {
|
||||
t.Errorf("output did not contain %q: %q", line, output.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPRStatus_blankSlate(t *testing.T) {
|
||||
initBlankContext("OWNER/REPO", "blueberries")
|
||||
http := initFakeHTTP()
|
||||
|
||||
http.StubResponse(200, bytes.NewBufferString(`
|
||||
{ "data": {} }
|
||||
`))
|
||||
|
||||
output, err := RunCommand(prStatusCmd, "pr status")
|
||||
if err != nil {
|
||||
t.Errorf("error running command `pr status`: %v", err)
|
||||
}
|
||||
|
||||
expected := `Current branch
|
||||
There is no pull request associated with [blueberries]
|
||||
|
||||
Created by you
|
||||
You have no open pull requests
|
||||
|
||||
Requesting a code review from you
|
||||
You have no pull requests to review
|
||||
|
||||
`
|
||||
if output.String() != expected {
|
||||
t.Errorf("expected %q, got %q", expected, output.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestPRList(t *testing.T) {
|
||||
initBlankContext("OWNER/REPO", "master")
|
||||
http := initFakeHTTP()
|
||||
|
|
@ -108,10 +164,7 @@ func TestPRList(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
eq(t, output.String(), `
|
||||
Pull requests for OWNER/REPO
|
||||
|
||||
32 New feature feature
|
||||
eq(t, output.String(), `32 New feature feature
|
||||
29 Fixed bad bug hubot:bug-fix
|
||||
28 Improve documentation docs
|
||||
`)
|
||||
|
|
@ -129,7 +182,7 @@ func TestPRList_filtering(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
eq(t, output.String(), "\nPull requests for OWNER/REPO\n\n")
|
||||
eq(t, output.String(), "")
|
||||
eq(t, output.Stderr(), "No pull requests match your search\n")
|
||||
|
||||
bodyBytes, _ := ioutil.ReadAll(http.Requests[0].Body)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue