(t *testing.T)
| 19 | } |
| 20 | |
| 21 | func 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 |
nothing calls this directly
no test coverage detected