WIP resuming pr create test work

This commit is contained in:
nate smith 2019-11-01 17:19:01 -05:00
parent 7555aa9be3
commit c12bdc2731
5 changed files with 87 additions and 1 deletions

60
command/pr_create_test.go Normal file
View file

@ -0,0 +1,60 @@
package command
import (
//"regexp"
"testing"
//"github.com/github/gh-cli/context"
"github.com/github/gh-cli/test"
//"github.com/github/gh-cli/utils"
)
func TestPrCreateHelperProcess(*testing.T) {
if test.SkipTestHelperProcess() {
return
}
statusOutputs := map[string]string{
"clean": "",
"dirty": " M git/git.go",
}
args := GetTestHelperProcessArgs()
switch args[1] {
case "status":
fmt.Println(statusOutputs(args[0]))
case "push":
fmt.Println()
}
defer os.Exit(0)
}
func TestReportsUncommittedChanges(t *testing.T) {
repoIdFix, _ := os.Open("test/fixtures/repoId.json")
defer repoIdFix.Close()
createPrFix, _ := os.Open("test/fixtures/createPr.json")
defer createPrFix.Close()
http := initFakeHTTP()
http.StubResponse(200, repoIdFix)
http.StubResponse(200, createPrFix)
origGitCommand := git.GitCommand
defer func() {
git.GitCommand = origGitCommand
}()
git.GitCommand = test.StubExecCommand("TestPrCreateHelperProcess", "dirty")
// init blank command and just run prCreate? Or try to use RunCommand?
// output, err := test.RunCommand(RootCmd, "pr create -tfoo -bbar")
// if err != nil {
// t.Errorf("error running command `pr create`: %v", err)
// }
// if len(output) == 0 {
// panic("lol")
// }
}

View file

@ -239,6 +239,11 @@ func UncommittedChangeCount() (int, error) {
return count, nil
}
func Push(remote string, ref string) error {
cmd := GitCommand("push", "--set-upstream", remote, ref)
return cmd.Run()
}
var Push = func(remote string, ref string) error {
return Run("push", "--set-upstream", remote, ref)
}

9
test/fixtures/createPr.json vendored Normal file
View file

@ -0,0 +1,9 @@
{
"data": {
"createPullRequest": {
"pullRequest": {
"url": "https://github.com/vilmibm/testing/pull/14"
}
}
}
}

7
test/fixtures/repoId.json vendored Normal file
View file

@ -0,0 +1,7 @@
{
"data": {
"repository": {
"id": "a repo id"
}
}
}

View file

@ -16,7 +16,7 @@ type ExecStub struct {
ExitCode int
}
func GetExecStub(outputs map[string]ExecStub) ExecStub {
func GetTestHelperProcessArgs() []string {
args := os.Args
for len(args) > 0 {
if args[0] == "--" {
@ -25,6 +25,11 @@ func GetExecStub(outputs map[string]ExecStub) ExecStub {
}
args = args[1:]
}
return args
}
func GetExecStub(outputs map[string]ExecStub) ExecStub {
args := GetTestHelperProcessArgs()
return outputs[args[0]]
}