diff --git a/command/pr_create_test.go b/command/pr_create_test.go new file mode 100644 index 000000000..8adec0a22 --- /dev/null +++ b/command/pr_create_test.go @@ -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") + // } +} diff --git a/git/git.go b/git/git.go index dcfe56190..6c0c31528 100644 --- a/git/git.go +++ b/git/git.go @@ -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) } diff --git a/test/fixtures/createPr.json b/test/fixtures/createPr.json new file mode 100644 index 000000000..47be76948 --- /dev/null +++ b/test/fixtures/createPr.json @@ -0,0 +1,9 @@ +{ + "data": { + "createPullRequest": { + "pullRequest": { + "url": "https://github.com/vilmibm/testing/pull/14" + } + } + } +} diff --git a/test/fixtures/repoId.json b/test/fixtures/repoId.json new file mode 100644 index 000000000..965b39f3d --- /dev/null +++ b/test/fixtures/repoId.json @@ -0,0 +1,7 @@ +{ + "data": { + "repository": { + "id": "a repo id" + } + } +} diff --git a/test/helpers.go b/test/helpers.go index e2f059175..bbc493ae3 100644 --- a/test/helpers.go +++ b/test/helpers.go @@ -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]] }