MCPcopy Create free account
hub / github.com/cli/cli / prFromFixtures

Function prFromFixtures

pkg/cmd/pr/view/view_test.go:213–254  ·  view source on GitHub ↗

hack for compatibility with old JSON fixture files

(fixtures map[string]string)

Source from the content-addressed store, hash-verified

211
212// hack for compatibility with old JSON fixture files
213func prFromFixtures(fixtures map[string]string) (*api.PullRequest, error) {
214 var response struct {
215 Data struct {
216 Repository struct {
217 PullRequest *api.PullRequest
218 }
219 }
220 }
221
222 ff, err := os.Open(fixtures["PullRequestByNumber"])
223 if err != nil {
224 return nil, err
225 }
226 defer ff.Close()
227
228 dec := json.NewDecoder(ff)
229 err = dec.Decode(&response)
230 if err != nil {
231 return nil, err
232 }
233
234 for name := range fixtures {
235 switch name {
236 case "PullRequestByNumber":
237 case "ReviewsForPullRequest", "CommentsForPullRequest":
238 ff, err := os.Open(fixtures[name])
239 if err != nil {
240 return nil, err
241 }
242 defer ff.Close()
243 dec := json.NewDecoder(ff)
244 err = dec.Decode(&response)
245 if err != nil {
246 return nil, err
247 }
248 default:
249 return nil, fmt.Errorf("unrecognized fixture type: %q", name)
250 }
251 }
252
253 return response.Data.Repository.PullRequest, nil
254}
255
256func TestPRView_Preview_nontty(t *testing.T) {
257 tests := map[string]struct {

Callers 4

TestPRView_PreviewFunction · 0.85
TestPRView_tty_CommentsFunction · 0.85

Calls 3

OpenMethod · 0.80
CloseMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected