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

Function prFromFixtures

pkg/cmd/pr/view/view_test.go:211–252  ·  view source on GitHub ↗

hack for compatibility with old JSON fixture files

(fixtures map[string]string)

Source from the content-addressed store, hash-verified

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