From a998a650cdd88a75122db4832996507853283196 Mon Sep 17 00:00:00 2001 From: vilmibm Date: Wed, 12 Feb 2020 08:15:10 -0600 Subject: [PATCH] still WIP, need to pause and refactor --- command/issue_test.go | 90 +++++++++++- command/pr_test.go | 309 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 380 insertions(+), 19 deletions(-) diff --git a/command/issue_test.go b/command/issue_test.go index 334554789..afc0d0c2e 100644 --- a/command/issue_test.go +++ b/command/issue_test.go @@ -258,9 +258,29 @@ No issues match your search } func TestIssueList_nullAssigneeLabels(t *testing.T) { - initBlankContext("OWNER/REPO", "master") + ctx := context.NewBlank() + ctx.SetBranch("master") + ctx.SetRemotes(map[string]string{ + "origin": "OWNER/REPO", + }) + initContext = func() context.Context { + return ctx + } http := initFakeHTTP() + http.StubResponse(200, bytes.NewBufferString(` + { "data": { "repo_000": { + "id": "REPOID", + "name": "REPO", + "owner": {"login": "OWNER"}, + "defaultBranchRef": { + "name": "master", + "target": {"oid": "deadbeef"} + }, + "viewerPermission": "WRITE" + } } } + `)) + http.StubResponse(200, bytes.NewBufferString(` { "data": { "repository": { "hasIssuesEnabled": true, @@ -456,9 +476,29 @@ func TestIssueView_urlArg(t *testing.T) { } func TestIssueCreate(t *testing.T) { - initBlankContext("OWNER/REPO", "master") + ctx := context.NewBlank() + ctx.SetBranch("master") + ctx.SetRemotes(map[string]string{ + "origin": "OWNER/REPO", + }) + initContext = func() context.Context { + return ctx + } http := initFakeHTTP() + http.StubResponse(200, bytes.NewBufferString(` + { "data": { "repo_000": { + "id": "REPOID", + "name": "REPO", + "owner": {"login": "OWNER"}, + "defaultBranchRef": { + "name": "master", + "target": {"oid": "deadbeef"} + }, + "viewerPermission": "WRITE" + } } } + `)) + http.StubResponse(200, bytes.NewBufferString(` { "data": { "repository": { "id": "REPOID", @@ -496,9 +536,29 @@ func TestIssueCreate(t *testing.T) { } func TestIssueCreate_disabledIssues(t *testing.T) { - initBlankContext("OWNER/REPO", "master") + ctx := context.NewBlank() + ctx.SetBranch("master") + ctx.SetRemotes(map[string]string{ + "origin": "OWNER/REPO", + }) + initContext = func() context.Context { + return ctx + } http := initFakeHTTP() + http.StubResponse(200, bytes.NewBufferString(` + { "data": { "repo_000": { + "id": "REPOID", + "name": "REPO", + "owner": {"login": "OWNER"}, + "defaultBranchRef": { + "name": "master", + "target": {"oid": "deadbeef"} + }, + "viewerPermission": "WRITE" + } } } + `)) + http.StubResponse(200, bytes.NewBufferString(` { "data": { "repository": { "id": "REPOID", @@ -513,8 +573,28 @@ func TestIssueCreate_disabledIssues(t *testing.T) { } func TestIssueCreate_web(t *testing.T) { - initBlankContext("OWNER/REPO", "master") - initFakeHTTP() + ctx := context.NewBlank() + ctx.SetBranch("master") + ctx.SetRemotes(map[string]string{ + "origin": "OWNER/REPO", + }) + initContext = func() context.Context { + return ctx + } + http := initFakeHTTP() + + http.StubResponse(200, bytes.NewBufferString(` + { "data": { "repo_000": { + "id": "REPOID", + "name": "REPO", + "owner": {"login": "OWNER"}, + "defaultBranchRef": { + "name": "master", + "target": {"oid": "deadbeef"} + }, + "viewerPermission": "WRITE" + } } } + `)) var seenCmd *exec.Cmd restoreCmd := utils.SetPrepareCmd(func(cmd *exec.Cmd) utils.Runnable { diff --git a/command/pr_test.go b/command/pr_test.go index cd22d5a85..d194cf726 100644 --- a/command/pr_test.go +++ b/command/pr_test.go @@ -11,6 +11,7 @@ import ( "strings" "testing" + "github.com/cli/cli/context" "github.com/cli/cli/utils" "github.com/google/shlex" "github.com/spf13/cobra" @@ -71,9 +72,29 @@ func RunCommand(cmd *cobra.Command, args string) (*cmdOut, error) { } func TestPRStatus(t *testing.T) { - initBlankContext("OWNER/REPO", "blueberries") + ctx := context.NewBlank() + ctx.SetBranch("blueberries") + ctx.SetRemotes(map[string]string{ + "origin": "OWNER/REPO", + }) + initContext = func() context.Context { + return ctx + } http := initFakeHTTP() + http.StubResponse(200, bytes.NewBufferString(` + { "data": { "repo_000": { + "id": "REPOID", + "name": "REPO", + "owner": {"login": "OWNER"}, + "defaultBranchRef": { + "name": "master", + "target": {"oid": "deadbeef"} + }, + "viewerPermission": "WRITE" + } } } + `)) + jsonFile, _ := os.Open("../test/fixtures/prStatus.json") defer jsonFile.Close() http.StubResponse(200, jsonFile) @@ -98,9 +119,29 @@ func TestPRStatus(t *testing.T) { } func TestPRStatus_reviewsAndChecks(t *testing.T) { - initBlankContext("OWNER/REPO", "blueberries") + ctx := context.NewBlank() + ctx.SetBranch("blueberries") + ctx.SetRemotes(map[string]string{ + "origin": "OWNER/REPO", + }) + initContext = func() context.Context { + return ctx + } http := initFakeHTTP() + http.StubResponse(200, bytes.NewBufferString(` + { "data": { "repo_000": { + "id": "REPOID", + "name": "REPO", + "owner": {"login": "OWNER"}, + "defaultBranchRef": { + "name": "master", + "target": {"oid": "deadbeef"} + }, + "viewerPermission": "WRITE" + } } } + `)) + jsonFile, _ := os.Open("../test/fixtures/prStatusChecks.json") defer jsonFile.Close() http.StubResponse(200, jsonFile) @@ -124,9 +165,29 @@ func TestPRStatus_reviewsAndChecks(t *testing.T) { } func TestPRStatus_blankSlate(t *testing.T) { - initBlankContext("OWNER/REPO", "blueberries") + ctx := context.NewBlank() + ctx.SetBranch("blueberries") + ctx.SetRemotes(map[string]string{ + "origin": "OWNER/REPO", + }) + initContext = func() context.Context { + return ctx + } http := initFakeHTTP() + http.StubResponse(200, bytes.NewBufferString(` + { "data": { "repo_000": { + "id": "REPOID", + "name": "REPO", + "owner": {"login": "OWNER"}, + "defaultBranchRef": { + "name": "master", + "target": {"oid": "deadbeef"} + }, + "viewerPermission": "WRITE" + } } } + `)) + http.StubResponse(200, bytes.NewBufferString(` { "data": {} } `)) @@ -155,9 +216,29 @@ Requesting a code review from you } func TestPRList(t *testing.T) { - initBlankContext("OWNER/REPO", "master") + ctx := context.NewBlank() + ctx.SetBranch("master") + ctx.SetRemotes(map[string]string{ + "origin": "OWNER/REPO", + }) + initContext = func() context.Context { + return ctx + } http := initFakeHTTP() + http.StubResponse(200, bytes.NewBufferString(` + { "data": { "repo_000": { + "id": "REPOID", + "name": "REPO", + "owner": {"login": "OWNER"}, + "defaultBranchRef": { + "name": "master", + "target": {"oid": "deadbeef"} + }, + "viewerPermission": "WRITE" + } } } + `)) + jsonFile, _ := os.Open("../test/fixtures/prList.json") defer jsonFile.Close() http.StubResponse(200, jsonFile) @@ -174,9 +255,29 @@ func TestPRList(t *testing.T) { } func TestPRList_filtering(t *testing.T) { - initBlankContext("OWNER/REPO", "master") + ctx := context.NewBlank() + ctx.SetBranch("master") + ctx.SetRemotes(map[string]string{ + "origin": "OWNER/REPO", + }) + initContext = func() context.Context { + return ctx + } http := initFakeHTTP() + http.StubResponse(200, bytes.NewBufferString(` + { "data": { "repo_000": { + "id": "REPOID", + "name": "REPO", + "owner": {"login": "OWNER"}, + "defaultBranchRef": { + "name": "master", + "target": {"oid": "deadbeef"} + }, + "viewerPermission": "WRITE" + } } } + `)) + respBody := bytes.NewBufferString(`{ "data": {} }`) http.StubResponse(200, respBody) @@ -206,9 +307,29 @@ No pull requests match your search } func TestPRList_filteringAssignee(t *testing.T) { - initBlankContext("OWNER/REPO", "master") + ctx := context.NewBlank() + ctx.SetBranch("master") + ctx.SetRemotes(map[string]string{ + "origin": "OWNER/REPO", + }) + initContext = func() context.Context { + return ctx + } http := initFakeHTTP() + http.StubResponse(200, bytes.NewBufferString(` + { "data": { "repo_000": { + "id": "REPOID", + "name": "REPO", + "owner": {"login": "OWNER"}, + "defaultBranchRef": { + "name": "master", + "target": {"oid": "deadbeef"} + }, + "viewerPermission": "WRITE" + } } } + `)) + respBody := bytes.NewBufferString(`{ "data": {} }`) http.StubResponse(200, respBody) @@ -242,9 +363,29 @@ func TestPRList_filteringAssigneeLabels(t *testing.T) { } func TestPRView_preview(t *testing.T) { - initBlankContext("OWNER/REPO", "master") + ctx := context.NewBlank() + ctx.SetBranch("master") + ctx.SetRemotes(map[string]string{ + "origin": "OWNER/REPO", + }) + initContext = func() context.Context { + return ctx + } http := initFakeHTTP() + http.StubResponse(200, bytes.NewBufferString(` + { "data": { "repo_000": { + "id": "REPOID", + "name": "REPO", + "owner": {"login": "OWNER"}, + "defaultBranchRef": { + "name": "master", + "target": {"oid": "deadbeef"} + }, + "viewerPermission": "WRITE" + } } } + `)) + jsonFile, _ := os.Open("../test/fixtures/prViewPreview.json") defer jsonFile.Close() http.StubResponse(200, jsonFile) @@ -271,9 +412,29 @@ func TestPRView_preview(t *testing.T) { } func TestPRView_previewCurrentBranch(t *testing.T) { - initBlankContext("OWNER/REPO", "blueberries") + ctx := context.NewBlank() + ctx.SetBranch("blueberries") + ctx.SetRemotes(map[string]string{ + "origin": "OWNER/REPO", + }) + initContext = func() context.Context { + return ctx + } http := initFakeHTTP() + http.StubResponse(200, bytes.NewBufferString(` + { "data": { "repo_000": { + "id": "REPOID", + "name": "REPO", + "owner": {"login": "OWNER"}, + "defaultBranchRef": { + "name": "master", + "target": {"oid": "deadbeef"} + }, + "viewerPermission": "WRITE" + } } } + `)) + jsonFile, _ := os.Open("../test/fixtures/prView.json") defer jsonFile.Close() http.StubResponse(200, jsonFile) @@ -305,9 +466,29 @@ func TestPRView_previewCurrentBranch(t *testing.T) { } func TestPRView_currentBranch(t *testing.T) { - initBlankContext("OWNER/REPO", "blueberries") + ctx := context.NewBlank() + ctx.SetBranch("blueberries") + ctx.SetRemotes(map[string]string{ + "origin": "OWNER/REPO", + }) + initContext = func() context.Context { + return ctx + } http := initFakeHTTP() + http.StubResponse(200, bytes.NewBufferString(` + { "data": { "repo_000": { + "id": "REPOID", + "name": "REPO", + "owner": {"login": "OWNER"}, + "defaultBranchRef": { + "name": "master", + "target": {"oid": "deadbeef"} + }, + "viewerPermission": "WRITE" + } } } + `)) + jsonFile, _ := os.Open("../test/fixtures/prView.json") defer jsonFile.Close() http.StubResponse(200, jsonFile) @@ -342,9 +523,29 @@ func TestPRView_currentBranch(t *testing.T) { } func TestPRView_noResultsForBranch(t *testing.T) { - initBlankContext("OWNER/REPO", "blueberries") + ctx := context.NewBlank() + ctx.SetBranch("blueberries") + ctx.SetRemotes(map[string]string{ + "origin": "OWNER/REPO", + }) + initContext = func() context.Context { + return ctx + } http := initFakeHTTP() + http.StubResponse(200, bytes.NewBufferString(` + { "data": { "repo_000": { + "id": "REPOID", + "name": "REPO", + "owner": {"login": "OWNER"}, + "defaultBranchRef": { + "name": "master", + "target": {"oid": "deadbeef"} + }, + "viewerPermission": "WRITE" + } } } + `)) + jsonFile, _ := os.Open("../test/fixtures/prView_NoActiveBranch.json") defer jsonFile.Close() http.StubResponse(200, jsonFile) @@ -372,9 +573,29 @@ func TestPRView_noResultsForBranch(t *testing.T) { } func TestPRView_numberArg(t *testing.T) { - initBlankContext("OWNER/REPO", "master") + ctx := context.NewBlank() + ctx.SetBranch("master") + ctx.SetRemotes(map[string]string{ + "origin": "OWNER/REPO", + }) + initContext = func() context.Context { + return ctx + } http := initFakeHTTP() + http.StubResponse(200, bytes.NewBufferString(` + { "data": { "repo_000": { + "id": "REPOID", + "name": "REPO", + "owner": {"login": "OWNER"}, + "defaultBranchRef": { + "name": "master", + "target": {"oid": "deadbeef"} + }, + "viewerPermission": "WRITE" + } } } + `)) + http.StubResponse(200, bytes.NewBufferString(` { "data": { "repository": { "pullRequest": { "url": "https://github.com/OWNER/REPO/pull/23" @@ -403,9 +624,29 @@ func TestPRView_numberArg(t *testing.T) { } func TestPRView_urlArg(t *testing.T) { - initBlankContext("OWNER/REPO", "master") + ctx := context.NewBlank() + ctx.SetBranch("master") + ctx.SetRemotes(map[string]string{ + "origin": "OWNER/REPO", + }) + initContext = func() context.Context { + return ctx + } http := initFakeHTTP() + http.StubResponse(200, bytes.NewBufferString(` + { "data": { "repo_000": { + "id": "REPOID", + "name": "REPO", + "owner": {"login": "OWNER"}, + "defaultBranchRef": { + "name": "master", + "target": {"oid": "deadbeef"} + }, + "viewerPermission": "WRITE" + } } } + `)) + http.StubResponse(200, bytes.NewBufferString(` { "data": { "repository": { "pullRequest": { "url": "https://github.com/OWNER/REPO/pull/23" @@ -434,9 +675,29 @@ func TestPRView_urlArg(t *testing.T) { } func TestPRView_branchArg(t *testing.T) { - initBlankContext("OWNER/REPO", "master") + ctx := context.NewBlank() + ctx.SetBranch("master") + ctx.SetRemotes(map[string]string{ + "origin": "OWNER/REPO", + }) + initContext = func() context.Context { + return ctx + } http := initFakeHTTP() + http.StubResponse(200, bytes.NewBufferString(` + { "data": { "repo_000": { + "id": "REPOID", + "name": "REPO", + "owner": {"login": "OWNER"}, + "defaultBranchRef": { + "name": "master", + "target": {"oid": "deadbeef"} + }, + "viewerPermission": "WRITE" + } } } + `)) + http.StubResponse(200, bytes.NewBufferString(` { "data": { "repository": { "pullRequests": { "nodes": [ { "headRefName": "blueberries", @@ -467,9 +728,29 @@ func TestPRView_branchArg(t *testing.T) { } func TestPRView_branchWithOwnerArg(t *testing.T) { - initBlankContext("OWNER/REPO", "master") + ctx := context.NewBlank() + ctx.SetBranch("master") + ctx.SetRemotes(map[string]string{ + "origin": "OWNER/REPO", + }) + initContext = func() context.Context { + return ctx + } http := initFakeHTTP() + http.StubResponse(200, bytes.NewBufferString(` + { "data": { "repo_000": { + "id": "REPOID", + "name": "REPO", + "owner": {"login": "OWNER"}, + "defaultBranchRef": { + "name": "master", + "target": {"oid": "deadbeef"} + }, + "viewerPermission": "WRITE" + } } } + `)) + http.StubResponse(200, bytes.NewBufferString(` { "data": { "repository": { "pullRequests": { "nodes": [ { "headRefName": "blueberries",