X Tutup
Skip to content

Commit c12bdc2

Browse files
author
nate smith
committed
WIP resuming pr create test work
1 parent 7555aa9 commit c12bdc2

File tree

5 files changed

+87
-1
lines changed

5 files changed

+87
-1
lines changed

command/pr_create_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package command
2+
3+
import (
4+
//"regexp"
5+
"testing"
6+
7+
//"github.com/github/gh-cli/context"
8+
"github.com/github/gh-cli/test"
9+
//"github.com/github/gh-cli/utils"
10+
)
11+
12+
func TestPrCreateHelperProcess(*testing.T) {
13+
if test.SkipTestHelperProcess() {
14+
return
15+
}
16+
17+
statusOutputs := map[string]string{
18+
"clean": "",
19+
"dirty": " M git/git.go",
20+
}
21+
22+
args := GetTestHelperProcessArgs()
23+
switch args[1] {
24+
case "status":
25+
fmt.Println(statusOutputs(args[0]))
26+
case "push":
27+
fmt.Println()
28+
}
29+
30+
defer os.Exit(0)
31+
}
32+
33+
func TestReportsUncommittedChanges(t *testing.T) {
34+
repoIdFix, _ := os.Open("test/fixtures/repoId.json")
35+
defer repoIdFix.Close()
36+
createPrFix, _ := os.Open("test/fixtures/createPr.json")
37+
defer createPrFix.Close()
38+
39+
http := initFakeHTTP()
40+
http.StubResponse(200, repoIdFix)
41+
http.StubResponse(200, createPrFix)
42+
43+
origGitCommand := git.GitCommand
44+
defer func() {
45+
git.GitCommand = origGitCommand
46+
}()
47+
48+
git.GitCommand = test.StubExecCommand("TestPrCreateHelperProcess", "dirty")
49+
50+
// init blank command and just run prCreate? Or try to use RunCommand?
51+
52+
// output, err := test.RunCommand(RootCmd, "pr create -tfoo -bbar")
53+
// if err != nil {
54+
// t.Errorf("error running command `pr create`: %v", err)
55+
// }
56+
57+
// if len(output) == 0 {
58+
// panic("lol")
59+
// }
60+
}

git/git.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,11 @@ func UncommittedChangeCount() (int, error) {
239239
return count, nil
240240
}
241241

242+
func Push(remote string, ref string) error {
243+
cmd := GitCommand("push", "--set-upstream", remote, ref)
244+
return cmd.Run()
245+
}
246+
242247
var Push = func(remote string, ref string) error {
243248
return Run("push", "--set-upstream", remote, ref)
244249
}

test/fixtures/createPr.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"data": {
3+
"createPullRequest": {
4+
"pullRequest": {
5+
"url": "https://github.com/vilmibm/testing/pull/14"
6+
}
7+
}
8+
}
9+
}

test/fixtures/repoId.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"data": {
3+
"repository": {
4+
"id": "a repo id"
5+
}
6+
}
7+
}

test/helpers.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type ExecStub struct {
1616
ExitCode int
1717
}
1818

19-
func GetExecStub(outputs map[string]ExecStub) ExecStub {
19+
func GetTestHelperProcessArgs() []string {
2020
args := os.Args
2121
for len(args) > 0 {
2222
if args[0] == "--" {
@@ -25,6 +25,11 @@ func GetExecStub(outputs map[string]ExecStub) ExecStub {
2525
}
2626
args = args[1:]
2727
}
28+
return args
29+
}
30+
31+
func GetExecStub(outputs map[string]ExecStub) ExecStub {
32+
args := GetTestHelperProcessArgs()
2833
return outputs[args[0]]
2934
}
3035

0 commit comments

Comments
 (0)
X Tutup