MCPcopy
hub / github.com/cli/cli / TestUnpinRun

Function TestUnpinRun

pkg/cmd/issue/unpin/unpin_test.go:21–100  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

19}
20
21func TestUnpinRun(t *testing.T) {
22 tests := []struct {
23 name string
24 tty bool
25 opts *UnpinOptions
26 httpStubs func(*httpmock.Registry)
27 wantStdout string
28 wantStderr string
29 }{
30 {
31 name: "unpin issue",
32 tty: true,
33 opts: &UnpinOptions{IssueNumber: 20},
34 httpStubs: func(reg *httpmock.Registry) {
35 reg.Register(
36 httpmock.GraphQL(`query IssueByNumber\b`),
37 httpmock.StringResponse(`
38 { "data": { "repository": {
39 "issue": { "id": "ISSUE-ID", "number": 20, "title": "Issue Title", "isPinned": true}
40 } } }`),
41 )
42 reg.Register(
43 httpmock.GraphQL(`mutation IssueUnpin\b`),
44 httpmock.GraphQLMutation(`{"id": "ISSUE-ID"}`,
45 func(inputs map[string]interface{}) {
46 assert.Equal(t, inputs["issueId"], "ISSUE-ID")
47 },
48 ),
49 )
50 },
51 wantStdout: "",
52 wantStderr: "✓ Unpinned issue OWNER/REPO#20 (Issue Title)\n",
53 },
54 {
55 name: "issue not pinned",
56 tty: true,
57 opts: &UnpinOptions{IssueNumber: 20},
58 httpStubs: func(reg *httpmock.Registry) {
59 reg.Register(
60 httpmock.GraphQL(`query IssueByNumber\b`),
61 httpmock.StringResponse(`
62 { "data": { "repository": {
63 "issue": { "id": "ISSUE-ID", "number": 20, "title": "Issue Title", "isPinned": false}
64 } } }`),
65 )
66 },
67 wantStderr: "! Issue OWNER/REPO#20 (Issue Title) is not pinned\n",
68 },
69 }
70 for _, tt := range tests {
71 reg := &httpmock.Registry{}
72 if tt.httpStubs != nil {
73 tt.httpStubs(reg)
74 }
75 tt.opts.HttpClient = func() (*http.Client, error) {
76 return &http.Client{Transport: reg}, nil
77 }
78

Callers

nothing calls this directly

Calls 14

RegisterMethod · 0.95
VerifyMethod · 0.95
GraphQLFunction · 0.92
StringResponseFunction · 0.92
GraphQLMutationFunction · 0.92
TestFunction · 0.92
NewBlankConfigFunction · 0.92
NewFunction · 0.92
unpinRunFunction · 0.85
EqualMethod · 0.80
SetStdinTTYMethod · 0.80
SetStdoutTTYMethod · 0.80

Tested by

no test coverage detected