From 0f1924ba7ee6c53df88924edacba4af297f4b157 Mon Sep 17 00:00:00 2001 From: Chris Westra Date: Tue, 13 Sep 2022 17:06:27 -0400 Subject: [PATCH] WIP tests for --list flag --- pkg/cmd/issue/develop/develop_test.go | 182 +++++++++++++++++++++++++- 1 file changed, 181 insertions(+), 1 deletion(-) diff --git a/pkg/cmd/issue/develop/develop_test.go b/pkg/cmd/issue/develop/develop_test.go index eb079323e..2b8927e0a 100644 --- a/pkg/cmd/issue/develop/develop_test.go +++ b/pkg/cmd/issue/develop/develop_test.go @@ -32,6 +32,180 @@ func Test_developRun(t *testing.T) { wantErr string tty bool }{ + {name: "list branches for an issue", + setup: func(opts *DevelopOptions, t *testing.T) func() { + opts.IssueSelector = "42" + opts.List = true + return func() {} + }, + httpStubs: func(reg *httpmock.Registry, t *testing.T) { + reg.Register( + httpmock.GraphQL(`query BranchIssueReferenceListLinkedBranches\b`), + httpmock.GraphQLQuery(`{ + "data": { + "repository": { + "issue": { + "linkedBranches": { + "edges": [ + { + "node": { + "ref": { + "name": "foo" + } + } + }, + { + "node": { + "ref": { + "name": "bar" + } + } + } + ] + } + } + } + } + } + `, func(query string, inputs map[string]interface{}) { + assert.Equal(t, float64(42), inputs["issueNumber"]) + assert.Equal(t, "OWNER", inputs["repositoryOwner"]) + assert.Equal(t, "REPO", inputs["repositoryName"]) + })) + }, + expectedOut: "foo\nbar\n", + }, + {name: "list branches for an issue providing an issue url", + setup: func(opts *DevelopOptions, t *testing.T) func() { + opts.IssueSelector = "https://github.com/cli/test-repo/issues/42" + opts.List = true + return func() {} + }, + httpStubs: func(reg *httpmock.Registry, t *testing.T) { + reg.Register( + httpmock.GraphQL(`query BranchIssueReferenceListLinkedBranches\b`), + httpmock.GraphQLQuery(`{ + "data": { + "repository": { + "issue": { + "linkedBranches": { + "edges": [ + { + "node": { + "ref": { + "name": "foo" + } + } + }, + { + "node": { + "ref": { + "name": "bar" + } + } + } + ] + } + } + } + } + } + `, func(query string, inputs map[string]interface{}) { + assert.Equal(t, float64(42), inputs["issueNumber"]) + assert.Equal(t, "cli", inputs["repositoryOwner"]) + assert.Equal(t, "test-repo", inputs["repositoryName"]) + })) + }, + expectedOut: "foo\nbar\n", + }, + {name: "list branches for an issue providing an issue repo", + setup: func(opts *DevelopOptions, t *testing.T) func() { + opts.IssueSelector = "42" + opts.IssueRepoSelector = "cli/test-repo" + opts.List = true + return func() {} + }, + httpStubs: func(reg *httpmock.Registry, t *testing.T) { + reg.Register( + httpmock.GraphQL(`query BranchIssueReferenceListLinkedBranches\b`), + httpmock.GraphQLQuery(`{ + "data": { + "repository": { + "issue": { + "linkedBranches": { + "edges": [ + { + "node": { + "ref": { + "name": "foo" + } + } + }, + { + "node": { + "ref": { + "name": "bar" + } + } + } + ] + } + } + } + } + } + `, func(query string, inputs map[string]interface{}) { + assert.Equal(t, float64(42), inputs["issueNumber"]) + assert.Equal(t, "cli", inputs["repositoryOwner"]) + assert.Equal(t, "test-repo", inputs["repositoryName"]) + })) + }, + expectedOut: "foo\nbar\n", + }, + {name: "list branches for an issue providing an issue url and specifying its repo returns an error", + setup: func(opts *DevelopOptions, t *testing.T) func() { + opts.IssueSelector = "https://github.com/cli/test-repo/issues/42" + opts.IssueRepoSelector = "cli/test-repo" + opts.List = true + return func() {} + }, + httpStubs: func(reg *httpmock.Registry, t *testing.T) { + reg.Register( + httpmock.GraphQL(`query BranchIssueReferenceListLinkedBranches\b`), + httpmock.GraphQLQuery(`{ + "data": { + "repository": { + "issue": { + "linkedBranches": { + "edges": [ + { + "node": { + "ref": { + "name": "foo" + } + } + }, + { + "node": { + "ref": { + "name": "bar" + } + } + } + ] + } + } + } + } + } + `, func(query string, inputs map[string]interface{}) { + assert.Equal(t, float64(42), inputs["issueNumber"]) + assert.Equal(t, "cli", inputs["repositoryOwner"]) + assert.Equal(t, "test-repo", inputs["repositoryName"]) + })) + }, + expectedErrOut: "error: --issue-repo cannot be used when providing an issue URL\n", + }, {name: "develop new branch", setup: func(opts *DevelopOptions, t *testing.T) func() { opts.Name = "my-branch" @@ -219,7 +393,13 @@ func Test_developRun(t *testing.T) { } defer cleanSetup() - err := developRun(&opts) + var err error + if opts.List { + err = developRunList(&opts) + } else { + + err = developRun(&opts) + } output := &test.CmdOut{ OutBuf: stdout, ErrBuf: stderr,