Skip to content

Commit 723cd06

Browse files
committed
Add pr list --assignee test
1 parent 6aa1efc commit 723cd06

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

command/pr_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
"github.com/github/gh-cli/test"
1515
"github.com/github/gh-cli/utils"
16+
"github.com/spf13/pflag"
1617
)
1718

1819
func eq(t *testing.T, got interface{}, expected interface{}) {
@@ -100,6 +101,39 @@ func TestPRList_filtering(t *testing.T) {
100101
eq(t, reqBody.Variables.Labels, []string{"one", "two"})
101102
}
102103

104+
func TestPRList_filteringAssignee(t *testing.T) {
105+
initBlankContext("OWNER/REPO", "master")
106+
http := initFakeHTTP()
107+
108+
respBody := bytes.NewBufferString(`{ "data": {} }`)
109+
http.StubResponse(200, respBody)
110+
111+
prListCmd.SetOut(ioutil.Discard)
112+
// Reset flag slice values so they don't leak between tests
113+
// TODO: generalize this hack
114+
prListCmd.Flags().Visit(func(f *pflag.Flag) {
115+
if v, ok := f.Value.(pflag.SliceValue); ok {
116+
v.Replace([]string{})
117+
}
118+
})
119+
120+
RootCmd.SetArgs([]string{"pr", "list", "-s", "merged", "-l", "one two", "-a", "hubot", "-B", "develop"})
121+
_, err := RootCmd.ExecuteC()
122+
if err != nil {
123+
t.Fatal(err)
124+
}
125+
126+
bodyBytes, _ := ioutil.ReadAll(http.Requests[0].Body)
127+
reqBody := struct {
128+
Variables struct {
129+
Q string
130+
}
131+
}{}
132+
json.Unmarshal(bodyBytes, &reqBody)
133+
134+
eq(t, reqBody.Variables.Q, `repo:OWNER/REPO assignee:hubot is:pr sort:created-desc is:merged label:"one two" base:"develop"`)
135+
}
136+
103137
func TestPRView_currentBranch(t *testing.T) {
104138
initBlankContext("OWNER/REPO", "blueberries")
105139
http := initFakeHTTP()

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ require (
1111
github.com/mitchellh/go-homedir v1.1.0
1212
github.com/pkg/errors v0.8.1
1313
github.com/spf13/cobra v0.0.5
14+
github.com/spf13/pflag v1.0.5
1415
github.com/stretchr/testify v1.3.0 // indirect
1516
golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5
1617
gopkg.in/yaml.v3 v3.0.0-20191010095647-fc94e3f71652

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tL
4646
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
4747
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
4848
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
49+
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
50+
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
4951
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
5052
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
5153
github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=

0 commit comments

Comments
 (0)