MCPcopy Index your code
hub / github.com/cli/cli / prFromFixtures

Function prFromFixtures

pkg/cmd/pr/view/view_test.go:206–247  ·  view source on GitHub ↗

hack for compatibility with old JSON fixture files

(fixtures map[string]string)

Source from the content-addressed store, hash-verified

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